-2
私は一連の短いDNAアライメントを持っており、それらのミスマッチの位置と種類を追跡したいと思います。Pythonスクリプト:出力はしませんが、エラーはありませんか?
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
あなたの全体のスクリプトですか?これらの機能を呼び出すことはありません。 –
行 'yield" {} "。format(i)'はジェネレータを作成します。あなたのコメントは、値を '返す 'ことができ、それを' yield'しないことを示しています。 –
サイドノート: 'itertools.groupby'は、グループの' key'値とグループ化された要素のジェネレータの2つの ''組 '(ペア)を返します。 'x [1:3]'はジェネレータだけを含む1タプルを作成します(スライスは2つの要素を要求しますが、インデックス1以降の要素は1つしかありません)。それを超えて、結果を使うときには、 'align'というグループの名前をつけてから' x'というインデックスを付けます。これは二重に間違っています。 'x'は存在せず、ジェネレータはインデックスに登録できません。あなたが実際に望んでいる 'groupby'ですか?他の 'groupby'が必要なのかもしれません。パンダから(それを使ったことはありません)? – ShadowRanger