10 def samtools_install_path():
12 Extract the samtools source tree, build the samtools binary, and
13 return the path to the source tree.
18 samtools_path = arvados.util.tarball_extract(
19 tarball = arvados.current_job()['script_parameters']['samtools_tgz'],
22 # build "samtools" binary
23 lockfile = open(os.path.split(samtools_path)[0] + '.samtools-make.lock',
25 fcntl.flock(lockfile, fcntl.LOCK_EX)
26 arvados.util.run_command(['make', '-j16'], cwd=samtools_path)
31 def samtools_binary():
33 Return the path to the samtools executable.
35 return os.path.join(samtools_install_path(), 'samtools')
37 def run(command, command_args, **kwargs):
39 Build and run the samtools binary.
41 command is the samtools subcommand, e.g., "view" or "sort".
43 command_args is a list of additional command line arguments, e.g.,
44 ['-bt', 'ref_list.txt', '-o', 'aln.bam', 'aln.sam.gz']
46 It is assumed that we are running in a Crunch job environment, and
47 the job's "samtools_tgz" parameter is a collection containing the
48 samtools source tree in a .tgz file.
50 execargs = [samtools_binary(),
52 execargs += command_args
53 sys.stderr.write("%s.run: exec %s\n" % (__name__, str(execargs)))
54 arvados.util.run_command(
56 cwd=arvados.current_task().tmpdir,
57 stdin=kwargs.get('stdin', subprocess.PIPE),
58 stderr=kwargs.get('stderr', sys.stderr),
59 stdout=kwargs.get('stdout', sys.stderr))
61 def one_task_per_bam_file(if_sequence=0, and_end_task=True):
63 Queue one task for each bam file in this job's input collection.
65 Each new task will have an "input" parameter: a manifest
66 containing one .bam file and (if available) the corresponding .bai
69 Files in the input collection that are not named *.bam or *.bai
70 (as well as *.bai files that do not match any .bam file present)
73 if_sequence and and_end_task arguments have the same significance
74 as in arvados.job_setup.one_task_per_input_file().
76 if if_sequence != arvados.current_task()['sequence']:
78 job_input = arvados.current_job()['script_parameters']['input']
79 cr = arvados.CollectionReader(job_input)
82 for s in cr.all_streams():
83 for f in s.all_files():
84 if re.search(r'\.bam$', f.name()):
85 bam[s.name(), f.name()] = f
86 elif re.search(r'\.bai$', f.name()):
87 bai[s.name(), f.name()] = f
88 for ((s_name, f_name), bam_f) in bam.items():
89 bai_f = bai.get((s_name, re.sub(r'bam$', 'bai', f_name)), None)
90 task_input = bam_f.as_manifest()
92 task_input += bai_f.as_manifest()
94 'job_uuid': arvados.current_job()['uuid'],
95 'created_by_job_task_uuid': arvados.current_task()['uuid'],
96 'sequence': if_sequence + 1,
101 arvados.api().job_tasks().create(body=new_task_attrs).execute()
103 arvados.api().job_tasks().update(uuid=arvados.current_task()['uuid'],
104 body={'success':True}