Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (24 sloc) 881 Bytes
#!/usr/bin/env python
import os
import sys
"""Modify Fasta headers in *.fasta files to include the raw filename
(without the extension)"""
if __name__ == '__main__':
if not sys.argv[1:]:
print "Please provide one or more directories in which there are",
print "fasta files to be processed."
def update_headers(d):
fastas = filter(lambda f: f.endswith('.fasta'), os.listdir(d))
for f in fastas:
base = os.path.join(d, f)
if not os.path.exists(base + '.bak'):
open(base + '.bak', 'w').write(open(base).read())
src = open(base)
src.readline() # skip header
data =
dest = open(base, 'w')
print >> dest, '>' + f[:-6]
map(update_headers, sys.argv[1:])