Mercurial > repos > dfornika > snippy
annotate snippy_core_wrapper.py @ 20:3bbfe41787af draft
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
author | dfornika |
---|---|
date | Fri, 08 Mar 2019 20:46:56 -0500 |
parents | |
children |
rev | line source |
---|---|
20
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
1 #!/usr/bin/env python |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
2 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
3 # -------------------------------------- |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
4 # |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
5 # snippy_core_wrapper.py |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
6 # |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
7 # This is an intermediary script between snippy-core.xml and snippy-core |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
8 # It: |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
9 # - Copys the supplied zipped snippy output files to the working dir |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
10 # - Untars them to their datafile name |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
11 # - Builds the snippy-core command |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
12 # - Runs the snippy-core command |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
13 # |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
14 # -------------------------------------- |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
15 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
16 import argparse |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
17 import os |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
18 import subprocess |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
19 from shutil import copyfile |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
20 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
21 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
22 def main(): |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
23 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
24 parser = argparse.ArgumentParser() |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
25 parser.add_argument('-r', '--ref', help='Reference fasta', required=True) |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
26 parser.add_argument('-i', '--indirs', help='Comma-separated list of input datasets') |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
27 args = parser.parse_args() |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
28 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
29 snippy_core_command_line = ['snippy-core', '--ref', args.ref] |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
30 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
31 for input_dataset in args.indirs.split(','): |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
32 base_name = os.path.basename(input_dataset) |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
33 copyfile(input_dataset, base_name) |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
34 subprocess.Popen(['tar', '-xf', base_name]).wait() |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
35 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
36 extracted_dirs = [f for f in os.listdir('.') if os.path.isdir(f) ] |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
37 for extracted_dir in extracted_dirs: |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
38 snippy_core_command_line.append(extracted_dir) |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
39 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
40 subprocess.Popen(snippy_core_command_line).wait() |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
41 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
42 |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
43 if __name__ == '__main__': |
3bbfe41787af
planemo upload commit bf653fc1bf39312caf070843fbde7b2570330917-dirty
dfornika
parents:
diff
changeset
|
44 main() |