annotate albacore_1D.py @ 6:3870c546db18 draft

planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
author jdv
date Tue, 23 Jan 2018 14:24:39 -0500
parents 8a9f61d08201
children ce1fa05ffb6c
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
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
11
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
12 def main():
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
13 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
14 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
15 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
16 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
17 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
18
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
19 (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
20
1
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
21 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
22 ["read_fast5_basecaller.py",
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
23 "--input", "in_dir",
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
24 "--worker_threads", threads,
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
25 "--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
26 "--flowcell", flowcell,
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
27 "--kit", kit,
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
28 "--recursive",
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
29 "--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
30 "--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
31 "--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
32 ["--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
33
4
8a9f61d08201 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents: 3
diff changeset
34 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
35 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
36 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
37 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
38 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
39 #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
40 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
41 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
42 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
43 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
44 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
45
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 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
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55 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
56
1
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
57 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
58 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
59 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
60 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
61 files = [d]
8a9f61d08201 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents: 3
diff changeset
62 else:
8a9f61d08201 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents: 3
diff changeset
63 continue
8a9f61d08201 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents: 3
diff changeset
64 else:
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 ) ) + ".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
66 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
67 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
68 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
69 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
70 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
71 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
72 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
73
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
74 else:
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
75 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
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 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
79 #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
80 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
81 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
82 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
83 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
84 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
85 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
86 #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
87 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
88 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
89 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
90 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
91 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
92 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
93 else:
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('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
95
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
96
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
97 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
98
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
99 try:
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
100 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
101 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
102 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
103
3
d561e3f9ccbb planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents: 1
diff changeset
104 # 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
105 # 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
106 # 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
107 subprocess.call([
d561e3f9ccbb planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents: 1
diff changeset
108 "tar",
4
8a9f61d08201 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
jdv
parents: 3
diff changeset
109 "--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
110 "-xf",
d561e3f9ccbb planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents: 1
diff changeset
111 fn,
d561e3f9ccbb planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents: 1
diff changeset
112 "-C",
d561e3f9ccbb planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents: 1
diff changeset
113 in_dir])
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
114
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
115 files = glob.glob(
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
116 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
117 recursive=True
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
118 )
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
119 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
120 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
121 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
122
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
123 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
124 #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
125 try:
3870c546db18 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents: 4
diff changeset
126 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
127 except:
3870c546db18 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents: 4
diff changeset
128 try:
3870c546db18 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents: 4
diff changeset
129 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
130 except:
3870c546db18 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 1514f4060da0b3a7866ac36d8a389828cbf48bd7
jdv
parents: 4
diff changeset
131 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
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 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
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 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
136
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
137 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
138 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
139 raise
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
140
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
141 except:
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
142 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
143 raise
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
144
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
145 return flowcell, kit
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
146
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
147 if __name__ == "__main__" :
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
148 main()