Mercurial > repos > jdv > nanopolish
comparison nanopolish_extract.py @ 2:e4b6d4a53f2e draft
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/nanopolish commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
author | jdv |
---|---|
date | Tue, 03 Oct 2017 21:23:56 -0400 |
parents | 2136c2725fc4 |
children |
comparison
equal
deleted
inserted
replaced
1:a5db82bec597 | 2:e4b6d4a53f2e |
---|---|
1 #!/usr/bin/env python3 | 1 #!/usr/bin/env python3 |
2 | 2 |
3 import sys, os | 3 import sys, os |
4 import glob | 4 import glob |
5 import tarfile | |
6 import subprocess | 5 import subprocess |
7 import shutil | 6 import shutil |
8 import h5py | 7 import h5py |
9 import numpy as np | 8 import numpy as np |
10 | 9 |
13 out_file = sys.argv[2] | 12 out_file = sys.argv[2] |
14 threads = sys.argv[3] # currently unused | 13 threads = sys.argv[3] # currently unused |
15 | 14 |
16 extract_fast5(tar_file) | 15 extract_fast5(tar_file) |
17 | 16 |
18 subprocess.call(["nanopolish", | 17 subprocess.call([ |
19 "extract", | 18 "nanopolish", |
20 "--recurse", | 19 "extract", |
20 "--recurse", | |
21 "--fastq", | 21 "--fastq", |
22 "--output", out_file, | 22 "--output", out_file, |
23 "in_dir" ]) | 23 "in_dir" ]) |
24 | 24 |
25 def extract_fast5(fn): | 25 def extract_fast5(fn): |
27 try: | 27 try: |
28 in_dir = "in_dir" | 28 in_dir = "in_dir" |
29 if not os.path.exists(in_dir): | 29 if not os.path.exists(in_dir): |
30 os.makedirs(in_dir) | 30 os.makedirs(in_dir) |
31 | 31 |
32 tar = tarfile.open(fn, mode='r') | 32 # python's tarfile interface does not sanitize file paths within |
33 tar.extractall(path=in_dir) | 33 # tarballs, which can be a big security risk. GNU tar does sanitize by |
34 # default, so it's easier/safer here just to call the system tar | |
35 subprocess.call([ | |
36 "tar", | |
37 "-xf", | |
38 fn, | |
39 "-C", | |
40 "in_dir"]) | |
34 | 41 |
35 files = glob.glob( | 42 files = glob.glob( |
36 os.path.join(in_dir, "**", "*.fast5"), | 43 os.path.join(in_dir, "**", "*.fast5"), |
37 recursive=True | 44 recursive=True |
38 ) | 45 ) |