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'],
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))
20 # build reference index
21 arvados_bwa.run('index',
22 ['-a', 'bwtsw'] + list(ref_fasta_files))
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)
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))
36 out = arvados.CollectionWriter()
37 out.write_directory_tree(out_dir, max_manifest_depth=0)
38 this_task.set_output(out.finish())