Statistics
| Branch: | Revision:

arvados / crunch_scripts / bwa-index @ master

History | View | Annotate | Download (1.17 KB)

1
#!/usr/bin/env python
2

    
3
import arvados
4
import arvados_bwa
5
import os
6
import re
7
import sys
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']['input'],
13
    path = 'reference',
14
    decompress = False)
15

    
16
ref_fasta_files = (os.path.join(ref_dir, f)
17
                   for f in os.listdir(ref_dir)
18
                   if re.search(r'\.fasta(\.gz)?$', f))
19

    
20
# build reference index
21
arvados_bwa.run('index',
22
                ['-a', 'bwtsw'] + list(ref_fasta_files))
23

    
24
# move output files to new empty directory
25
out_dir = os.path.join(arvados.current_task().tmpdir, 'out')
26
arvados.util.run_command(['rm', '-rf', out_dir], stderr=sys.stderr)
27
os.mkdir(out_dir)
28
for f in os.listdir(ref_dir):
29
    if re.search(r'\.(amb|ann|bwt|pac|rbwt|rpac|rsa|sa)$', f):
30
        sys.stderr.write("bwa output: %s (%d)\n" %
31
                         (f, os.stat(os.path.join(ref_dir, f)).st_size))
32
        os.rename(os.path.join(ref_dir, f),
33
                  os.path.join(out_dir, f))
34

    
35
# store output
36
out = arvados.CollectionWriter()
37
out.write_directory_tree(out_dir, max_manifest_depth=0)
38
this_task.set_output(out.finish())