Skip to content

Instantly share code, notes, and snippets.

@nickloman
Created June 9, 2014 16:01
Show Gist options
  • Save nickloman/3345d05e3a4642b5306c to your computer and use it in GitHub Desktop.
Save nickloman/3345d05e3a4642b5306c to your computer and use it in GitHub Desktop.
fast5tofasta.py
import h5py
from Bio import SeqIO
from StringIO import StringIO
import sys
keys = {'template' : '/Analyses/Basecall_2D_000/BaseCalled_template/Fastq',
'complement' : '/Analyses/Basecall_2D_000/BaseCalled_complement/Fastq',
'twodirections' : '/Analyses/Basecall_2D_000/BaseCalled_2D/Fastq'}
for fn in sys.argv[1:]:
hdf = h5py.File(fn, 'r')
for id, key in keys.iteritems():
try:
fq = hdf[key][()]
rec = SeqIO.read(StringIO(fq), "fastq")
rec.id += "_" + id
SeqIO.write([rec], sys.stdout, "fasta")
except Exception, e:
pass
hdf.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment