annotate albacore_1D.py @ 9:710ccd01ae81 draft default tip

planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 77215a157940a91a5f46b71f85163dc477434668-dirty
author jdv
date Sun, 05 Aug 2018 12:24:31 -0400
parents 3dfde840119e
children
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
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():
8
3dfde840119e planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 8bb4eaadc31e6b986bee59392559a825c782447c-dirty
jdv
parents: 7
diff changeset
14 tar_file = sys.argv[1]
3dfde840119e planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 8bb4eaadc31e6b986bee59392559a825c782447c-dirty
jdv
parents: 7
diff changeset
15 out_file = sys.argv[2]
3dfde840119e planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 8bb4eaadc31e6b986bee59392559a825c782447c-dirty
jdv
parents: 7
diff changeset
16 out_fmt = sys.argv[3]
3dfde840119e planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 8bb4eaadc31e6b986bee59392559a825c782447c-dirty
jdv
parents: 7
diff changeset
17 demux = strtobool( sys.argv[4] )
3dfde840119e planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 8bb4eaadc31e6b986bee59392559a825c782447c-dirty
jdv
parents: 7
diff changeset
18 disable_filt = strtobool( sys.argv[5] )
3dfde840119e planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 8bb4eaadc31e6b986bee59392559a825c782447c-dirty
jdv
parents: 7
diff changeset
19 threads = sys.argv[6]
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
20
7
ce1fa05ffb6c planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents: 6
diff changeset
21 tempdir = mkdtemp()
ce1fa05ffb6c planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents: 6
diff changeset
22
ce1fa05ffb6c planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents: 6
diff changeset
23 (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
24
1
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
25 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
26 ["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
27 "--input", tempdir,
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
28 "--worker_threads", threads,
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
29 "--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
30 "--flowcell", flowcell,
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
31 "--kit", kit,
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
32 "--recursive",
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
33 "--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
34 "--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
35 "--reads_per_fastq_batch", "999999999" ] +
8
3dfde840119e planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 8bb4eaadc31e6b986bee59392559a825c782447c-dirty
jdv
parents: 7
diff changeset
36 ["--barcoding"] * demux +
3dfde840119e planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 8bb4eaadc31e6b986bee59392559a825c782447c-dirty
jdv
parents: 7
diff changeset
37 ["--disable_filtering"] * disable_filt )
1
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
38
4
8a9f61d08201 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents: 3
diff changeset
39 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
40 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
41 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
42 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
43 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
44 #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
45 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
46 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
47 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
48 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
49 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
50
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
51 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
52 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
53 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
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61
1
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
62 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
63 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
64 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
65 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
66 files = [d]
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 continue
8a9f61d08201 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents: 3
diff changeset
69 else:
8a9f61d08201 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents: 3
diff changeset
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
79 else:
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
80 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
81
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
82 else:
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
83 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
84 #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
85 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
86 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
87 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
88 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
89 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
90 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
91 #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
92 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
93 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
94 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
95 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
96 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
97 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
98 else:
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
99 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
100
7
ce1fa05ffb6c planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents: 6
diff changeset
101 try:
ce1fa05ffb6c planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents: 6
diff changeset
102 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
103 except:
ce1fa05ffb6c planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents: 6
diff changeset
104 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
105 raise
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
106
7
ce1fa05ffb6c planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents: 6
diff changeset
107
ce1fa05ffb6c planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 00096785a6bc71027828388a53a61b9d22fdaadf
jdv
parents: 6
diff changeset
108 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
109
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
110 try:
3
d561e3f9ccbb planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents: 1
diff changeset
111 # 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
112 # 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
113 # 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
114 subprocess.call([
d561e3f9ccbb planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents: 1
diff changeset
115 "tar",
4
8a9f61d08201 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents: 3
diff changeset
116 "--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
117 "-xf",
d561e3f9ccbb planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents: 1
diff changeset
118 fn,
d561e3f9ccbb planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents: 1
diff changeset
119 "-C",
d561e3f9ccbb planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents: 1
diff changeset
120 in_dir])
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
121
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
122 files = glob.glob(
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
123 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
124 recursive=True
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
125 )
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
126 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
127 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
128 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
129
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
130 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
131 #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
132 try:
3870c546db18 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents: 4
diff changeset
133 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
134 except:
3870c546db18 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents: 4
diff changeset
135 try:
3870c546db18 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents: 4
diff changeset
136 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
137 except:
3870c546db18 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents: 4
diff changeset
138 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
139 try:
3870c546db18 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents: 4
diff changeset
140 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
141 except:
3870c546db18 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents: 4
diff changeset
142 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
143
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
144 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
145 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
146 raise
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
147
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
148 except:
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
149 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
150 raise
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 return flowcell, kit
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
153
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
154 if __name__ == "__main__" :
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
155 main()