-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSplit_fasta.py
More file actions
23 lines (21 loc) · 1007 Bytes
/
Split_fasta.py
File metadata and controls
23 lines (21 loc) · 1007 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'''If you have a single fna file with multiple fasta within and want to split up into individual files for each fasta use this script. I modified it to change the header name as well'''
#!usr/bin/env python
import os
def splitfasta_file(fasta):
fin=open(fasta,"r")
count=0
for line in fin:
if line.startswith('>'):
line=line.split('|')
fout=open("gi"+''+line[1]+"_genomic.tax.fna","w")
count+=1
fout.write('>'+line[1]+' '+ line[4]) # this was added to change the name of the fasta header but you can change it to simple fout.write(line) to simply write the fasta header in the original file
else:
fout.write(line)
if line.startswith('>'):
pass
fout.close()
fin.close()
print "There are "+str(count)+ " fasta headers"
return count
# splitfasta_file(fasta="/Volumes/Transcend/Candidatus_Bacteroides_periocalifornicus/LIIK01.1.fsa_nt")# change this to file desired