annotate albacore_1D.py @ 1:0a4f83207e53 draft

planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
author jdv
date Wed, 06 Sep 2017 12:12:52 -0400
parents f8e25d69167d
children d561e3f9ccbb
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 import tarfile
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
11 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
12
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
13 def main():
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
14 tar_file = sys.argv[1]
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
15 out_file = sys.argv[2]
1
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
16 out_fmt = sys.argv[3]
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
17 demux = strtobool( sys.argv[4] )
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
18 threads = sys.argv[5]
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
19
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
20 (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
21
1
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
22 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
23 ["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
24 "--input", "in_dir",
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
25 "--worker_threads", threads,
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
26 "--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
27 "--flowcell", flowcell,
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
28 "--kit", kit,
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
29 "--recursive",
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
30 "--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
31 "--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
32 "--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
33 ["--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
34
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
35 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
36 #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
37 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
38 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
39 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
40 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
41 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
42
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 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
44 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
45 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
46 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
47 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
48 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
49 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
50 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
51 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
52 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
53
1
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
54 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
55 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64 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
65
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
66 else:
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
67 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
68
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
69 else:
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
70 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
71 #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
72 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
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 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
75 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
76 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
77 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
78 #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
79 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
80 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
81 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
82 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
83 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
84 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
85 else:
0a4f83207e53 planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 4aa7a76a7b29c425dd89a020979e835d785d3c95-dirty
jdv
parents: 0
diff changeset
86 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
87
0
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
88
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
89 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
90
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
91 try:
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
92 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
93 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
94 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
95
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
96 tar = tarfile.open(fn, mode='r')
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
97 tar.extractall(path=in_dir)
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
98
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
99 files = glob.glob(
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
100 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
101 recursive=True
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
102 )
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
103 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
104 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
105 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
106
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
107 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
108 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
109 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
110 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
111 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
112 raise
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
113
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
114 except:
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
115 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
116 raise
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
117
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
118 return flowcell, kit
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 if __name__ == "__main__" :
f8e25d69167d planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit bf5788ad5a3293446a50a3246b44ba09174c9b71
jdv
parents:
diff changeset
121 main()