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