2 # Copyright (C) The Arvados Authors. All rights reserved.
4 # SPDX-License-Identifier: Apache-2.0
10 arvados.job_setup.one_task_per_input_file(if_sequence=0, and_end_task=True)
12 this_job = arvados.current_job()
13 this_task = arvados.current_task()
14 gatk_path = arvados.util.tarball_extract(
15 tarball = this_job['script_parameters']['gatk_binary_tarball'],
17 bundle_path = arvados.util.collection_extract(
18 collection = this_job['script_parameters']['gatk_bundle'],
20 files = ['human_g1k_v37.dict', 'human_g1k_v37.fasta', 'human_g1k_v37.fasta.fai'])
21 this_task_input = this_task['parameters']['input']
23 input_file = list(arvados.CollectionReader(this_task_input).all_files())[0]
25 # choose vcf temporary file names
26 vcf_in = os.path.join(arvados.current_task().tmpdir,
27 os.path.basename(input_file.name()))
28 vcf_out = re.sub('(.*)\\.vcf', '\\1-filtered.vcf', vcf_in)
30 # fetch the unfiltered data
31 vcf_in_file = open(vcf_in, 'w')
32 for buf in input_file.readall():
33 vcf_in_file.write(buf)
36 stdoutdata, stderrdata = arvados.util.run_command(
38 '-jar', os.path.join(gatk_path,'GenomeAnalysisTK.jar'),
39 '-T', 'VariantFiltration', '--variant', vcf_in,
41 '--filterExpression', 'QD < 2.0',
42 '--filterName', 'GATK_QD',
43 '--filterExpression', 'MQ < 40.0',
44 '--filterName', 'GATK_MQ',
45 '--filterExpression', 'FS > 60.0',
46 '--filterName', 'GATK_FS',
47 '--filterExpression', 'MQRankSum < -12.5',
48 '--filterName', 'GATK_MQRankSum',
49 '--filterExpression', 'ReadPosRankSum < -8.0',
50 '--filterName', 'GATK_ReadPosRankSum',
51 '-R', os.path.join(bundle_path, 'human_g1k_v37.fasta')],
52 cwd=arvados.current_task().tmpdir)
54 # store the filtered data
55 with open(vcf_out, 'rb') as f:
56 out = arvados.CollectionWriter()
62 out.set_current_file_name(os.path.basename(vcf_out))
64 this_task.set_output(out.finish())