-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunNuclDyn
executable file
·117 lines (95 loc) · 3.18 KB
/
runNuclDyn
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
#!/usr/bin/perl
# Copyright 2019 Barcelona Supercomputing Center
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# runNuclDyn: launcher for Nucl. Dynamics executables
# Authors: Josep Ll. Gelpi 2018
# Authors: Marc del Pino 2019
use strict;
use File::Basename;
use Cwd;
my $RSCRIPT = "/usr/bin/Rscript";
my $NDDIR = "/home/NucleosomeDynamics";
if (! -d $NDDIR){
my $lo = dirname($0);
$lo =~ s/\.//g;
$NDDIR = cwd().$lo;
}
my $BINDIR = "$NDDIR/NucleosomeDynamics/bin";
my $STATSDIR = "$NDDIR/NucleosomeDynamics/statistics";
my $HELPDIR = "$NDDIR/help";
# my $DATADIR = "/data_dir"; # used to find DATADIR/scripts/user_wf.file
# my $PUBLICDIR = "/public_dir"; # OBSOLETE
my $FUNCTIONS = ['run','readBAM','nucleR','NFR','txstart','periodicity','stiffness','nucDyn','nucleR2structure','toBigWig','fromBigWig','coverage','js_plot'];
my $FUNCTIONS_STATS = ['nucleR_stats','NFR_stats','txstart_stats','periodicity_stats','stiffness_stats','nucDyn_stats'];
#
system ("/bin/cat $HELPDIR/header.txt");
# Main Help
if (!@ARGV || ($ARGV[0] eq '--help') || ($ARGV[0] eq '-h')) {
system ("/bin/cat $HELPDIR/main.hlp");
exit;
}
my $op = shift;
if (!is_valid_function($op) && !is_valid_function_stats($op)) {
die "\nError: unrecognized function $op, try [-h |--help]\n\n";
}
#Specific help
if (!@ARGV || ($ARGV[0] eq '--help') || ($ARGV[0] eq '-h')) {
system ("/bin/cat $HELPDIR/$op.hlp");
exit;
}
# Running tool
#
my $hasError_file = "/tmp/hasError".rand();
my $cmd_catchErr = "while read line; do echo \$line; if echo \${line} | grep -iqP 'ERROR'; then echo \${line} > $hasError_file; fi; done";
#if (-e $DATADIR) {
#chdir $DATADIR;
# }
if ($op eq "run") {
print "===> Running $op <===\n\n";
system ("/bin/sh @ARGV 2>&1 | $cmd_catchErr");
} else {
print "===> Running $op <===\n\n";
if (($op =~ /stats/) && is_valid_function_stats($op)) {
$op =~ s/_stats//g;
my $args_str = join(" ",@ARGV);
my $cmd = "$RSCRIPT $STATSDIR/$op.R $args_str 2>&1 | $cmd_catchErr\n";
system($cmd);
} elsif (is_valid_function($op)) {
my $args_str = join(" ",@ARGV);
my $cmd = "$RSCRIPT $BINDIR/$op.R $args_str 2>&1 | $cmd_catchErr\n";
system ($cmd);
} else {
system ("/bin/cat $HELPDIR/main.hlp");
}
}
# Catch error
#
if (-e $hasError_file){
print STDERR "ERROR while running $op. Check the full report at 'stdout'\n";
}
sub is_valid_function {
my $f = shift;
return _is_valid($f, $FUNCTIONS);
}
sub is_valid_function_stats {
my $f = shift;
return _is_valid($f, $FUNCTIONS_STATS);
}
sub _is_valid {
my ($f, $list) = @_;
my $i=0;
while (($i<$#{$list}) && ($list->[$i] ne $f)) {$i++};
return ($list->[$i] eq $f);
}