Mercurial > repos > dfornika > snippy
annotate snippy_core_wrapper.py @ 7:ab3026667cdc draft
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
author | dfornika |
---|---|
date | Mon, 21 Jan 2019 18:17:52 -0500 |
parents | b9eacd069df6 |
children | c441153cb4c2 |
rev | line source |
---|---|
4
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
1 #!/usr/bin/env python |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
2 |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
3 #-------------------------------------- |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
4 # |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
5 # snippy_core_wrapper.py |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
6 # |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
7 # This is an intermediary script between snippy-core.xml and snippy-core |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
8 # It: |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
9 # - Copys the supplied zipped snippy output files to the working dir |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
10 # - Untars them to their datafile name |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
11 # - Builds the snippy-core command |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
12 # - Runs the snippy-core command |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
13 # |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
14 #-------------------------------------- |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
15 |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
16 import os |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
17 import sys |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
18 import argparse |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
19 import subprocess |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
20 from shutil import copyfile |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
21 |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
22 def main(): |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
23 parser = argparse.ArgumentParser() |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
24 parser.add_argument('-r', '--ref', help='Reference fasta', required=True) |
5
b9eacd069df6
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
4
diff
changeset
|
25 parser.add_argument('-i', '--indirs', nargs='+') |
4
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
26 args = parser.parse_args() |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
27 |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
28 snippy_core_command_line = ['snippy-core', '--ref', args.ref] |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
29 |
7
ab3026667cdc
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
5
diff
changeset
|
30 for indir in args.indirs.split(): |
5
b9eacd069df6
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
4
diff
changeset
|
31 base_name = os.path.basename(indir) |
b9eacd069df6
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
4
diff
changeset
|
32 sys.stderr.write(indir + '\n') |
b9eacd069df6
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
4
diff
changeset
|
33 copyfile(indir, base_name) |
b9eacd069df6
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
4
diff
changeset
|
34 sys.stderr.write('\n'.join([indir, base_name]) + '\n') |
b9eacd069df6
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
4
diff
changeset
|
35 subprocess.run(['tar', '-xf', base_name]) |
4
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
36 |
5
b9eacd069df6
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
4
diff
changeset
|
37 extracted_dirs = [f.path for f in os.scandir() if f.is_dir() ] |
4
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
38 |
5
b9eacd069df6
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
4
diff
changeset
|
39 for extracted_dir in extracted_dirs: |
b9eacd069df6
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
4
diff
changeset
|
40 snippy_core_command_line.append(extracted_dir) |
4
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
41 |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
42 print(snippy_core_command_line) |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
43 subprocess.run(snippy_core_command_line) |
5
b9eacd069df6
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
4
diff
changeset
|
44 |
4
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
45 if __name__ == '__main__': |
3f5ced130c5c
planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff
changeset
|
46 main() |