首页 > 解决方案 > 在 FASTA 文件中的多个序列的阅读框 2 中查找最长的 ORF(开放阅读框)

问题描述

我已经看到了一些关于该领域问题的问题,但无法将其用于我的问题,尽管试图理解 Biopython 方法很多小时。

我可以用逻辑做到这一点,但我相信最好使用 Biopython。

我尝试使用我发现的代码:

f = open(r"C:\Users\97254\Downloads\dna2.fasta")
sequences = {}
count = 0
for line in f:
    line = line.rstrip()
    if line[0] == '>':
        count += 1
        first_row = line.split()
        name = first_row[0][1:]
        sequences[name] = ''
    else:
        sequences[name] = sequences[name] + line

startP = re.compile('ATG')
for sequence in sequences.values():
    sequence = squence[1:]
    longest = (0,)
    for m in startP.finditer(sequence):
        if len(Seq.Seq(sequence)[m.start():].translate(to_stop=True)) > longest[0]:
            pro = Seq.Seq(sequence)[m.start():].translate(to_stop=True)
            longest = (len(sequence[m.start():m.start()+len(pro)*3+3]), 
            m.start(), 
            sequence[m.start():m.start()+len(pro)*3+3])

我应该使用诸如 for 循环之类的逻辑,它以 3 的跳跃迭代序列,还是有一种 Biopythonic 方法来做到这一点?

谢谢!

标签: bioinformaticsbiopythonfasta

解决方案


BioPython教程和食谱包含以下用于查找开放阅读框的代码

from Bio import SeqIO
record = SeqIO.read("NC_005816.fna", "fasta")
table = 11
min_pro_len = 100

for strand, nuc in [(+1, record.seq), (-1, record.seq.reverse_complement())]:
    for frame in range(3):
        length = 3 * ((len(record)-frame) // 3) #Multiple of three
        for pro in nuc[frame:frame+length].translate(table).split("*"):
            if len(pro) >= min_pro_len:
                print("%s...%s - length %i, strand %i, frame %i" \
                      % (pro[:30], pro[-3:], len(pro), strand, frame))

输出:

GCLMKKSSIVATIITILSGSANAASSQLIP...YRF - length 315, strand 1, frame 0
KSGELRQTPPASSTLHLRLILQRSGVMMEL...NPE - length 285, strand 1, frame 1
GLNCSFFSICNWKFIDYINRLFQIIYLCKN...YYH - length 176, strand 1, frame 1
VKKILYIKALFLCTVIKLRRFIFSVNNMKF...DLP - length 165, strand 1, frame 1
NQIQGVICSPDSGEFMVTFETVMEIKILHK...GVA - length 355, strand 1, frame 2
RRKEHVSKKRRPQKRPRRRRFFHRLRPPDE...PTR - length 128, strand 1, frame 2
TGKQNSCQMSAIWQLRQNTATKTRQNRARI...AIK - length 100, strand 1, frame 2
QGSGYAFPHASILSGIAMSHFYFLVLHAVK...CSD - length 114, strand -1, frame 0
IYSTSEHTGEQVMRTLDEVIASRSPESQTR...FHV - length 111, strand -1, frame 0
WGKLQVIGLSMWMVLFSQRFDDWLNEQEDA...ESK - length 125, strand -1, frame 1
RGIFMSDTMVVNGSGGVPAFLFSGSTLSSY...LLK - length 361, strand -1, frame 1
WDVKTVTGVLHHPFHLTFSLCPEGATQSGR...VKR - length 111, strand -1, frame 1
LSHTVTDFTDQMAQVGLCQCVNVFLDEVTG...KAA - length 107, strand -1, frame 2
RALTGLSAPGIRSQTSCDRLRELRYVPVSL...PLQ - length 119, strand -1, frame 2

由于它直接来自本教程,因此我认为这是查找 ORF 的最符合 Biopythonic 的方法。它还迭代“3 的跳跃”中的序列,但它使用 BioPython 函数SeqIO.read()来解析 fasta 文件。


推荐阅读