annotate snippy_core_wrapper.py @ 4:3f5ced130c5c draft

planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
author dfornika
date Mon, 21 Jan 2019 15:18:21 -0500
parents
children b9eacd069df6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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)
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
25 parser.add_argument('inputs', nargs='+')
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
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
30 for input in args.inputs:
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
31 bn = os.path.basename(input)
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
32 sys.stderr.write(input + '\n')
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
33 copyfile(input, bn)
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
34 sys.stderr.write('\n'.join([input, bn]) + '\n')
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
35 subprocess.run(['tar', '-xf', bn])
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
36
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
37 test_list = [f.path for f in os.scandir() if f.is_dir() ]
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
38
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
39 for dir in test_list:
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
40 snippy_core_command_line.append(dir)
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)
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
44 if __name__ == '__main__':
3f5ced130c5c planemo upload for repository https://github.com/tseemann/snippy commit 73ec6ea773b1b88f7c32a2e8bc57b644b82f7ff9-dirty
dfornika
parents:
diff changeset
45 main()