Skip to content

Instantly share code, notes, and snippets.

@kescobo
Last active August 29, 2015 14:12
Show Gist options
  • Save kescobo/ee69d7fd087c3e3192ca to your computer and use it in GitHub Desktop.
Save kescobo/ee69d7fd087c3e3192ca to your computer and use it in GitHub Desktop.
import re
#open file to read
with open('test.fasta', 'r') as seqs:
seqFile = (open('throwaway.txt', 'a+'))
for line in seqs:
if re.search('^>[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]', line):
seqFile.close()
seqFile = open('%s.fasta' % line, 'a+')
seqs.next()
else:
seqFile.write('%s' % line)
seqFile.close()
import re
#open file to read
with open('test.fasta', 'r') as seqs:
#seqFile = (open('throwaway.txt', 'a+'))
mydict = {}
for line in seqs:
if re.search('^>[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]', line):
fileName = line + '.fasta'
if fileName not in mydict:
mydict[fileName] = open(fileName, 'a+')
seqs.next()
else:
#seqFile.write('%s' % line)
mydict[fileName].write('%s' % line)
seqFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment