【问题标题】:calculate the length of a sequence after adding the length of previous sequences将前面序列的长度相加后计算一个序列的长度
【发布时间】:2018-08-10 05:45:56
【问题描述】:

我想确定 multifasta 文件中各个序列的长度。我从 bio 手册中得到了这个 biopython 代码:

from Bio import SeqIO
import sys
cmdargs = str(sys.argv)
for seq_record in SeqIO.parse(str(sys.argv[1]), "fasta"):
 output_line = '%s\t%i' % \
(seq_record.id, len(seq_record))
 print(output_line)

我的输入文件是这样的:

>Protein1
MNT
>Protein2
TSMN
>Protein3
TTQRT

代码产生:

Protein1        3
Protein2        4
Protein3        5

但是我想在添加先前序列的长度后计算序列的长度。就像:

Protein1        1-3
Protein2        4-7
Protein3        8-12

我不知道我需要更改上述代码中的哪一行以获得该输出。非常感谢您对这个问题的任何帮助,谢谢!!!!

【问题讨论】:

    标签: python biopython fasta


    【解决方案1】:

    很容易得到总长度:

    from Bio import SeqIO
    import sys
    cmdargs = str(sys.argv)
    total_len = 0
    for seq_record in SeqIO.parse(str(sys.argv[1]), "fasta"):
        total_len += len(seq_record)
        output_line = '%s\t%i' % (seq_record.id, total_len))
        print(output_line)
    

    获取范围:

    from Bio import SeqIO
    import sys
    cmdargs = str(sys.argv)
    total_len = 0
    for seq_record in SeqIO.parse(str(sys.argv[1]), "fasta"):
        previous_total_len = total_len
        total_len += len(seq_record)
        output_line = '%s\t%i - %i' % (seq_record.id, previous_total_len + 1, total_len)
        print(output_line)
    

    【讨论】:

      猜你喜欢
      • 2018-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      相关资源
      最近更新 更多