-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathscafe.check.dependencies
574 lines (462 loc) · 19.3 KB
/
scafe.check.dependencies
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
#!/usr/bin/env perl
# This chunk of stuff was generated by App::FatPacker. To find the original
# file's code, look for the end of this BEGIN block or the string 'FATPACK'
BEGIN {
my %fatpacked;
s/^ //mg for values %fatpacked;
my $class = 'FatPacked::'.(0+\%fatpacked);
no strict 'refs';
*{"${class}::files"} = sub { keys %{$_[0]} };
if ($] < 5.008) {
*{"${class}::INC"} = sub {
if (my $fat = $_[0]{$_[1]}) {
my $pos = 0;
my $last = length $fat;
return (sub {
return 0 if $pos == $last;
my $next = (1 + index $fat, "\n", $pos) || $last;
$_ .= substr $fat, $pos, $next - $pos;
$pos = $next;
return 1;
});
}
};
}
else {
*{"${class}::INC"} = sub {
if (my $fat = $_[0]{$_[1]}) {
open my $fh, '<', \$fat
or die "FatPacker error loading $_[1] (could be a perl installation issue?)";
return $fh;
}
return;
};
}
unshift @INC, bless \%fatpacked, $class;
} # END OF FATPACK CODE
#====================================================================================================================================================#
#<use>
$|++; #---turn on the auto flush for the progress bar
no warnings 'utf8';
use warnings;
use strict;
use Getopt::Long 'HelpMessage';
use Time::HiRes qw( time );
use File::Spec::Functions qw(rel2abs abs2rel);
use Cwd 'abs_path';
#<\use>
#====================================================================================================================================================#
#====================================================================================================================================================#
#<doc>
=head1 SYNOPSIS
5'-O~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~AAA-3'
O~~~AA O~~ O~ O~~~~~~~AO~~~~~~~~A
O~~ O~~ O~~ O~~ O~O~~ O~~ O~~
O~~ O~~ O~ O~~ O~~ O~~
O~~ O~~ O~~ O~~ O~~~~~AA O~~~~~~A
O~~ O~~ O~~~~~A O~~ O~~ O~~
O~~ O~~ O~~ O~~ O~~ O~~ O~~ O~~
O~~~~A O~~~ O~~ O~~O~~ O~~~~~~~AA
┌─ᐅ 5'-O~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-3'
...===┴========================================================================================...
Single Cell Analysis of Five-prime End (SCAFE) Tool Suite
---> check.dependencies <---
<--- check dependencies --->
Description:
This scripts check the integrity of tools and workflow scripts, 3rd executable dependencies and R packages.
Usage:
check.dependencies
Dependencies:
wget
tar
Rscript
For demo, cd to SCAFE dir and run,
scafe.check.dependencies
=head1 VERSION
v0.9.0-beta [March 20, 2021]
-Initial pre-release
v1.0.0 [June 6, 2022]
-will check optimize_tangent.R
-will check tabix and bgzip
-will not check cicero related function
=cut
#<\doc>
#====================================================================================================================================================#
#====================================================================================================================================================#
#<lastCmdCalled>
#
# notCalledBefore
#
# notCalledBefore
#
#<\lastCmdCalled>
#====================================================================================================================================================#
#====================================================================================================================================================#
#<global>
#<\global>
#====================================================================================================================================================#
#====================================================================================================================================================#
{ #Main sections lexical scope starts
#====================================================================================================================================================#
#====================================================================================================================================================#
# section 0_startTasks
#
#<section ID="startTasks" num="0">
my $check_hsh_ref = {};
&readParameters();#->433
my ($scafe_dir, $script_dir, $check_dir) = &prepDir();#->407
&checkPerlScript($script_dir, $check_hsh_ref);#->156
&checkDownload($check_dir, $check_hsh_ref);#->123
&checkThirdParty($scafe_dir, $check_hsh_ref);#->291
&checkRVersion($check_hsh_ref);#->252
&checkRPackages($check_hsh_ref);#->197
&checkRScript($scafe_dir, $check_hsh_ref);#->224
&summary($check_hsh_ref);#->453
#<\section>
#====================================================================================================================================================#
#====================================================================================================================================================#
# section 1_run
#
#<section ID="run" num="1">
#<\section>
#====================================================================================================================================================#
#====================================================================================================================================================#
} #Main sections lexical scope ends
#====================================================================================================================================================#
#====================================================================================================================================================#
#List of subroutines by category
#
# general [n=1]:
# readParameters
#
# unassigned [n=8]:
# checkDownload, checkPerlScript, checkRPackages
# checkRScript, checkRVersion, checkThirdParty
# prepDir, summary
#
#====================================================================================================================================================#
sub checkDownload {
#....................................................................................................................................................#
# subroutineCategory: unassigned
# dependOnSub: >none
# appearInSub: >none
# primaryAppearInSection: 0_startTasks|82
# secondaryAppearInSection: >none
# input: $check_dir, $check_hsh_ref
# output:
# toCall: &checkDownload($check_dir, $check_hsh_ref);
# calledInLine: 89
#....................................................................................................................................................#
my ($check_dir, $check_hsh_ref) = @_;
my $status = "checking";
my $check_name = "wget tar data";
my $type = "dropbox access";
printf ("%-20s %-35s %-10s\r", $type, $check_name, $status);
my $check_data_url = "https://www.dropbox.com/s/yx1306zuvtc7li3/demo.tar.gz";
my $tar_gz_path = "$check_dir/demo.tar.gz";
system ("rm -f $tar_gz_path");
system ("rm -rf $check_dir/demo/");
my $stdout = `wget $check_data_url -P $check_dir 2>&1`;
system ("tar -xzvf $tar_gz_path -C $check_dir 2>&1 >/dev/null");
$status = "failed";
$status = 'successful' if (-s "$check_dir/demo/demo.txt");
printf ("%-20s %-35s %-10s\n", $type, $check_name, $status);
system ("rm -rf $check_dir");
$check_hsh_ref->{$status}{$type}{$check_name}++;
return ();
}
sub checkPerlScript {
#....................................................................................................................................................#
# subroutineCategory: unassigned
# dependOnSub: >none
# appearInSub: >none
# primaryAppearInSection: 0_startTasks|82
# secondaryAppearInSection: >none
# input: $check_hsh_ref, $script_dir
# output:
# toCall: &checkPerlScript($script_dir, $check_hsh_ref);
# calledInLine: 88
#....................................................................................................................................................#
my ($script_dir, $check_hsh_ref) = @_;
print "===============================\n";
print "start checking\n";
print "===============================\n";
printf ("%-20s %-35s %-10s\n", 'Check Type', 'Check Item', 'Check Status');
printf ("%-20s %-35s %-10s\n", '===============', '===============', '===============');
my $type = "perl executables";
my $readme_path = "$script_dir/README.md";
open README, "<", $readme_path;
while (<README>) {
chomp;
if ($_ =~ m/^\* \[\*\*(.+)\*\*\]/) {
my $script_name = $1;
$script_name =~ s/\\//g;
my $status = "checking";
printf ("%-20s %-35s %-10s\r", $type, $script_name, $status);
my $script_path = "$script_dir/$script_name";
my @help_message = `$script_path --help`;
$status = "failed";
$status = 'successful' if ($help_message[0] =~ m/Usage:/);
printf ("%-20s %-35s %-10s\n", $type, $script_name, $status);
$check_hsh_ref->{$status}{$type}{$script_name}++;
}
}
close README;
return ();
}
sub checkRPackages {
#....................................................................................................................................................#
# subroutineCategory: unassigned
# dependOnSub: >none
# appearInSub: >none
# primaryAppearInSection: 0_startTasks|82
# secondaryAppearInSection: >none
# input: $check_hsh_ref
# output:
# toCall: &checkRPackages($check_hsh_ref);
# calledInLine: 92
#....................................................................................................................................................#
my ($check_hsh_ref) = @_;
my $type = "R packages";
foreach my $package (qw/ROCR PRROC caret e1071 ggplot2 scales reshape2 R.utils/) {
my $status = "checking";
printf ("%-20s %-35s %-10s\r", $type, $package, $status);
my $stdOut = `Rscript -e "packageVersion('$package')" 2>&1`;
$status = "failed";
$status = 'successful' if ($stdOut =~ m/[1]/);
printf ("%-20s %-35s %-10s\n", $type, $package, $status);
$check_hsh_ref->{$status}{$type}{$package}++;
}
return ();
}
sub checkRScript {
#....................................................................................................................................................#
# subroutineCategory: unassigned
# dependOnSub: >none
# appearInSub: >none
# primaryAppearInSection: 0_startTasks|82
# secondaryAppearInSection: >none
# input: $check_hsh_ref, $scafe_dir
# output:
# toCall: &checkRScript($scafe_dir, $check_hsh_ref);
# calledInLine: 93
#....................................................................................................................................................#
my ($scafe_dir, $check_hsh_ref) = @_;
my $type = "R scripts";
my $R_dir = "$scafe_dir/resources/R/";
foreach my $R_script (qw/benchmark_roc.R build_glm.R predict_prob.R optimize_tangent.R/) {
my $status = "checking";
printf ("%-20s %-35s %-10s\r", $type, $R_script, $status);
my $stdOut = `Rscript $R_dir/$R_script 2>&1`;
$status = "failed";
$status = 'successful' if ($stdOut =~ m/Error: $R_script has no input/);
printf ("%-20s %-35s %-10s\n", $type, $R_script, $status);
$check_hsh_ref->{$status}{$type}{$R_script}++;
}
return ();
}
sub checkRVersion {
#....................................................................................................................................................#
# subroutineCategory: unassigned
# dependOnSub: >none
# appearInSub: >none
# primaryAppearInSection: 0_startTasks|82
# secondaryAppearInSection: >none
# input: $check_hsh_ref
# output:
# toCall: &checkRVersion($check_hsh_ref);
# calledInLine: 91
#....................................................................................................................................................#
my ($check_hsh_ref) = @_;
my $type = "R version";
my $name = "v3.5 or later";
my $status = "checking";
printf ("%-20s %-35s %-10s\r", $type, $name, $status);
my $stdOut = `Rscript --version 2>&1`;
$status = 'failed';
if ($stdOut =~ m/version (.+) /) {
my ($version, $sub_version) = split /\./, $1;
#print "$version $sub_version\n";
if ($version >= 3) {
if ($version > 3) {
$status = 'successful';
} else {
if ($sub_version >= 5) {
$status = 'successful';
}
}
}
}
printf ("%-20s %-35s %-10s\n", $type, $name, $status);
$check_hsh_ref->{$status}{$type}{$name}++;
return ();
}
sub checkThirdParty {
#....................................................................................................................................................#
# subroutineCategory: unassigned
# dependOnSub: >none
# appearInSub: >none
# primaryAppearInSection: 0_startTasks|82
# secondaryAppearInSection: >none
# input: $check_hsh_ref, $scafe_dir
# output:
# toCall: &checkThirdParty($scafe_dir, $check_hsh_ref);
# calledInLine: 90
#....................................................................................................................................................#
my ($scafe_dir, $check_hsh_ref) = @_;
my $bedtools_bin = "$scafe_dir/resources/bin/bedtools/bedtools";
my $samtools_bin = "$scafe_dir/resources/bin/samtools/samtools";
my $paraclu_bin = "$scafe_dir/resources/bin/paraclu/paraclu";
my $cut_sh_path = "$scafe_dir/resources/bin/paraclu/paraclu-cut.sh";
my $bedGraphToBigWig_bin = "$scafe_dir/resources/bin/bedGraphToBigWig/bedGraphToBigWig";
my $bigWigAverageOverBed_bin = "$scafe_dir/resources/bin/bigWigAverageOverBed/bigWigAverageOverBed";
my $tabix_bin = "$scafe_dir/resources/bin/tabix/tabix";
my $bgzip_bin = "$scafe_dir/resources/bin/bgzip/bgzip";
my $type = "3rd-party apps";
{
my $status = "checking";
my $check_name = "bgzip";
printf ("%-20s %-35s %-10s\r", $type, $check_name, $status);
my $stdOut = `$bgzip_bin --version 2>&1`;
$status = "failed";
$status = 'successful' if ($stdOut =~ m/bgzip \(htslib\) (\S+)/);
printf ("%-20s %-35s %-10s\n", $type, $check_name, $status);
$check_hsh_ref->{$status}{$type}{$check_name}++;
}
{
my $status = "checking";
my $check_name = "tabix";
printf ("%-20s %-35s %-10s\r", $type, $check_name, $status);
my $stdOut = `$tabix_bin --version 2>&1`;
$status = "failed";
$status = 'successful' if ($stdOut =~ m/tabix \(htslib\) (\S+)/);
printf ("%-20s %-35s %-10s\n", $type, $check_name, $status);
$check_hsh_ref->{$status}{$type}{$check_name}++;
}
{
my $status = "checking";
my $check_name = "bedtools";
printf ("%-20s %-35s %-10s\r", $type, $check_name, $status);
my $stdOut = `$bedtools_bin --version 2>&1`;
$status = "failed";
$status = 'successful' if ($stdOut =~ m/bedtools v(\S+)/);
printf ("%-20s %-35s %-10s\n", $type, $check_name, $status);
$check_hsh_ref->{$status}{$type}{$check_name}++;
}
{
my $status = "checking";
my $check_name = "samtools";
printf ("%-20s %-35s %-10s\r", $type, $check_name, $status);
my $stdOut = `$samtools_bin 2>&1`;
$status = "failed";
$status = 'successful' if ($stdOut =~ m/\s+(Version: \S+)\s+/);
printf ("%-20s %-35s %-10s\n", $type, $check_name, $status);
$check_hsh_ref->{$status}{$type}{$check_name}++;
}
{
my $status = "checking";
my $check_name = "paraclu";
printf ("%-20s %-35s %-10s\r", $type, $check_name, $status);
my $stdOut = `$paraclu_bin 2>&1`;
$status = "failed";
$status = 'successful' if ($stdOut =~ m/paraclu: I need a minValue and a fileName/);
printf ("%-20s %-35s %-10s\n", $type, $check_name, $status);
$check_hsh_ref->{$status}{$type}{$check_name}++;
}
{
my $status = "checking";
my $check_name = "paraclu-cut.sh";
printf ("%-20s %-35s %-10s\r", $type, $check_name, $status);
my $stdOut = `$cut_sh_path 55C7128A 2>&1`;
$status = "failed";
$status = 'successful' if ($stdOut =~ m/awk:/);
printf ("%-20s %-35s %-10s\n", $type, $check_name, $status);
$check_hsh_ref->{$status}{$type}{$check_name}++;
}
{
my $status = "checking";
my $check_name = "bedGraphToBigWig";
printf ("%-20s %-35s %-10s\r", $type, $check_name, $status);
my $stdOut = `$bedGraphToBigWig_bin 2>&1`;
$status = "failed";
$status = 'successful' if ($stdOut =~ m/bedGraphToBigWig v (\S+)/);
printf ("%-20s %-35s %-10s\n", $type, $check_name, $status);
$check_hsh_ref->{$status}{$type}{$check_name}++;
}
{
my $status = "checking";
my $check_name = "bigWigAverageOverBed";
printf ("%-20s %-35s %-10s\r", $type, $check_name, $status);
my $stdOut = `$bigWigAverageOverBed_bin 2>&1`;
$status = "failed";
$status = 'successful' if ($stdOut =~ m/bigWigAverageOverBed v(\S+)/);
printf ("%-20s %-35s %-10s\n", $type, $check_name, $status);
$check_hsh_ref->{$status}{$type}{$check_name}++;
}
return ();
}
sub prepDir {
#....................................................................................................................................................#
# subroutineCategory: unassigned
# dependOnSub: >none
# appearInSub: >none
# primaryAppearInSection: 0_startTasks|82
# secondaryAppearInSection: >none
# input: none
# output: $check_dir, $scafe_dir, $script_dir
# toCall: my ($scafe_dir, $script_dir, $check_dir) = &prepDir();
# calledInLine: 87
#....................................................................................................................................................#
my $scriptAbsPath = abs_path($0);
my @path_split = split /\//, $scriptAbsPath;
my $scafe_dir_index = $#path_split-2;
my $script_dir_index = $#path_split-1;
my $scafe_dir = join "/", @path_split[0..$scafe_dir_index];
my $script_dir = join "/", @path_split[0..$script_dir_index];
my @mkDirAry = ();
my $check_dir = $scafe_dir."/check_log/"; push @mkDirAry, $check_dir;
foreach my $dir (@mkDirAry) {system ("mkdir -pm 755 $dir");}
return ($scafe_dir, $script_dir, $check_dir);
}
sub readParameters {
#....................................................................................................................................................#
# subroutineCategory: general
# dependOnSub: >none
# appearInSub: >none
# primaryAppearInSection: 0_startTasks|82
# secondaryAppearInSection: >none
# input: none
# output:
# toCall: &readParameters();
# calledInLine: 86
#....................................................................................................................................................#
GetOptions (
'help' => sub { HelpMessage(0) },
);
return();
}
sub summary {
#....................................................................................................................................................#
# subroutineCategory: unassigned
# dependOnSub: >none
# appearInSub: >none
# primaryAppearInSection: 0_startTasks|82
# secondaryAppearInSection: >none
# input: $check_hsh_ref
# output:
# toCall: &summary($check_hsh_ref);
# calledInLine: 94
#....................................................................................................................................................#
my ($check_hsh_ref) = @_;
print "===============================\n";
print "Finished checking\n";
print "===============================\n";
print "\n";
if (not exists $check_hsh_ref->{'failed'}) {
print "Successful for all checks. SCAFE should run well.\n";
} else {
print "A few checks failed. Please address.\n";
}
return ();
}
exit;