python实现fasta文件碱基序列每行按照指定数目输出

 

001、

复制代码
(base) [root@pc1 test1]# ls
a.fa  test.py
(base) [root@pc1 test1]# cat a.fa          ## 测试fasta
>chr1
tttcccggg
>chr2
tttgggjjj
cccjjjjjj
>chr3
ccc
>chr4
aaaaatt
(base) [root@pc1 test1]# cat test.py      ## 程序
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

dict1 = dict()
with open("a.fa", "r") as in_put:
        for i in in_put:
                i = i.strip()
                if i[0] == ">":
                        key = i
                        dict1[key] = ""
                else:
                        dict1[key] += i
        in_put.close()

        for i,j in dict1.items():
                print(i)
                for k in range(0, len(j), 5):
                        print(j[k:k+5])
复制代码

 

复制代码
(base) [root@pc1 test1]# ls
a.fa  test.py
(base) [root@pc1 test1]# python3 test.py   ## 运算结果
>chr1
tttcc
cggg
>chr2
tttgg
gjjjc
ccjjj
jjj
>chr3
ccc
>chr4
aaaaa
tt
复制代码

 。

 

posted @   小鲨鱼2018  阅读(47)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2022-10-14 configure: error: htscodecs submodule files not present.
2022-10-14 centos中 在线安装 libz
2022-10-14 slurm、docker
2022-10-14 centos7 中 升级cmake
2022-10-14 linux 中如何统计每一行所占的字符长度
2022-10-14 centos7 中manta软件的安装
2020-10-14 linux系统中case命令的用法
点击右上角即可分享
微信分享提示