-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDRIVER.pm
186 lines (155 loc) · 6.29 KB
/
DRIVER.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#------------------------------------------------------------------------------
# CancerRNASeq - a pipeline for transcriptomics datasets
# Author: Raphael Hablesreiter
#
# DRIVER.pm
#
# Description: Driver Module
# This module checks, if the pipeline has to start at the begining
# or if the pipeline has to start at a certain module.
# There are 8 different options available:
# (1. Preprocessing)
# 1.1. Cutadapt
# 1.2. Trimmomatic
# 1.3. rCorrector
# 2. Mapping
# (3. Analyzing)
# 3.1. Cufflinks
# 3.2. Cuffmerge
# 3.3. Cuffdiff
# 3.4. CummeRbund
#
#-------------------------------------------------------------------------------
#
package DRIVER;
use 5.010;
use strict;
use warnings;
use Config::Simple;
use PIPELINETOOLS;
use PREPROCESSING;
use MAPPING;
use ANALYZING;
#-------------------------------------------------------------------------------
# Main: Checks the progress of the Pipeline and after that
# starts all the different modules.
#-------------------------------------------------------------------------------
sub Main{
my $end_condition = 0;
my $succ = DRIVER::CheckSuccess();
if ($::global_cfg -> param("optional.end") &&
$::global_cfg -> param("optional.end") eq $succ)
{
$end_condition = 1;
}
elsif ($succ eq "Cummerbund")
{
$end_condition = 1;
}
#Pipeline Run
while ($end_condition == 0)
{
given ($succ)
{
when ("Start") {PREPROCESSING::Main(1); $succ = "Cutadapt";}
when ("Cutadapt") {PREPROCESSING::Main(2); $succ = "Trimmomatic";}
when ("Trimmomatic") {PREPROCESSING::Main(3); $succ = "rCorrector";}
when ("rCorrector") {MAPPING::Main(1); $succ = "Mapping";}
when ("Mapping") {MAPPING::Main(2); $succ = "QualiMap";}
when ("QualiMap") {ANALYZING::Main(1); $succ = "Cufflinks";}
when ("Cufflinks") {ANALYZING::Main(2); $succ = "Cuffmerge";}
when ("Cuffmerge") {ANALYZING::Main(3); $succ = "Cuffdiff";}
when ("Cuffdiff") {ANALYZING::Main(4); $succ = "CummeRbund";}
when ("CummeRbund") {}
when ("ERROR") {die "ERROR: Can't read success files!\n";}
default {die "ERROR: In SUCCES Routine!\n";}
}
# $::global_cfg -> param("optional.end") can also have
# the same values as the return values of CheckSuccess are
# if value of $::global_cfg -> param("optional.end") and
# pipeline progress is equal the pipeline stops
if ($::global_cfg -> param("optional.end") &&
$::global_cfg -> param("optional.end") eq $succ)
{
$end_condition = 1;
}
elsif ($succ eq "Cummerbund")
{
$end_condition = 1;
}
}
PIPELINETOOLS::PrintStd("Pipeline Finished");
PIPELINETOOLS::WriteLogOut("Pipeline Finished");
return;
}
#-------------------------------------------------------------------------------
# CheckSuccess: Checks the progress of the Pipeline and returns last finished
# pipeline module.
# return values: "Start" -> starts with Cutadapt
# "Cutadapt" -> starts with Trimmomatic
# "Trimmomatic" -> starts with rCorrector
# "rCorrector" -> starts with Mapping
# "Mapping" -> starts with Cufflinks
# "Cufflinks" -> starts with Cuffmerge
# "Cuffmerge" -> starts with Cuffdiff
# "Cuffdiff" -> starts with CummeRbund
#
#-------------------------------------------------------------------------------
sub CheckSuccess{
my $succ_dir = $::global_cfg -> param("results.tmp");
my @succ_files = PIPELINETOOLS::ReadDirectory($succ_dir,".succ");
if (@succ_files)
{
@succ_files = sort(@succ_files);
my $last_succ_name = pop(@succ_files);
my $last_succ = new Config::Simple($succ_dir."/".$last_succ_name);
if ($last_succ)
{
my $last_cmd = $last_succ -> param("success.cmd");
if ($last_cmd eq "Cutadapt" or
$last_cmd eq "Trimmomatic" or
$last_cmd eq "rCorrector")
{
@::sequences_1 = ();
@::sequences_2 = ();
my @tmp_files = PIPELINETOOLS::ReadDirectory(
$succ_dir,".fastq.gz");
my $namead;
given($last_cmd)
{
when("Cutadapt"){$namead = "_CA.fastq.gz";}
when("Trimmomatic"){$namead = "_CA_Trim_P.fastq.gz";}
when("rCorrector"){$namead = "_CA_Trim_P.cor.fq.gz";}
default{die "ERROR! In reading successfiles!\n";}
}
my @sequences = PIPELINETOOLS::ReadDirectory($succ_dir,$namead);
while (@sequences)
{
my $tmp_seq = shift(@sequences);
if ($tmp_seq =~ $::global_cfg -> param("required.sequence_1"))
{
push(@::sequences_1, $succ_dir."/".$tmp_seq);
}
elsif ($tmp_seq =~ $::global_cfg -> param("required.sequence_2"))
{
push(@::sequences_2, $succ_dir."/".$tmp_seq);
}
}
@::sequences_1 = sort(@::sequences_1);
@::sequences_2 = sort(@::sequences_2);
$::global_cfg -> param("required.seqlength1", scalar(@::sequences_1));
$::global_cfg -> param("required.seqlength2", scalar(@::sequences_2));
}
return $last_cmd;
}
else
{
die "ERROR: Wrong success-file in the tmp-folder!\n";
}
}
else
{
return "Start";
}
}
1;