script/germline.pl untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 88 CC 11 SCAR 45.8
CC
11
Cov
0%
germline_stages
132.0
BEGIN
2.0
BEGIN
2.0
CRAP 97.3
1 use strict;
2 use warnings;
3 use HPCI;
4 use File::Path qw(make_path);
5  
6 our ($wd, $chr, $diploid, $reference, $gpercent, $phasing) = @ARGV;
7 our $group = HPCI->group(cluster => 'SGE', name => "GermlineSim-$chr", base_dir => $wd);
8  
9 germline_stages(
10 chr => $chr,
11 diploid => $diploid
12 );
13  
14 $group->execute();
15  
16  
17 sub germline_stages {
18 my %args = (
19 chr => "",
20 diploid => 1,
21 @_
22 );
23  
24 # input_bam = $self->bam
25 # ref = $self->config->{reference}
26 # randompick_dir = $self->wd . "/germ_mutations"
27 # percent = $self->gpercent
28  
29 # $self->HPCI_group->stage(
30 # name => "",
31 # command => "",
32 # resources_required => {
33 # h_vmem => "60G"
34 # },
35 # modules_to_load => $self->modules
36 # );
37  
38 my @phase_list = ("phase.0");
39  
40 my %phase_dir = (
41 "phase.0" => $wd . "/chr" . $args{chr} . "/phase.0",
42 "phase.1" => $wd . "/chr" . $args{chr} . "/phase.1"
43 );
44 my %phase_dir_with_stem = (
45 "phase.0" => $wd . "/chr" . $args{chr} . "/phase.0/phase.0",
46 "phase.1" => $wd . "/chr" . $args{chr} . "/phase.1/phase.1"
47 );
48  
49 my $phasing_command = "samtools sort -m 5G -@ 4 " . $wd . "/chr" . $args{chr} . ".bam " . $phase_dir{"phase.0"};
50 if ($args{diploid}) {
51 push(@phase_list, "phase.1");
52 if ($phasing) {
53 $phasing_command =
54 "samtools sort -m 5G -@ 4 " . $wd . "/chr" . $args{chr} . ".bam " . $wd . "/chr" . $args{chr} . ";\n" .
55 "samtools phase -b phase " . $wd . "/chr" . $args{chr} . ".bam";
56 }
57 }
58  
59  
60 foreach my $phase (@phase_list) {
61 if (! -e $phase_dir{$phase}) {
62 make_path($phase_dir{$phase});
63 }
64 my $phasing_stage;
65 if ($phasing) {
66 $phasing_stage = $group->stage(
67 name => "phasing_" . $args{chr} . $phase,
68 command => $phasing_command,
69 resources_required => {
70 h_vmem => "12G"
71 },
72 modules_to_load => [ 'samtools/1.2' ]
73 );
74 }
75  
76 my $pre_stage;
77 if (! -e $phase_dir_with_stem{$phase} . ".postprocessed.bam") {
78 $pre_stage = $group->stage(
79 name => "germ_hap_pre_" . $args{chr} . $phase,
80 command =>
81 "cd " . $phase_dir{$phase} . "; " .
82 "postprocess.py -f " . $reference . ".fai -t 4 -m 10G " . $phase_dir{$phase} . ".bam;\n" .
83 "mv " . $phase_dir{$phase} . ".postprocessed.bam " . $phase_dir_with_stem{$phase} . ".postprocessed.bam;\n" .
84 "samtools sort -m 5G -@ 4 " . $phase_dir_with_stem{$phase} . ".postprocessed.bam " . $phase_dir_with_stem{$phase} . ".postprocessed.sorted;\n" .
85 "mv " . $phase_dir_with_stem{$phase} . ".postprocessed.sorted.bam " . $phase_dir_with_stem{$phase} . ".postprocessed.bam;\n" .
86 "samtools index " . $phase_dir_with_stem{$phase} . ".postprocessed.bam;\n",
87 resources_required => {
88 h_vmem => "32G"
89 },
90 modules_to_load => [ 'samtools/1.2', 'Python-BL', 'bamsurgeon/0.1.0-local' ]
91 );
92
93 if (defined($phasing_stage)) {
94 $group->add_deps(
95 pre_req => $phasing_stage,
96 deps => $pre_stage
97 ) if $phasing_stage;
98 }
99 }
100  
101 my $snv_stage = $group->stage(
102 name => "snvhet_" . $args{chr} . $phase,
103 command =>
104 "cd " . $phase_dir{$phase} . "; " .
105 "addsnv.py -r " . $reference . " -v " . $wd . "/germ_mutations/pick_" . $args{chr} . "_snv_het.txt -f " . $phase_dir_with_stem{$phase} . ".postprocessed.bam -o snvhet_ph0 --mindepth 10 --ignoresnps --skipmerge",
106 resources_required => {
107 h_vmem => "8G"
108 },
109 modules_to_load => [ "Python-BL", 'bamsurgeon/0.1.0-local' ]
110 );
111  
112 $group->add_deps(
113 pre_req => $pre_stage,
114 deps => $snv_stage
115 ) if $pre_stage;
116  
117 my $indel_stage = $group->stage(
118 name => "indelhet_" . $args{chr} . $phase,
119 command =>
120 "cd " . $phase_dir{$phase} . "; " .
121 "addindel.py -r " . $reference . " -v " . $wd . "/germ_mutations/pick_" . $args{chr} . "_indel_het.txt -f " . $phase_dir_with_stem{$phase} . '.postprocessed.bam -o indelhet_ph0 --mindepth 10 -p 4 --skipmerge --picardjar $PICARDROOT/picard.jar --aligner mem',
122 resources_required => {
123 h_vmem => "8G"
124 },
125 modules_to_load => [ "Python-BL", "picard/1.130", 'bamsurgeon/0.1.0-local' ]
126 );
127  
128 $group->add_deps(
129 pre_req => $snv_stage,
130 deps => $indel_stage
131 );
132  
133 my $merge_sort_muts_stage = $group->stage(
134 name => "merge_sort_muts_" . $args{chr} . $phase,
135 command =>
136 "cd " . $phase_dir{$phase} . "; " .
137 "samtools merge -f " . $phase_dir_with_stem{$phase} . ".muts.bam *.muts.bam;\n" .
138 "samtools sort -m 500M -@ 4 " . $phase_dir_with_stem{$phase} . ".muts.bam " . $phase_dir_with_stem{$phase} . ".muts.sorted; mv " . $phase_dir_with_stem{$phase} . ".muts.sorted.bam " . $phase_dir_with_stem{$phase} . ".muts.bam",
139 resources_required => {
140 h_vmem => "4G"
141 },
142 modules_to_load => ["samtools/1.2"]
143 );
144  
145 $group->add_deps(
146 pre_req => $indel_stage,
147 deps => $merge_sort_muts_stage
148 ) if $indel_stage;
149  
150 my $replace_read_stage = $group->stage(
151 name => "replace_reads_" . $args{chr} . $phase,
152 command =>
153 "cd " . $phase_dir{$phase} . "; " .
154 "replacereads.py -b " . $phase_dir_with_stem{$phase} . ".postprocessed.bam -r " . $phase_dir_with_stem{$phase} . ".muts.bam -o " . $phase_dir_with_stem{$phase} . ".postprocessed.muts.bam --all --progress",
155 resources_required => {
156 h_vmem => "12G"
157 },
158 retry_resources_required => {
159 h_vmem => ['16G', '20G', '24G']
160 },
161 modules_to_load => [ "Python-BL", 'bamsurgeon/0.1.0-local', 'samtools/1.2' ]
162 );
163  
164 $group->add_deps(
165 pre_req => $merge_sort_muts_stage,
166 deps => $replace_read_stage
167 ) if $merge_sort_muts_stage;
168  
169 my $postprocess_stage = $group->stage(
170 name => "post_" . $args{chr} . $phase,
171 command =>
172 "cd " . $phase_dir{$phase} . "; " .
173 "postprocess.py -f " . $reference . ".fai -t 4 -m 10G " . $phase_dir_with_stem{$phase} . ".postprocessed.muts.bam;",
174 resources_required => {
175 h_vmem => "32G"
176 },
177 modules_to_load => [ "Python-BL", 'bamsurgeon/0.1.0-local', 'samtools/1.2' ]
178 );
179  
180 $group->add_deps(
181 pre_req => $replace_read_stage,
182 deps => $postprocess_stage
183 );
184  
185 my $sort_post_stage = $group->stage(
186 name => "sort_post_" . $args{chr} . $phase,
187 command =>
188 "cd " . $phase_dir{$phase} . "; " .
189 "samtools sort -m 500M -@ 4 " . $phase_dir_with_stem{$phase} . ".postprocessed.muts.bam " . $phase_dir_with_stem{$phase} . ".postprocessed.muts.sorted; mv " . $phase_dir_with_stem{$phase} . ".postprocessed.muts.sorted.bam " . $phase_dir_with_stem{$phase} . ".postprocessed.muts.bam",
190 resources_required => {
191 h_vmem => "4G"
192 },
193 modules_to_load => ["samtools/1.2"]
194 );
195  
196 $group->add_deps(
197 pre_req => $postprocess_stage,
198 deps => $sort_post_stage
199 );
200  
201 my $nongpercent = 1 - $gpercent;
202 my $bamsplit_stage = $group->stage(
203 name => "bamsplit_ph0_" . $args{chr} . $phase,
204 command =>
205 "cd " . $phase_dir{$phase} . "; " .
206 "bamsplit_multiple.py " . $phase_dir_with_stem{$phase} . ".postprocessed.muts.postprocessed.bam " . $phase_dir{$phase} . " $phase.N.bam,$phase.T.bam " . " $nongpercent,$gpercent ",
207 resources_required => {
208 h_vmem => "4G"
209 },
210 modules_to_load => [ "Python-BL", 'bamsurgeon/0.1.0-local' ]
211 );
212  
213 $group->add_deps(
214 pre_req => $sort_post_stage,
215 deps => $bamsplit_stage
216 );
217 }
218  
219 return 0;
220 }