我有两个fasta文件,我想匹配较短的序列,这是在文件b.fasta到原始序列文件a.fasta获取其坐标或位置。但我的输出格式不正确。有人能帮我吗?你知道吗
文件a.fasta
>chr1:2000-2019
ACGTCGATCGGTCGACGTGC
文件b.fasta
>chr1:2000-2019
GATCGG
病床
chr1:2000-2019 6 11
代码
from Bio import SeqIO
output_file = open('fileC.bed','w')
for long_sequence_record in SeqIO.parse(open('fileA.fasta'), 'fasta'):
long_sequence = str(long_sequence_record.seq)
for short_sequence_record in SeqIO.parse(open('fileB.fasta'), 'fasta'):
short_sequence = str(short_sequence_record.seq)
if short_sequence in long_sequence:
start = long_sequence.index(short_sequence) + 1
stop = start + len(short_sequence) - 1
# print short_sequence_record.id, start, stop
output_line ='%s\t%i\t%i\n' % \
(short_sequence_record.id,start,stop)
output_file.write(output_line )
output_file.close()
所需输出病床
chr1 2005 2011
好吧,你在索引上加了一个1,在这里你可以找到一个较短的序列-
别那么做,应该没事的。也不要对
stop
变量执行-1
。你知道吗您应该从id添加起始序列号
示例-
对于记录的
id
,如果您不希望在:
之前有任何内容,那么您应该在:
处分割id,并获取左侧部分(分割后的索引字符串为0)。你知道吗示例-
更一般的解决方案:
相关问题 更多 >
编程相关推荐