Mercurial > repos > jdv > albacore
annotate albacore_1D.py @ 7:ce1fa05ffb6c draft
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
author | jdv |
---|---|
date | Sat, 10 Mar 2018 15:43:07 -0500 |
parents | 3870c546db18 |
children | 3dfde840119e |
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 |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
10 from distutils.util import strtobool |
7
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
11 from tempfile import mkdtemp |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
12 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
13 def main(): |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
14 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
|
15 out_file = sys.argv[2] |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
16 out_fmt = sys.argv[3] |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
17 demux = strtobool( sys.argv[4] ) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
18 threads = sys.argv[5] |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
19 |
7
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
20 tempdir = mkdtemp() |
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
21 |
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
22 (flowcell, kit) = parse_meta(tar_file, tempdir) |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
23 |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
24 subprocess.call( |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
25 ["read_fast5_basecaller.py", |
7
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
26 "--input", tempdir, |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
27 "--worker_threads", threads, |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
28 "--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
|
29 "--flowcell", flowcell, |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
30 "--kit", kit, |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
31 "--recursive", |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
32 "--files_per_batch_folder", "0", |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
33 "--output_format", out_fmt, |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
34 "--reads_per_fastq_batch", "999999999" ] + |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
35 ["--barcoding"] * demux ) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
36 |
4
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
37 out_path = "out_dir/workspace" |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
38 pass_path = os.path.join( out_path, "pass" ) |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
39 if os.path.exists( pass_path ): |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
40 out_path = pass_path |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
41 if demux: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
42 #check for demuxed albacore output and copy to Galaxy output |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
43 final_dir = "final" |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
44 if not os.path.exists(final_dir): |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
45 os.makedirs(final_dir) |
4
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
46 dirs = glob.glob( os.path.join(out_path, "*") ) |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
47 for d in dirs: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
48 |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
49 if out_fmt == 'fastq': |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
50 bc = os.path.basename( os.path.normpath( d ) ) + ".fastq" |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
51 print(d) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
52 print(bc) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
53 out = os.path.join( final_dir, bc ) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
54 files = glob.glob( os.path.join( d, "*.fastq") ) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
55 if len(files) != 1: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
56 raise ValueError('No or multiple FASTQ output files found') |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
57 found_file = files[0] |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
58 shutil.copy(found_file, out) |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
59 |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
60 elif out_fmt == 'fast5': |
4
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
61 if (os.path.isfile(d)): |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
62 if (d.endswith('.fast5')): |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
63 bc = os.path.basename( os.path.normpath(d) ) + ".tar.gz" |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
64 files = [d] |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
65 else: |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
66 continue |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
67 else: |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
68 bc = os.path.basename( os.path.normpath( d ) ) + ".fast5.tar.gz" |
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
69 files = glob.glob( os.path.join( d, "**", "*.fast5"), recursive=True) |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
70 out = os.path.join( final_dir, bc ) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
71 if len(files) < 1: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
72 raise ValueError('No FAST5 output files found') |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
73 tar = tarfile.open(out, 'w:gz') |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
74 tar.add( d ) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
75 tar.close() |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
76 |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
77 else: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
78 raise ValueError('Bad output format specified') |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
79 |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
80 else: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
81 if out_fmt == 'fastq': |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
82 #check for single albacore output and copy to Galaxy output |
4
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
83 files = glob.glob( os.path.join(out_path, "*.fastq") ) |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
84 if len(files) != 1: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
85 raise ValueError('No or multiple FASTQ output files found') |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
86 found_file = files[0] |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
87 shutil.copy(found_file, out_file) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
88 elif out_fmt == 'fast5': |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
89 #check for single albacore output and copy to Galaxy output |
4
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
90 files = glob.glob( os.path.join(out_path,"**","*.fast5"), recursive=True ) |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
91 if len(files) < 1: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
92 raise ValueError('No FAST5 output files found') |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
93 tar = tarfile.open(out_file, 'w:gz') |
4
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
94 tar.add(out_path) |
1
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
95 tar.close() |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
96 else: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
97 raise ValueError('Bad output format specified') |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
98 |
7
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
99 try: |
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
100 shutil.rmtree(tempdir) |
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
101 except: |
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
102 print("Unable to remove temp directory:", sys.exc_info()[0]) |
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
103 raise |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
104 |
7
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
105 |
ce1fa05ffb6c
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents:
6
diff
changeset
|
106 def parse_meta(fn, in_dir): |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
107 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
108 try: |
3
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
109 # python's tarfile interface does not sanitize file paths within |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
110 # tarballs, which can be a big security risk. GNU tar does sanitize by |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
111 # default, so it's easier/safer here just to call the system tar |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
112 subprocess.call([ |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
113 "tar", |
4
8a9f61d08201
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents:
3
diff
changeset
|
114 "--warning=no-unknown-keyword", |
3
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
115 "-xf", |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
116 fn, |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
117 "-C", |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
118 in_dir]) |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
119 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
120 files = glob.glob( |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
121 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
|
122 recursive=True |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
123 ) |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
124 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
|
125 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
|
126 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
|
127 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
128 f = h5py.File(test_file,"r") |
6
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
129 #TODO: clean up attribute checking |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
130 try: |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
131 flowcell = f["/UniqueGlobalKey/context_tags"].attrs["flowcell"].upper() |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
132 except: |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
133 try: |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
134 flowcell = f["/UniqueGlobalKey/context_tags"].attrs["flowcell_type"].upper() |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
135 except: |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
136 raise ValueError('No attribute found for flowcell type') |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
137 try: |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
138 kit = f["/UniqueGlobalKey/context_tags"].attrs["sequencing_kit"].upper() |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
139 except: |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
140 raise ValueError('No attribute found for sequencing kit') |
3870c546db18
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents:
4
diff
changeset
|
141 |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
142 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
|
143 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
|
144 raise |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
145 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
146 except: |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
147 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
|
148 raise |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
149 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
150 return flowcell, kit |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
151 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
152 if __name__ == "__main__" : |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
153 main() |