Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def yield_FASTA(f):
- header, seq = '', ''
- for line in f:
- if line.startswith('>'):
- if header:
- yield (header, seq)
- header, seq = line, ''
- else:
- header = line
- else:
- seq += filter( lambda x: not x.isdigit() and not x.isspace(), line )
- yield (header, seq)
- with open('fasta.txt') as f:
- for i in yield_FASTA(f):
- print i
- #Using this example fasta.txt
- '''
- > Fake Line
- AGCTACGACTAGCCGCGCGCTATATACTAGCATCGACATTTTTATATTAAGACGAGACTATCATATACTAGCGAGCGCGGCACTATATTTGCTCGACTACACAGCCATCAAGATCAACACATATATACTTCCCCTATACACCAACACAGCGGGGACGAATACTATCATCATCATCATCAGCGCGCGCGCAGCAGAGGAAGGAAGGAATTCCTCTACTCTATTTATAGACGCGASAGCAG
- > New Line
- AGTAGAT
- > Cat
- > Doghead
- AGTCG
- GAT
- GGG
- C
- GAGTCAG
- > Noodles
- G
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement