|
5 | 5 | import subprocess
|
6 | 6 | import traceback
|
7 | 7 | import argparse
|
| 8 | +import platform |
8 | 9 | from functools import partial
|
9 | 10 | '''
|
10 | 11 |
|
|
17 | 18 | It takes 3 files as input: fastq/paf/flat, sequencing_summary, index
|
18 | 19 |
|
19 | 20 | --------------------------------------------------------------------------------------
|
20 |
| - version 0.0 - initial |
21 |
| - version 0.2 - added argparser and buffered gz streams |
22 |
| - version 0.3 - added paf input |
23 |
| - version 0.4 - added read id flat file input |
24 |
| - version 0.5 - pppp print output instead of extracting |
25 |
| - version 0.6 - did a dumb. changed x in s to set/dic entries O(n) vs O(1) |
26 |
| - version 0.7 - cleaned up a bit to share and removed some hot and steamy features |
27 |
| - version 0.8 - Added functionality for un-tarred file structures and seq_sum only |
28 |
| - version 1.0 - First release |
29 |
| - version 1.1 - refactor with dicswitch and batch_tater updates |
30 |
| -
|
| 21 | + version 0.0 - initial |
| 22 | + version 0.2 - added argparser and buffered gz streams |
| 23 | + version 0.3 - added paf input |
| 24 | + version 0.4 - added read id flat file input |
| 25 | + version 0.5 - pppp print output instead of extracting |
| 26 | + version 0.6 - did a dumb. changed x in s to set/dic entries O(n) vs O(1) |
| 27 | + version 0.7 - cleaned up a bit to share and removed some hot and steamy features |
| 28 | + version 0.8 - Added functionality for un-tarred file structures and seq_sum only |
| 29 | + version 1.0 - First release |
| 30 | + version 1.1 - refactor with dicswitch and batch_tater updates |
| 31 | + version 1.1.1 - Bug fix on --transform method, added OS detection |
31 | 32 |
|
32 | 33 | TODO:
|
33 | 34 | - Python 3 compatibility
|
@@ -82,8 +83,8 @@ def main():
|
82 | 83 | help="paf alignment file for read ids")
|
83 | 84 | group.add_argument("-f", "--flat",
|
84 | 85 | help="flat file of read ids")
|
85 |
| - # parser.add_argument("-b", "--fast5", |
86 |
| - # help="fast5.tar path to extract from - individual") |
| 86 | + parser.add_argument("--OSystem", default=platform.system(), |
| 87 | + help="running operating system - leave default unless doing odd stuff") |
87 | 88 | parser.add_argument("-s", "--seq_sum",
|
88 | 89 | help="sequencing_summary.txt.gz file")
|
89 | 90 | parser.add_argument("-i", "--index",
|
@@ -128,7 +129,7 @@ def main():
|
128 | 129 | continue
|
129 | 130 | else:
|
130 | 131 | try:
|
131 |
| - extract_file(p, f, args.output) |
| 132 | + extract_file(args, p, f) |
132 | 133 | except:
|
133 | 134 | traceback.print_exc()
|
134 | 135 | print >> sys.stderr, "Failed to extract:", p, f
|
@@ -312,17 +313,32 @@ def get_paths(index_file, filenames, f5=None):
|
312 | 313 | return paths
|
313 | 314 |
|
314 | 315 |
|
315 |
| -def extract_file(path, filename, save_path): |
| 316 | +def extract_file(args, path, filename): |
316 | 317 | '''
|
317 | 318 | Do the extraction.
|
318 | 319 | I was using the tarfile python lib, but honestly, it sucks and was too volatile.
|
319 | 320 | if you have a better suggestion, let me know :)
|
320 |
| - That --transform hack is awesome btw. Blows away all the leading folders. use it |
| 321 | + That --transform hack is awesome btw. Blows away all the leading folders. use |
321 | 322 | cp for when using untarred structures. Not recommended, but here for completeness.
|
| 323 | +
|
| 324 | + --transform not working on MacOS. Need to use gtar |
| 325 | + Thanks to Kai Martin for picking that one up! |
| 326 | +
|
322 | 327 | '''
|
| 328 | + OSystem = "" |
| 329 | + OSystem = args.OSystem |
| 330 | + save_path = args.output |
323 | 331 | if path.endswith('.tar'):
|
324 |
| - cmd = "tar -xf {} --transform='s/.*\///' -C {} {}".format( |
325 |
| - path, save_path, filename) |
| 332 | + if OSystem in ["Linux", "Windows"]: |
| 333 | + cmd = "tar -xf {} --transform='s/.*\///' -C {} {}".format( |
| 334 | + path, save_path, filename) |
| 335 | + elif OSystem == "Darwin": |
| 336 | + cmd = "gtar -xf {} --transform='s/.*\///' -C {} {}".format( |
| 337 | + path, save_path, filename) |
| 338 | + else: |
| 339 | + print >> sys.stderr, "Unsupported OSystem, trying Tar anyway, OS:", OSystem |
| 340 | + cmd = "tar -xf {} --transform='s/.*\///' -C {} {}".format( |
| 341 | + path, save_path, filename) |
326 | 342 | else:
|
327 | 343 | cmd = "cp {} {}".format(filename, os.path.join(
|
328 | 344 | save_path, filename.split('/')[-1]))
|
|
0 commit comments