Skip to content

Instantly share code, notes, and snippets.

@ethanagb
Created May 20, 2014 19:13
Show Gist options
  • Save ethanagb/1eaa8273d51133a1caf4 to your computer and use it in GitHub Desktop.
Save ethanagb/1eaa8273d51133a1caf4 to your computer and use it in GitHub Desktop.
#from pprint import pprint
FN ='Trinity.fasta'
def get_data(fn):
with open(fn, mode='r') as fh:
header, fasta = "",""
for line in fh:
if line[0]=='>' and header:
yield header, fasta
header = line.strip()
fasta = ''
elif line[0]=='>':
header = line.strip()
else:
fasta += line.strip()
if header:
yield header, fasta
seqs = {}
for h,f in get_data(FN):
if h not in seqs or len(f)>len(seqs[h]):
seqs[h]=f
#pprint(seqs)
def new_fasta(x):
new_file = open(raw_input('Enter new file name: '), 'a')
y = x.replace(': ', '\n')
z = y.strip()
w = z.replace("', '",'\n')
q = w.replace("'",'')
new_file.write(q.strip())
x=str(seqs)
new_fasta(x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment