comparison albacore_1D.py @ 0:f8e25d69167d draft

planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
author jdv
date Wed, 30 Aug 2017 02:47:27 -0400
parents
children 0a4f83207e53
comparison
equal deleted inserted replaced
-1:000000000000 0:f8e25d69167d
1 #!/usr/bin/env python3
2
3 import sys, os
4 import glob
5 import tarfile
6 import subprocess
7 import shutil
8 import h5py
9 import numpy as np
10
11 def main():
12 tar_file = sys.argv[1]
13 out_file = sys.argv[2]
14 threads = sys.argv[3]
15
16 (flowcell, kit) = parse_meta(tar_file)
17
18 subprocess.call(["read_fast5_basecaller.py",
19 "--input", "in_dir",
20 "--worker_threads", threads,
21 "--save_path", "out_dir",
22 "--flowcell", flowcell,
23 "--kit", kit,
24 "--recursive",
25 "--files_per_batch_folder", "0",
26 "--output_format", "fastq",
27 "--reads_per_fastq_batch", "999999999" ])
28
29 #check for single albacore output and copy to Galaxy output
30 files = glob.glob("out_dir/workspace/*.fastq")
31 if len(files) != 1:
32 raise ValueError('No or multiple FASTQ output files found')
33 found_file = files[0]
34 shutil.copy(found_file, out_file)
35
36 def parse_meta(fn):
37
38 try:
39 in_dir = "in_dir"
40 if not os.path.exists(in_dir):
41 os.makedirs(in_dir)
42
43 tar = tarfile.open(fn, mode='r')
44 tar.extractall(path=in_dir)
45
46 files = glob.glob(
47 os.path.join(in_dir, "**", "*.fast5"),
48 recursive=True
49 )
50 if len(files) < 1:
51 raise ValueError('No FAST5 files found')
52 test_file = files[0]
53
54 f = h5py.File(test_file,"r")
55 flowcell = f["/UniqueGlobalKey/context_tags"].attrs["flowcell"].upper()
56 kit = f["/UniqueGlobalKey/context_tags"].attrs["sequencing_kit"].upper()
57 except OSError as e:
58 print("Unexpected error:", e.strerror)
59 raise
60
61 except:
62 print("Unexpected error:", sys.exc_info()[0])
63 raise
64
65 return flowcell, kit
66
67 if __name__ == "__main__" :
68 main()