我使用biopython从我的核苷酸比对计算位置特异性评分矩阵(PSSM)。 http://biopython.org/DIST/docs/tutorial/Tutorial.html#htoc255 所以,我的script.py是:
from Bio import AlignIO
from Bio.Align import AlignInfo
alignment = AlignIO.read("alignment_1.fasta", "fasta")
summary_align = AlignInfo.SummaryInfo(alignment)
consensus = summary_align.dumb_consensus()
my_pssm = summary_align.pos_specific_score_matrix(consensus, chars_to_ignore = ['N', '-'])
我想知道是否可以将my_pssm对象写入脚本内的文件?我在文档中找不到任何解决方案。现在我只能这样做:
python script.py > text.txt
但它并不适合我(我想用它作为批处理脚本)。
答案 0 :(得分:0)
您可以在脚本末尾添加print my_pssm
然后按照您的意愿python script.py > text.txt
对于不同的序列,您可以这样做:
for fasta in files:
alignment = AlignIO.read(fasta, "fasta")
summary_align = AlignInfo.SummaryInfo(alignment)
consensus = summary_align.dumb_consensus()
my_pssm = summary_align.pos_specific_score_matrix(consensus, chars_to_ignore = ['N', '-'])
file_pssm = fasta+"pssm"
with open(file_pssm) as f:
f.write(my_pssm)