首先将文件保存在一个文件夹下:
image.png
运行python脚本:
# 读取fasta文件头
import os
path_files=os.listdir("F:\文件处理\\fasta_dir")# 获取目录下的文件
out_file=open('header','w')
for file in path_files:
filename=os.path.basename(file)#获取文件名
fasta_file=open("F:\\文件处理\\fasta_dir\\"+filename,'r')#打开文件
for line in fasta_file:
if line[0]=='>':
print (line)
out_file.writelines(line)
out_file.close()
输出结果
>NC_007122.7:21138038-21139481 Danio rerio strain Tuebingen chromosome 11, GRCz11 Primary Assembly
>NC_000001.11:206767603-206772494 Homo sapiens chromosome 1, GRCh38.p12 Primary Assembly
>NC_000067.6:131019845-131024970 Mus musculus strain C57BL/6J chromosome 1, GRCm38.p4 C57BL/6J
>NC_000019.10:58346806-58353499 Homo sapiens chromosome 19, GRCh38.p12 Primary Assembly
>NC_005112.4:47738933-47743392 Rattus norvegicus strain mixed chromosome 13, Rnor_6.0
网友评论