Python脚本:没有输出,但没有错误?

时间:2016-06-01 15:35:15

标签: python

我有一系列短的DNA比对,我想跟踪它们中的不匹配的位置和种类。对齐用' - '分隔,因此文件如下所示:

TTCGCTTGCAGAGAGAAATCAC
||||| ||||||||||||||||
TTCGCATGCAGAGAGAAATCAC
--
TGCTCACCTCTCTTTCTGTCAGT
||||||||||||||| |||||||
TGCTCACCTCTCTTTGTGTCAGT
--
TGCTCAC-TGCTCTTTCTGTCAG
||||||| | |||||||||||||
TGCTCACCT-CTCTTTCTGTCAG
--

我有一个使用BioPython创建对齐对象的简短脚本,我想将结果写入这样的文件:

5,'T A'
15,'C G'
7,'- C'
9,'G -'

这是我到目前为止编写的脚本。它不会返回任何错误,也不会返回任何输出。非常感谢您的帮助/辅导!

#!/usr/bin/python

from __future__ import print_function
from itertools import groupby
from Bio import Alphabet
from Bio.Align.Generic import Alignment
from Bio.Align import AlignInfo
from Bio.Align.AlignInfo import SummaryInfo
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC, Gapped

def align_iter(tmp2):
    """given an alignment file, yield tuples of topline, pipes, bottomline"""
    al = open('tmp2', 'r')
    alniter = (x[1:3] for x in groupby(al, lambda line: line[0] == "-"))  ## split file on '--'
    align = Alignment(Gapped(IUPAC.unambiguous_dna, "-"))  ## these are gapped alignments
    for align in alniter: # for i in range(len(alniter(i)))
        align.add_sequence("full", x[1])    ### together the 3 lines are the alignment
        align.add_sequence("pipes", x[2])
        align.add_sequence("mature", x[3])
    """
    for each mismatch in the alignment, print out the mismatching pairs
    and their index position
    """
def reportMismatch(align):
    for i,c in enumerate(align):     #### want to return an iterator, i think
        if " "==str(x[2].seq):       ### where ever there's a mismatch in the alignment (no pipe),
            yield "{}".format(i)     ### return the column and its index
    for i in reportMismatch():
        with open('Out.txt', 'a') as f:   ### write the results to a file
            print(i, align.get_column(i), file=f)    ### including the position (index) and column contents

1 个答案:

答案 0 :(得分:0)

您的Python脚本需要主入口点才能运行它。

在脚本底部添加以下内容

if __name__ == '__main__':
  # Call the function you want to invoke.

然后你至少看到你的功能被执行了。然后你可以进一步开始调试。