comparison seal-galaxy-cc1b1911/seal/merge_alignments.py @ 0:244073d9abc1 draft default tip

Uploaded
author crs4
date Wed, 15 Oct 2014 09:41:10 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:244073d9abc1
1 #!/usr/bin/env python
2
3 # Copyright (C) 2011-2014 CRS4.
4 #
5 # This file is part of Seal.
6 #
7 # Seal is free software: you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the Free
9 # Software Foundation, either version 3 of the License, or (at your option)
10 # any later version.
11 #
12 # Seal is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Seal. If not, see <http://www.gnu.org/licenses/>.
19
20
21
22 import os
23 import subprocess
24 import sys
25 import tempfile
26
27 import hadoop_galaxy.pathset as pathset
28 import hadoop_galaxy.cat_paths as cat_paths
29
30 def usage_error(msg=None):
31 if msg:
32 print >> sys.stderr, msg
33 print >> sys.stderr, os.path.basename(__file__), "INPUT_PATHSET OUTPUT [args...]"
34 sys.exit(1)
35
36 def main(args):
37 if len(args) < 2:
38 usage_error()
39
40 # We generate the header with seal_merge_alignments, insert it at the
41 # top of a copy of the input pathset, and then use cat_parts to
42 # join everything into a single file.
43
44 input_pathset, output_path = map(os.path.abspath, args[0:2])
45
46 with tempfile.NamedTemporaryFile() as header_file:
47 print "generating header"
48 gen_header_cmd = [ 'seal', 'merge_alignments', '--header-only' ]
49 gen_header_cmd.extend(args[2:])
50 header_text = subprocess.check_output(gen_header_cmd)
51
52 header_file.write(header_text)
53 header_file.flush()
54 print "header ready"
55 print "generating new pathset"
56
57 original_pathset = pathset.FilePathset.from_file(input_pathset)
58 new_pathset = pathset.FilePathset()
59 new_pathset.append(header_file.name)
60 for p in original_pathset:
61 new_pathset.append(p)
62
63 with tempfile.NamedTemporaryFile() as temp_pathset:
64 new_pathset.write(temp_pathset)
65 temp_pathset.flush()
66
67 print "concatenating pathset"
68 # TODO: Add ability to use dist_cat_paths
69 cat_paths.main([temp_pathset.name, output_path])
70 print "operation complete"
71
72 if __name__ == '__main__':
73 main(sys.argv[1:])