annotate sortmerna.py @ 0:a8ac09e937f3 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
author rnateam
date Mon, 03 Aug 2015 08:18:26 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
1 #!/usr/bin/env python
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
2
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
3 """
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
4 Runs SortMeRNA
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
5 """
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
6
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
7 import subprocess
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
8 import optparse
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
9 import shlex
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
10
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
11
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
12 def main():
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
13 """Parse the command line, exectutes SortMeRNA and buildtrie if neeeded."""
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
14 #TODO: Put all SortMeRNA options in the command-line parser
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
15 parser = optparse.OptionParser()
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
16 parser.add_option('--sortmerna', dest='sortmerna_cmd', help='')
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
17 parser.add_option('--buildtrie', dest='buildtrie',
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
18 default=False, action='store_true', help='')
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
19 (options, args) = parser.parse_args()
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
20 if not args:
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
21 raise Exception('Please provide at least one database')
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
22
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
23 if options.buildtrie:
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
24 buildtrie = 'buildtrie'
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
25 for database in args:
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
26 run_buildtrie([buildtrie, '--db', database])
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
27
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
28 if options.sortmerna_cmd:
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
29 sortmerna = 'sortmerna'
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
30 run_sortmerna([sortmerna] +
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
31 shlex.split(options.sortmerna_cmd) +
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
32 ['-m', '262144', '-n', str(len(args)), '--db'] +
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
33 args)
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
34
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
35
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
36 def run_buildtrie(cmd):
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
37 """Run the BuildTrie program."""
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
38 try:
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
39 stdout_arg = subprocess.PIPE
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
40 stderr_arg = subprocess.PIPE
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
41 child_process = subprocess.Popen(args=" ".join(cmd), shell=True,
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
42 stdin=None, stdout=stdout_arg,
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
43 stderr=stderr_arg)
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
44 stdout_str, stderr_str = child_process.communicate()
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
45 return_code = child_process.returncode
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
46 if return_code is not 0:
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
47 raise Exception(stderr_str)
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
48
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
49 except Exception, error:
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
50 raise Exception('Error while running Buildtrie:\n' +
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
51 '\n'.join([str(error), stdout_str, stderr_str]))
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
52
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
53
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
54 def run_sortmerna(cmd):
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
55 """Run the SortMeRNA program."""
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
56 try:
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
57 stdout_arg = subprocess.PIPE
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
58 stderr_arg = subprocess.PIPE
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
59 child_process = subprocess.Popen(args=" ".join(cmd), shell=True,
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
60 stdin=None, stdout=stdout_arg,
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
61 stderr=stderr_arg)
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
62 stdout_str, stderr_str = child_process.communicate()
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
63 return_code = child_process.returncode
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
64 if return_code is not 0:
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
65 raise Exception(stderr_str)
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
66 except Exception, error:
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
67 raise Exception('Error while running SortMeRNA:\n' +
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
68 '\n'.join([str(error), stdout_str, stderr_str]))
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
69
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
70
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
71 if __name__ == "__main__":
a8ac09e937f3 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/rna_tools/sortmerna commit 04cfb5475292e4fd1f7c0ca86d8d0d5e5f886c3d-dirty
rnateam
parents:
diff changeset
72 main()