Mercurial > repos > jdv > albacore
comparison albacore_1D.py @ 4:8a9f61d08201 draft
planemo upload for repository https://github.com/jvolkening/galaxy-tools/tree/master/tools/albacore commit 9a7fa5134243f712595bef72121b8006be8a318b
author | jdv |
---|---|
date | Fri, 13 Oct 2017 16:13:22 -0400 |
parents | d561e3f9ccbb |
children | 3870c546db18 |
comparison
equal
deleted
inserted
replaced
3:d561e3f9ccbb | 4:8a9f61d08201 |
---|---|
29 "--files_per_batch_folder", "0", | 29 "--files_per_batch_folder", "0", |
30 "--output_format", out_fmt, | 30 "--output_format", out_fmt, |
31 "--reads_per_fastq_batch", "999999999" ] + | 31 "--reads_per_fastq_batch", "999999999" ] + |
32 ["--barcoding"] * demux ) | 32 ["--barcoding"] * demux ) |
33 | 33 |
34 out_path = "out_dir/workspace" | |
35 pass_path = os.path.join( out_path, "pass" ) | |
36 if os.path.exists( pass_path ): | |
37 out_path = pass_path | |
34 if demux: | 38 if demux: |
35 #check for demuxed albacore output and copy to Galaxy output | 39 #check for demuxed albacore output and copy to Galaxy output |
36 final_dir = "final" | 40 final_dir = "final" |
37 if not os.path.exists(final_dir): | 41 if not os.path.exists(final_dir): |
38 os.makedirs(final_dir) | 42 os.makedirs(final_dir) |
39 dirs = glob.glob("out_dir/workspace/*") | 43 dirs = glob.glob( os.path.join(out_path, "*") ) |
40 for d in dirs: | 44 for d in dirs: |
41 | 45 |
42 if out_fmt == 'fastq': | 46 if out_fmt == 'fastq': |
43 bc = os.path.basename( os.path.normpath( d ) ) + ".fastq" | 47 bc = os.path.basename( os.path.normpath( d ) ) + ".fastq" |
44 print(d) | 48 print(d) |
49 raise ValueError('No or multiple FASTQ output files found') | 53 raise ValueError('No or multiple FASTQ output files found') |
50 found_file = files[0] | 54 found_file = files[0] |
51 shutil.copy(found_file, out) | 55 shutil.copy(found_file, out) |
52 | 56 |
53 elif out_fmt == 'fast5': | 57 elif out_fmt == 'fast5': |
54 bc = os.path.basename( os.path.normpath( d ) ) + ".fast5.tar.gz" | 58 if (os.path.isfile(d)): |
55 print(d) | 59 if (d.endswith('.fast5')): |
56 print(bc) | 60 bc = os.path.basename( os.path.normpath(d) ) + ".tar.gz" |
61 files = [d] | |
62 else: | |
63 continue | |
64 else: | |
65 bc = os.path.basename( os.path.normpath( d ) ) + ".fast5.tar.gz" | |
66 files = glob.glob( os.path.join( d, "**", "*.fast5"), recursive=True) | |
57 out = os.path.join( final_dir, bc ) | 67 out = os.path.join( final_dir, bc ) |
58 files = glob.glob( os.path.join( d, "**", "*.fast5"), recursive=True) | |
59 if len(files) < 1: | 68 if len(files) < 1: |
60 raise ValueError('No FAST5 output files found') | 69 raise ValueError('No FAST5 output files found') |
61 tar = tarfile.open(out, 'w:gz') | 70 tar = tarfile.open(out, 'w:gz') |
62 tar.add( d ) | 71 tar.add( d ) |
63 tar.close() | 72 tar.close() |
66 raise ValueError('Bad output format specified') | 75 raise ValueError('Bad output format specified') |
67 | 76 |
68 else: | 77 else: |
69 if out_fmt == 'fastq': | 78 if out_fmt == 'fastq': |
70 #check for single albacore output and copy to Galaxy output | 79 #check for single albacore output and copy to Galaxy output |
71 files = glob.glob("out_dir/workspace/*.fastq") | 80 files = glob.glob( os.path.join(out_path, "*.fastq") ) |
72 if len(files) != 1: | 81 if len(files) != 1: |
73 raise ValueError('No or multiple FASTQ output files found') | 82 raise ValueError('No or multiple FASTQ output files found') |
74 found_file = files[0] | 83 found_file = files[0] |
75 shutil.copy(found_file, out_file) | 84 shutil.copy(found_file, out_file) |
76 elif out_fmt == 'fast5': | 85 elif out_fmt == 'fast5': |
77 #check for single albacore output and copy to Galaxy output | 86 #check for single albacore output and copy to Galaxy output |
78 files = glob.glob("out_dir/workspace/**/*.fast5", recursive=True) | 87 files = glob.glob( os.path.join(out_path,"**","*.fast5"), recursive=True ) |
79 if len(files) < 1: | 88 if len(files) < 1: |
80 raise ValueError('No FAST5 output files found') | 89 raise ValueError('No FAST5 output files found') |
81 tar = tarfile.open(out_file, 'w:gz') | 90 tar = tarfile.open(out_file, 'w:gz') |
82 tar.add("out_dir/workspace") | 91 tar.add(out_path) |
83 tar.close() | 92 tar.close() |
84 else: | 93 else: |
85 raise ValueError('Bad output format specified') | 94 raise ValueError('Bad output format specified') |
86 | 95 |
87 | 96 |
95 # python's tarfile interface does not sanitize file paths within | 104 # python's tarfile interface does not sanitize file paths within |
96 # tarballs, which can be a big security risk. GNU tar does sanitize by | 105 # tarballs, which can be a big security risk. GNU tar does sanitize by |
97 # default, so it's easier/safer here just to call the system tar | 106 # default, so it's easier/safer here just to call the system tar |
98 subprocess.call([ | 107 subprocess.call([ |
99 "tar", | 108 "tar", |
109 "--warning=no-unknown-keyword", | |
100 "-xf", | 110 "-xf", |
101 fn, | 111 fn, |
102 "-C", | 112 "-C", |
103 in_dir]) | 113 in_dir]) |
104 | 114 |