添加先前序列的长度后计算序列的长度
calculate the length of a sequence after adding the length of previous sequences
我想确定 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
我不知道我需要更改以上代码中的哪一行才能获得该输出。如果您对此问题有任何帮助,我将不胜感激!!!
只求总长度很容易:
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)
我想确定 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
我不知道我需要更改以上代码中的哪一行才能获得该输出。如果您对此问题有任何帮助,我将不胜感激!!!
只求总长度很容易:
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)