此代碼寫作列表CSV
for record in SeqIO.parse(open(file, 'rU'), 'fasta', generic_protein):
record_id = re.sub(r'\d+_(\d+_\d\#\d+)_\d+', r'\1', record.id)
if (not reference_sequence):
reference_sequence = record.seq
reference_name = record_id
#continue
print ",".join([reference_name, record_id, compare_seqs(reference_sequence, record.seq)])
使端子輸出,看起來像
7065_8#1,8987_2#53,
7065_8#1,8987_2#58,
7065_8#1,8987_2#61,
7065_8#1,8987_2#62,E-G [246]
7065_8#1,8987_2#65,N-K [71],Y-D [223]
我想通過線來寫這條線到CSV,有什麼建議?在嵌套列表
for record in SeqIO.parse(open(file, 'rU'), 'fasta', generic_protein):
record_id = re.sub(r'\d+_(\d+_\d\#\d+)_\d+', r'\1', record.id)
if (not reference_sequence):
reference_sequence = record.seq
reference_name = record_id
#continue
line= ",".join([reference_name, record_id, compare_seqs(reference_sequence, record.seq)])
with open(csvfile, "w") as output:
writer = csv.writer(output, lineterminator='\n')
writer.writerow([line])
也太棒了!謝謝 – user3234810 2014-09-22 14:16:15