Mercurial > repos > jdv > albacore
annotate albacore_1D.py @ 3:d561e3f9ccbb draft
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
author | jdv |
---|---|
date | Tue, 03 Oct 2017 20:12:09 -0400 |
parents | 0a4f83207e53 |
children | 8a9f61d08201 |
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 |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
34 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
|
35 #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
|
36 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
|
37 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
|
38 os.makedirs(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
|
39 dirs = glob.glob("out_dir/workspace/*") |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
40 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
|
41 |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 |
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 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
|
54 bc = os.path.basename( os.path.normpath( d ) ) + ".fast5.tar.gz" |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
55 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
|
56 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
|
57 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
|
58 files = glob.glob( os.path.join( d, "**", "*.fast5"), recursive=True) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 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
|
64 |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
65 else: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
66 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
|
67 |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
68 else: |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
69 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
|
70 #check for single 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
|
71 files = glob.glob("out_dir/workspace/*.fastq") |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
72 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
|
73 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
|
74 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
|
75 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
|
76 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
|
77 #check for single 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
|
78 files = glob.glob("out_dir/workspace/**/*.fast5", recursive=True) |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
79 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
|
80 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
|
81 tar = tarfile.open(out_file, '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
|
82 tar.add("out_dir/workspace") |
0a4f83207e53
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents:
0
diff
changeset
|
83 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
|
84 else: |
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('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
|
86 |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
87 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
88 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
|
89 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
90 try: |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
91 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
|
92 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
|
93 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
|
94 |
3
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
95 # 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
|
96 # 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
|
97 # 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
|
98 subprocess.call([ |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
99 "tar", |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
100 "-xf", |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
101 fn, |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
102 "-C", |
d561e3f9ccbb
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit d8cc434bd1704b2834f89b7d91370f356e3ac85a
jdv
parents:
1
diff
changeset
|
103 in_dir]) |
0
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
104 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
105 files = glob.glob( |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
106 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
|
107 recursive=True |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
108 ) |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
109 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
|
110 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
|
111 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
|
112 |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
113 f = h5py.File(test_file,"r") |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
114 flowcell = f["/UniqueGlobalKey/context_tags"].attrs["flowcell"].upper() |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
115 kit = f["/UniqueGlobalKey/context_tags"].attrs["sequencing_kit"].upper() |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
116 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
|
117 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
|
118 raise |
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 except: |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
121 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
|
122 raise |
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 return flowcell, kit |
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 __name__ == "__main__" : |
f8e25d69167d
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff
changeset
|
127 main() |