os
[color=]def
[color=]merge_fasta_files
(
[color=]directory
,
[color=]output_file
):
[color=]"""
[color=] Merges multiple fasta files from a specified directory into a single fasta file.
[color=] Parameters:
[color=] - directory (str): The path to the directory containing the fasta files.
[color=] - output_file (str): The path where the merged fasta file will be saved.
[color=] """
[color=]with
[color=]open
(output_file,
[color=]'w'
)
[color=]as
outfile:
[color=]# 遍历目录中的所有文件
[color=]for
filename
[color=]in
os.listdir(directory):
[color=]if
filename.endswith(
[color=]'.fasta'
):
[color=]# 确保只处理.fasta文件
filepath
[color=]=
os.path.join(directory, filename)
[color=]with
[color=]open
(filepath,
[color=]'r'
)
[color=]as
infile:
[color=]# 将文件内容写入输出文件
outfile.write(infile.read())
outfile.write(
[color=]'
[color=]\n
[color=]'
)
[color=]# 添加换行符以分隔不同的fasta文件
[color=]# 使用函数
directory_path
[color=]=
[color=]'C:/Users/Administrator/Desktop/No_protein/'
[color=]# 这里替换为你的fasta文件所在的文件夹路径
output_path
[color=]=
[color=]'C:/Users/Administrator/Desktop/No_protein/Tp_output.fasta'
[color=]# 这里替换为你想要保存合并后的文件的路径
merge_fasta_files(directory_path, output_path)