Python:如何在FASTA文件中找到短序列的坐标?

2024-09-26 18:15:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个短序列的列表,我想获得它的坐标,或者换句话说,在与包含原始序列的fasta文件进行比较后得到它的bed文件。

Fasta文件:

>PGH2
CGTAGCGGCTGAGTGCGCGGATAGCGCGTA

短序列fasta文件:

^{pr2}$

有什么方法可以得到它的坐标吗?床具也帮不了什么忙。

期望输出:

PGH2  6 14

Tags: 文件方法列表序列fastabedpr2cgtagcggctgagtgcgcggatagcgcgta
2条回答

使用BioPyton

from Bio import SeqIO

for long_sequence_record in SeqIO.parse(open('long_sequences.fasta'), 'fasta'):
    long_sequence = str(long_sequence_record.seq)

    for short_sequence_record in SeqIO.parse(open('short_sequences.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
str1 = "CGTAGCGGCTGAGTGCGCGGATAGCGCGTA"
str2 = "CGGCTGAGT"
index = str1.index(str2)
print index

输出:index=5,要得到6,14,使用index+1,index+len(str2)

相关问题 更多 >

    热门问题