如何使用Python根据BED文件格式更改坐标格式?
我有两个fasta文件,我想将FileB.fasta中的较短序列与FileA.fasta中的原始序列进行匹配,以获得其坐标或位置。但我的输出格式不正确。有人能帮我吗 FileA.fasta如何使用Python根据BED文件格式更改坐标格式?,python,bioinformatics,fasta,Python,Bioinformatics,Fasta,我有两个fasta文件,我想将FileB.fasta中的较短序列与FileA.fasta中的原始序列进行匹配,以获得其坐标或位置。但我的输出格式不正确。有人能帮我吗 FileA.fasta >chr1:2000-2019 ACGTCGATCGGTCGACGTGC >chr1:2000-2019 GATCGG FileB.fasta >chr1:2000-2019 ACGTCGATCGGTCGACGTGC >chr1:2000-2019 GATCGG 文件床 chr
>chr1:2000-2019
ACGTCGATCGGTCGACGTGC
>chr1:2000-2019
GATCGG
FileB.fasta
>chr1:2000-2019
ACGTCGATCGGTCGACGTGC
>chr1:2000-2019
GATCGG
文件床
chr1:2000-2019 6 11
chr1 2005 2011
代码
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:2000-2019 6 11
chr1 2005 2011
好的,你在索引上加了一个1,在这个索引上你可以找到更短的序列-
start = long_sequence.index(short_sequence) + 1 <--- notice the +1
对于记录的id
,如果您不想在:
之前添加任何内容,则应在:
处拆分id,并取左侧部分(拆分后的索引字符串为0)
范例-
start = long_sequence.index(short_sequence) + int((short_sequence_record.id.split(':')[1].split('-')[0]))
stop = start + len(short_sequence)
output_line ='%s\t%i\t%i\n' % \
((short_sequence_record.id.split(':')[0]),start,stop)
output_file.write(output_line )
好的,你在索引上加了一个1,在这个索引上你可以找到更短的序列-
start = long_sequence.index(short_sequence) + 1 <--- notice the +1
对于记录的id
,如果您不想在:
之前添加任何内容,则应在:
处拆分id,并取左侧部分(拆分后的索引字符串为0)
范例-
start = long_sequence.index(short_sequence) + int((short_sequence_record.id.split(':')[1].split('-')[0]))
stop = start + len(short_sequence)
output_line ='%s\t%i\t%i\n' % \
((short_sequence_record.id.split(':')[0]),start,stop)
output_file.write(output_line )
好的,你在索引上加了一个1,在这个索引上你可以找到更短的序列-
start = long_sequence.index(short_sequence) + 1 <--- notice the +1
对于记录的id
,如果您不想在:
之前添加任何内容,则应在:
处拆分id,并取左侧部分(拆分后的索引字符串为0)
范例-
start = long_sequence.index(short_sequence) + int((short_sequence_record.id.split(':')[1].split('-')[0]))
stop = start + len(short_sequence)
output_line ='%s\t%i\t%i\n' % \
((short_sequence_record.id.split(':')[0]),start,stop)
output_file.write(output_line )
好的,你在索引上加了一个1,在这个索引上你可以找到更短的序列-
start = long_sequence.index(short_sequence) + 1 <--- notice the +1
对于记录的id
,如果您不想在:
之前添加任何内容,则应在:
处拆分id,并取左侧部分(拆分后的索引字符串为0)
范例-
start = long_sequence.index(short_sequence) + int((short_sequence_record.id.split(':')[1].split('-')[0]))
stop = start + len(short_sequence)
output_line ='%s\t%i\t%i\n' % \
((short_sequence_record.id.split(':')[0]),start,stop)
output_file.write(output_line )
一个更普遍的解决方案:
一个更普遍的解决方案:
一个更普遍的解决方案:
一个更普遍的解决方案:
我只是编辑我的问题。请看一看。如果我使用上面的示例,它将无法工作。它仍将从0开始计数。我相信,如果您想开始计数,请让我更改我的代码。此外,您确定id将始终像-
chr1:-
?fasta文件中有许多chr类型,例如chr2、chr3等。chr2/3/4。。。etc很好,意思是一切都应该是这样,我只是编辑我的问题。请看一看。如果我使用上面的示例,它将无法工作。它仍将从0开始计数。我相信,如果您想开始计数,请让我更改我的代码。此外,您确定id将始终像-chr1:-
?fasta文件中有许多chr类型,例如chr2、chr3等。chr2/3/4。。。etc很好,意思是一切都应该是这样,我只是编辑我的问题。请看一看。如果我使用上面的示例,它将无法工作。它仍将从0开始计数。我相信,如果您想开始计数,请让我更改我的代码。此外,您确定id将始终像-chr1:-
?fasta文件中有许多chr类型,例如chr2、chr3等。chr2/3/4。。。etc很好,意思是一切都应该是这样,我只是编辑我的问题。请看一看。如果我使用上面的示例,它将无法工作。它仍将从0开始计数。我相信,如果您想开始计数,请让我更改我的代码。此外,您确定id将始终像-chr1:-
?fasta文件中有许多chr类型,例如chr2、chr3等。chr2/3/4。。。etc是好的,意思是所有的都应该是那种模式