Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. def yield_FASTA(f):
  2.  
  3.     header, seq = '', ''
  4.  
  5.     for line in f:
  6.         if line.startswith('>'):
  7.             if header:
  8.                 yield (header, seq)
  9.                 header, seq = line, ''
  10.             else:
  11.                 header = line
  12.  
  13.         else:
  14.             seq += filter( lambda x: not x.isdigit() and not x.isspace(), line )
  15.  
  16.     yield (header, seq)
  17.  
  18. with open('fasta.txt') as f:
  19.     for i in yield_FASTA(f):
  20.         print i
  21.  
  22.  
  23.  
  24. #Using this example fasta.txt
  25. '''
  26. > Fake Line
  27. AGCTACGACTAGCCGCGCGCTATATACTAGCATCGACATTTTTATATTAAGACGAGACTATCATATACTAGCGAGCGCGGCACTATATTTGCTCGACTACACAGCCATCAAGATCAACACATATATACTTCCCCTATACACCAACACAGCGGGGACGAATACTATCATCATCATCATCAGCGCGCGCGCAGCAGAGGAAGGAAGGAATTCCTCTACTCTATTTATAGACGCGASAGCAG
  28. > New Line
  29. AGTAGAT
  30. > Cat
  31. > Doghead
  32. AGTCG
  33. GAT
  34. GGG
  35. C
  36. GAGTCAG
  37. > Noodles
  38. G
  39. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement