把各个fasta格式文件批量合并,但合并后的文件还带有比对标记“-”。  

    
#==========================================
# This code was written by Sihua Peng, PhD.
#==========================================

from Bio import SeqIO
import csv

# 从accession_numbers.csv读取待合并的文件名
#A2-generate-sample-1.fasta
#A2-generate-sample-2.fasta
#A2-generate-sample-3.fasta
#....
input_files = []
with open('A2-generated-89-samples.csv', 'r') as csvfile:
    csvreader = csv.reader(csvfile)
    for row in csvreader:
        input_files.extend(row)

# 输出文件
output_file = 'A2-generated-89-samples.fasta'
#这个合并样本后的文件还带有比对标记“-”

# 合并序列并保存为FASTA格式文件
with open(output_file, 'w') as output_handle:
    for input_file in input_files:
        with open(input_file, 'r') as input_handle:
            records = SeqIO.parse(input_handle, 'fasta')
            SeqIO.write(records, output_handle, 'fasta')