如何像tsv一样从python保存输出 [英] How to save output from python like tsv
本文介绍了如何像tsv一样从python保存输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用biopython软件包,我想保存tsv文件之类的结果.此输出从打印到tsv.
I am using biopython package and I would like to save result like tsv file. This output from print to tsv.
for record in SeqIO.parse("/home/fil/Desktop/420_2_03_074.fastq", "fastq"):
print ("%s %s %s" % (record.id,record.seq, record.format("qual")))
谢谢.
推荐答案
这很简单,除了打印它,您还需要将其写到文件中.
That is fairly simple , instead of printing it you need to write that to a file.
with open("records.tsv", "w") as record_file:
for record in SeqIO.parse("/home/fil/Desktop/420_2_03_074.fastq", "fastq"):
record_file.write("%s %s %s\n" % (record.id,record.seq, record.format("qual")))
如果要命名文件中的各个列,则可以使用:
And if you want to name the various columns in the file then you can use:
record_file.write("Record_Id Record_Seq Record_Qal\n")
因此完整的代码可能如下所示:
So the complete code may look like:
with open("records.tsv", "w") as record_file:
record_file.write("Record_Id Record_Seq Record_Qal\n")
for record in SeqIO.parse("/home/fil/Desktop/420_2_03_074.fastq", "fastq"):
record_file.write(str(record.id)+" "+str(record.seq)+" "+ str(record.format("qual"))+"\n")
这篇关于如何像tsv一样从python保存输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文