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