view scrappie_raw.py @ 2:b4721d6ecae2 draft

planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/scrappie commit 669955c21a5e770a6777269de6b1d2c375a704e3
author jdv
date Fri, 08 Sep 2017 11:17:48 -0400
parents 30c2b84b4117
children 632c50fe83ba
line wrap: on
line source

#!/usr/bin/env python3

import sys, os
import glob
import tarfile
import subprocess
import shutil
import h5py
import numpy as np

def main():
    tar_file = sys.argv[1]
    out_file = sys.argv[2]
    threads  = sys.argv[3]

    extract_fast5(tar_file)
    with open(out_file, "w") as outfile:
        subprocess.call(["scrappie",
            "raw",
            "--threads", threads,
            "--outformat", "fasta",
            "in_dir" ],
            stdout=outfile )

def extract_fast5(fn):

    try:
        in_dir = "in_dir"
        if not os.path.exists(in_dir):
            os.makedirs(in_dir)

        tar = tarfile.open(fn, mode='r')
        tar.extractall(path=in_dir)

        files = glob.glob(
            os.path.join(in_dir, "**", "*.fast5"),
            recursive=True
        )
        if len(files) < 1:
            raise ValueError('No FAST5 files found')
        for f in files:
            shutil.copy(f, in_dir)

    except OSError as e:
        print("Unexpected error:", e.strerror)
        raise

    except:
        print("Unexpected error:", sys.exc_info()[0])
        raise

if __name__ == "__main__" :
    main()