#! /bin/env python3
import csv
with open('records.tsv', 'w') as tsvfile:
writer = csv.writer(tsvfile, delimiter='\t', newline='\n')
for record in SeqIO.parse("/home/fil/Desktop/420_2_03_074.fastq", "fastq"):
writer.writerow([record.id, record.seq, record.format("qual")])
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")))
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")
我的首选解决方案是使用CSV模块。这是一个标准模块,所以:
下面的代码片段应该可以帮您实现这一点:
注意,这是针对Python 3.x的。如果您使用的是2.x,那么
open
和writer = ...
将略有不同。如果要使用
.tsv
在TensorBoard中标记单词嵌入,请使用以下代码片段。它使用CSV模块(请参见Doug's answer)。word_count
是这样的元组列表:这是相当简单的,而不是打印它,你需要写一个文件。
如果要命名文件中的各个列,则可以使用:
所以完整的代码可能看起来像:
相关问题 更多 >
编程相关推荐