crunch-dispatch preserves LD_LIBRARY_PATH environment variable.
[arvados.git] / crunch_scripts / rtg-snp
1 #!/usr/bin/env python
2
3 import arvados
4 import os
5 import re
6 import sys
7 import pyrtg
8
9 this_job = arvados.current_job()
10 this_task = arvados.current_task()
11 ref_dir = arvados.util.collection_extract(
12     collection = this_job['script_parameters']['reference'],
13     path = 'reference',
14     decompress = False)
15 input_dir = arvados.util.collection_extract(
16     collection = this_job['script_parameters']['input'],
17     path = 'input')
18 bam_files = map(lambda f: os.path.join(input_dir, f),
19                 filter(lambda f: re.search(r'^(.*/)?alignments.bam$', f),
20                        arvados.util.listdir_recursive(input_dir)))
21 out_dir = os.path.join(arvados.current_task().tmpdir, 'out')
22 arvados.util.run_command(['rm', '-rf', out_dir], stderr=sys.stderr)
23
24 # call sequence variants
25 pyrtg.run_rtg('snp', out_dir,
26               ['-t', ref_dir] + bam_files)
27
28 # store output
29 out = arvados.CollectionWriter()
30 out.write_directory_tree(out_dir, max_manifest_depth=0)
31 this_task.set_output(out.finish())