forked from Molmed/sisyphus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aeacus-reports.pl
executable file
·287 lines (235 loc) · 8.82 KB
/
aeacus-reports.pl
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/usr/bin/perl -w
use FindBin; # Find the script location
use lib "$FindBin::Bin/lib";# Add the script libdir to libs
use Molmed::Sisyphus::Libpath;
use strict;
use Getopt::Long;
use Pod::Usage;
use Cwd qw(abs_path cwd);
use File::Basename;
use Molmed::Sisyphus::Uppmax::SlurmJob;
use Molmed::Sisyphus::Common;
=pod
=head1 NAME
aeacus.pl - Post process a runfolder at UPPMAX
=head1 SYNOPSIS
aeacus.pl -help|-man
aeacus.pl -runfolder <runfolder> [-debug]
=head1 OPTIONS
=over 4
=item -h|-help
prints out a brief help text.
=item -m|-man
Opens the manpage.
=item -runfolder
The runfolder to process.
=item -debug
Print debugging information
=back
The rest of the configuration is read from RUNFOLDER/sisyphus.yml. See example included in the sisyphus directory.
=head1 DESCRIPTION
aeacus.pl submits postprocessing batchjobs to the cluster at UPPMAX. Which jobs to submit is
determined from the sisyphus.yml configuration file.
aeacus.pl is normally started remotely as the last step performed by sisyphus.pl
The postprocessing includes the following steps:
=over 4
=item Extraction of projects for data delivery
=item Generation of global report
=item Archiving
=back
=cut
my $rfPath = undef;
our $debug = 0;
my ($help,$man) = (0,0);
umask(007);
GetOptions('help|?'=>\$help,
'man'=>\$man,
'runfolder=s' => \$rfPath,
'debug' => \$debug,
) or pod2usage(-verbose => 0);
pod2usage(-verbose => 1) if ($help);
pod2usage(-verbose => 2) if ($man);
unless(defined $rfPath && -e $rfPath){
print STDERR "Runfolder not specified or does not exist\n";
pod2usage(-verbose => 1);
exit;
}
# Pass debug to scripts with this flag
my $debugFlag='';
if($debug){
$debugFlag = '-debug';
}
my $sisyphus = Molmed::Sisyphus::Common->new(PATH=>$rfPath, DEBUG=>$debug);
$rfPath = $sisyphus->PATH;
my $rfName = basename($rfPath);
my $rfRoot = dirname($rfPath);
my $sampleSheet = $sisyphus->readSampleSheet();
my $excludedTiles = $sisyphus->excludedTiles();
# Set short name for use in jobnames
my $rfShort = join('-', @{[split(/_/, $rfName)]}[0,3]);
# Set some defaults
my $uProj = 'a2009002';
my $uQos = undef;
my $aPath = "/proj/$uProj";
my $iPath = "/ssUppnexZone/proj/$uProj";
my $oPath = "$rfPath/Projects";
my $tmpdir = "/proj/a2009002/private/nobackup/tmp/$$";
my $scriptDir = "$rfPath/slurmscripts";
my $skipLanes = [];
my $email = undef;
# Read the sisyphus configuration and override the defaults
my $config = $sisyphus->readConfig();
if(defined $config->{UPPNEX_PROJECT}){
$uProj = $config->{UPPNEX_PROJECT};
}
if(defined $config->{UPPNEX_QOS}){
$uQos = $config->{UPPNEX_QOS};
}
if(defined $config->{OUTBOX_PATH} && $config->{OUTBOX_PATH} !~ /\s*default\s*/i){
$oPath = $config->{OUTBOX_PATH};
}
if(defined $config->{ARCHIVE_PATH}){
$aPath = $config->{ARCHIVE_PATH};
}
if(defined $config->{SWESTORE_PATH}){
$iPath = $config->{SWESTORE_PATH};
}
if(defined $config->{TMPDIR}){
$tmpdir = $config->{TMPDIR};
}
if(defined $config->{SKIP_LANES}){
$skipLanes = $config->{SKIP_LANES};
}
if(defined $config->{MAIL}){
$email = $config->{MAIL};
}
# Strip trailing slashes from paths
$oPath =~ s:/*$::;
$aPath =~ s:/*$::;
# Fastq statistics
# One per lane
my %ffJobs;
my $numLanes = $sisyphus->laneCount();
open(my $jidFh, '<', "$rfPath/slurmscripts/ffJobs") or die $!;
while(<$jidFh>){
chomp;
my($l,$j) = split /\t/, $_;
$ffJobs{$l} = $j;
}
# Extract data to OUTBOX
# One per project
my %projJobs;
foreach my $proj (keys %{$sampleSheet}){
# Create a slurm job handler
my $projJob =
Molmed::Sisyphus::Uppmax::SlurmJob->new(
DEBUG=>$debug, # bool
SCRIPTDIR=>$scriptDir, # Directory for writing the script
EXECDIR=>$rfPath, # Directory from which to run the script
NAME=>"$proj-$rfShort",# Name of job, also used in script name
PROJECT=>$uProj, # project for resource allocation
TIME=>"0-06:00:00", # Maximum runtime, formatted as d-hh:mm:ss
QOS=>$uQos, # High priority
PARTITION=>'core', # core or node (or devel));
MAIL_USER=>$email,
MAIL_TYPE=>'FAIL'
);
foreach my $lane (keys (%{$sampleSheet->{$proj}})){
$projJob->addDep($ffJobs{$lane}) if exists($ffJobs{$lane});
}
$projJob->addCommand("module load uppmax");
$projJob->addCommand("module load gnuplot");
$projJob->addCommand("umask 007");
my $cmd = "$FindBin::Bin/extractProject.pl -runfolder $rfPath -project '$proj' -outdir '$oPath/$proj' $debugFlag";
foreach my $lane (@{$skipLanes}){
$cmd .= " -skip $lane";
}
$projJob->addCommand($cmd, "extractProject.pl on $proj FAILED");
print STDERR "Submitting $proj-$rfShort\t";
$projJob->submit({queue=>1});
$projJobs{$proj} = $projJob;
print STDERR $projJob->jobId(), "\n";
# Make sure to get the script md5 into the sisyphus cache,
# otherwise any old checksum from a failed run might fail the
# archiving
my $scriptFile = $projJob->scriptFile();
print STDERR "$scriptFile\n";
# If an old script was created the MD5 might be saved, so make sure to overwrite that
$sisyphus->saveMd5($scriptFile, $sisyphus->getMd5($scriptFile, -noCache=>1));
}
# Global report
# Depend on all other jobs
# Create a slurm job handler
my $repJob =
Molmed::Sisyphus::Uppmax::SlurmJob->new(
DEBUG=>$debug, # bool
SCRIPTDIR=>$scriptDir, # Directory for writing the script
EXECDIR=>$rfPath, # Directory from which to run the script
NAME=>"Rep-$rfShort", # Name of job, also used in script name
PROJECT=>$uProj, # project for resource allocation
TIME=>"0-10:00:00", # Maximum runtime, formatted as d-hh:mm:ss
QOS=>$uQos, # High priority
PARTITION=>'core', # core or node (or devel));
MAIL_USER=>$email,
MAIL_TYPE=>'FAIL'
);
foreach my $job (values %projJobs){
$repJob->addDep($job);
}
$repJob->addCommand("module load uppmax");
$repJob->addCommand("module load gnuplot");
$repJob->addCommand("umask 007");
$repJob->addCommand("$FindBin::Bin/generateReport.pl -runfolder $rfPath $debugFlag", "generateReport.pl on $rfPath FAILED");
print STDERR "Submitting Rep-$rfShort\t";
$repJob->submit({queue=>1});
print STDERR $repJob->jobId(), "\n";
# Make sure to get the script md5 into the sisyphus cache,
# otherwise any old checksum from a failed run might fail the
# archiving
my $scriptFile = $repJob->scriptFile();
print STDERR "$scriptFile\n";
# If an old script was created the MD5 might be saved, so make sure to overwrite that
$sisyphus->saveMd5($scriptFile, $sisyphus->getMd5($scriptFile, -noCache=>1));
# Archive
# Depend on report generation
# Create a slurm job handler
my $archJob =
Molmed::Sisyphus::Uppmax::SlurmJob->new(
DEBUG=>$debug, # bool
SCRIPTDIR=>$scriptDir, # Directory for writing the script
EXECDIR=>$rfPath, # Directory from which to run the script
NAME=>"Arch-$rfShort", # Name of job, also used in script name
PROJECT=>$uProj, # project for resource allocation
TIME=>"2-00:00:00", # Maximum runtime, formatted as d-hh:mm:ss
PARTITION=>'core', # core or node (or devel))
CORES=>'2',
MAIL_USER=>$email,
MAIL_TYPE=>'FAIL'
);
$archJob->addDep($repJob);
$archJob->addCommand("module load uppmax");
$archJob->addCommand("module load irods/swestore");
$archJob->addCommand("umask 007");
# Add year and month to outdir if not already included
unless($aPath =~ m/201\d-[0123]\d$/){
if($sisyphus->RUNFOLDER =~ m/(1\d)([01]\d)[0123]\d_/){
$aPath .= "/20$1-$2";
}
}
unless($iPath =~ m/201\d-[0123]\d$/){
if($sisyphus->RUNFOLDER =~ m/(1\d)([01]\d)[0123]\d_/){
$iPath .= "/20$1-$2";
}
}
$archJob->addCommand("$FindBin::Bin/archive.pl -runfolder $rfPath -outdir '$aPath' -swestore $debugFlag", "archive.pl on $rfPath FAILED");
print STDERR "Submitting Arch-$rfShort\t";
$archJob->submit({queue=>1});
print STDERR $archJob->jobId(), "\n";
# Make sure to get the script md5 into the sisyphus cache,
# otherwise any old checksum from a failed run might fail the
# archiving
$scriptFile = $archJob->scriptFile();
print STDERR "$scriptFile\n";
# If an old script was created the MD5 might be saved, so make sure to overwrite that
$sisyphus->saveMd5($scriptFile, $sisyphus->getMd5($scriptFile, -noCache=>1));
print STDERR "Done\n";