Python 合并 FASTA 文件:高效合并多个序列文件
以下是 Python 代码,用于合并一个文件夹中的多个 FASTA 序列文件:
import os
# 输入文件夹路径和输出文件名
input_dir = 'path/to/folder'
output_file = 'merged.fasta'
# 打开输出文件
with open(output_file, 'w') as out_file:
# 循环遍历文件夹中的所有文件
for file_name in os.listdir(input_dir):
# 检查文件扩展名是否为.fasta
if file_name.endswith('.fasta'):
# 打开FASTA文件
with open(os.path.join(input_dir, file_name)) as in_file:
# 读取文件内容并写入输出文件
out_file.write(in_file.read())
这段代码将打开一个指定路径的文件夹,并循环遍历该文件夹中的所有文件。对于每个以‘.fasta’为扩展名的文件,它将打开该文件,读取其中的内容,并将其写入输出文件。最终,输出文件将包含所有FASTA序列文件的内容。
原文地址: https://www.cveoy.top/t/topic/lMeb 著作权归作者所有。请勿转载和采集!