Skip to content

Instantly share code, notes, and snippets.

@nickloman
Created June 9, 2014 16:01

Revisions

  1. nickloman created this gist Jun 9, 2014.
    20 changes: 20 additions & 0 deletions fast5tofasta.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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()