Mercurial > repos > jdv > nanopolish
diff nanopolish_extract.py @ 0:2136c2725fc4 draft
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopolish commit 0206b7bd377b39ad28592b0a02588f40575efd3e-dirty
author | jdv |
---|---|
date | Wed, 06 Sep 2017 12:15:45 -0400 |
parents | |
children | e4b6d4a53f2e |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nanopolish_extract.py Wed Sep 06 12:15:45 2017 -0400 @@ -0,0 +1,51 @@ +#!/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] # currently unused + + extract_fast5(tar_file) + + subprocess.call(["nanopolish", + "extract", + "--recurse", + "--fastq", + "--output", out_file, + "in_dir" ]) + +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') + + except OSError as e: + print("Unexpected error:", e.strerror) + raise + + except: + print("Unexpected error:", sys.exc_info()[0]) + raise + +if __name__ == "__main__" : + main()