write template
[arvados.git] / crunch_scripts / arvados-bcbio-nextgen.py
1 #!/usr/bin/python
2
3 import arvados
4 import subprocess
5 import subst
6 import shutil
7 import os
8
9 if len(arvados.current_task()['parameters']) > 0:
10     p = arvados.current_task()['parameters']
11 else:
12     p = arvados.current_job()['script_parameters']
13
14 t = arvados.current_task().tmpdir
15
16 os.unlink("/usr/local/share/bcbio-nextgen/galaxy")
17 os.mkdir("/usr/local/share/bcbio-nextgen/galaxy")
18 shutil.copy("/usr/local/share/bcbio-nextgen/config/bcbio_system.yaml", "/usr/local/share/bcbio-nextgen/galaxy")
19
20 os.mkdir("/usr/local/share/bcbio-nextgen/galaxy/tool-data")
21
22 with open("/usr/local/share/bcbio-nextgen/galaxy/tool-data/tool_data_table_conf.xml", "w") as f:
23     f.write('''<tables>
24     <!-- Locations of indexes in the BWA mapper format -->
25     <table name="bwa_indexes" comment_char="#">
26         <columns>value, dbkey, name, path</columns>
27         <file path="tool-data/bwa_index.loc" />
28     </table>
29     <!-- Locations of indexes in the Bowtie2 mapper format -->
30     <table name="bowtie2_indexes" comment_char="#">
31         <columns>value, dbkey, name, path</columns>
32         <file path="tool-data/bowtie2_indices.loc" />
33     </table>
34     <!-- Locations of indexes in the Bowtie2 mapper format for TopHat2 to use -->
35     <table name="tophat2_indexes" comment_char="#">
36         <columns>value, dbkey, name, path</columns>
37         <file path="tool-data/bowtie2_indices.loc" />
38     </table>
39     <!-- Location of SAMTools indexes and other files -->
40     <table name="sam_fa_indexes" comment_char="#">
41         <columns>index, value, path</columns>
42         <file path="tool-data/sam_fa_indices.loc" />
43     </table>
44     <!-- Location of Picard dict file and other files -->
45     <table name="picard_indexes" comment_char="#">
46         <columns>value, dbkey, name, path</columns>
47         <file path="tool-data/picard_index.loc" />
48     </table>
49     <!-- Location of Picard dict files valid for GATK -->
50     <table name="gatk_picard_indexes" comment_char="#">
51         <columns>value, dbkey, name, path</columns>
52         <file path="tool-data/gatk_sorted_picard_index.loc" />
53     </table>
54 </tables>
55 ''')
56
57 os.mkdir("/usr/local/share/bcbio-nextgen/galaxy/templates")
58
59 with open("/usr/local/share/bcbio-nextgen/galaxy/templates/gatk-variant.yaml", "w") as f:
60     f.write('''
61 # Template for whole genome Illumina variant calling with GATK pipeline
62 ---
63 details:
64   - analysis: variant2
65     genome_build: GRCh37
66     # to do multi-sample variant calling, assign samples the same metadata / batch
67     # metadata:
68     #   batch: your-arbitrary-batch-name
69     algorithm:
70       aligner: bwa
71       mark_duplicates: picard
72       recalibrate: gatk
73       realign: gatk
74       variantcaller: gatk-haplotype
75       platform: illumina
76       quality_format: Standard
77       coverage_interval: genome
78       # for targetted projects, set the region
79       # variant_regions: /path/to/your.bed
80 ''')
81
82 with open("/usr/local/share/bcbio-nextgen/galaxy/tool-data/bowtie2_indices.loc", "w") as f:
83     f.write(subst.do_substitution(p, "GRCh37\tGRCh37\tHuman (GRCh37)\t$(dir $(bowtie2_indices))"))
84
85 with open("/usr/local/share/bcbio-nextgen/galaxy/tool-data/bwa_indices.loc", "w") as f:
86     f.write(subst.do_substitution(p, "GRCh37\tGRCh37\tHuman (GRCh37)\t$(file $(bwa_indices))"))
87
88 with open("/usr/local/share/bcbio-nextgen/galaxy/tool-data/gatk_sorted_picard_index.loc", "w") as f:
89     f.write(subst.do_substitution(p, "GRCh37\tGRCh37\tHuman (GRCh37)\t$(file $(gatk_sorted_picard_index))"))
90
91 with open("/usr/local/share/bcbio-nextgen/galaxy/tool-data/picard_index.loc", "w") as f:
92     f.write(subst.do_substitution(p, "GRCh37\tGRCh37\tHuman (GRCh37)\t$(file $(picard_index))"))
93
94 with open("/usr/local/share/bcbio-nextgen/galaxy/tool-data/sam_fa_indices.loc", "w") as f:
95     f.write(subst.do_substitution(p, "index\tGRCh37\t$(file $(sam_fa_indices))"))
96
97 os.chdir(arvados.current_task().tmpdir)
98
99 rcode = subprocess.call(["bcbio_nextgen.py", "--workflow", "template", "gatk-variant", "project1",
100                          subst.do_substitution(p, "$(R1)"),
101                          subst.do_substitution(p, "$(R2)")])
102
103 os.chdir("project1/work")
104
105 rcode = subprocess.call(["bcbio_nextgen.py", "../config/project1.yaml"])