-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun_pipeline_mysql.pl
199 lines (149 loc) · 5.01 KB
/
run_pipeline_mysql.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
#!/usr/bin/env perl
use strict;
use Getopt::Long;
use Config::Simple;
use Data::Dumper;
use File::Temp qw/ :POSIX /;
use File::Path qw(make_path);
use Cwd qw(cwd);
# Wrapper for running the pipeline in MySQL mode - Use with nohup and ideally save log
my ($confFile,$show_help);
my $nextflow = "nextflow";
# Tested NF version
my $nextflowver = "20.10.0";
my $nfscript = "main.nf";
my $nfparams = ""; # By default no additional params
my $resume = 0;
my $mysqlonly = 0;
my $engine = "sge";
my $mysqldata = $ENV{'HOME'}."/mysqldata";
my $mysqllog = $ENV{'HOME'}."/mysqllog";
# Random
my @rchars = ("A".."Z", "a".."z");
my $random;
$random .= @rchars[rand @rchars] for 1..8;
# extra params for cluster queue
my $extra = "-j y -l virtual_free=4G,h_rt=372800 -N MYSQL_container -m be -cwd -V -q long-sl7";
GetOptions(
"conf=s"=>\$confFile,
"help|h" => \$show_help,
"nextflow=s" => \$nextflow,
"nextflowver=s" => \$nextflowver,
"params=s" => \$nfparams,
"extra=s" => \$extra,
"resume|r" => \$resume,
"mysqlonly|m" => \$mysqlonly,
"engine=s" => \$engine
);
my $resumeStr = "";
if ( $resume ) {
$resumeStr = "-resume";
}
if( !defined $confFile || $show_help ) {
die(qq/
Usage: run_pipeline_mysql.pl [options]
Options
-h || help : This message
-conf : Configuration file; by default 'main_configuration.ini' in the current folder
-nextflow : Nextflow path
-params : Parameters for Nextflow program
-extra : Extra parameters to be passed to the cluster queue
-resume : Resume the pipeline (it passes -resume argument to nextflow)
-mysqlonly : Lauch only MySQL server (as far as running in MySQL mode)
-engine : Engine to be used (so far 'sge' by default, otherwise local)
\n/);
}
my $tmpconf = tmpnam();
my $pwd = cwd;
my $strFile="";
open( CONF, $confFile );
while ( <CONF> ) {
if ( $_=~/\$\{baseDir\}/ ) {
s/\$\{baseDir\}/$pwd/g;
}
if ( $_=~/\$baseDir/ ) {
s/\$baseDir/$pwd/g;
}
if ($_=~/^\s*params\s*{\s*$/) {
next;
}
if ($_=~/^\s*}\s*$/) {
next;
}
$_=~s/\s*\=\s*/:/g;
if ( $_=~/^\s*\/\// ) {
next;
}
$strFile = $strFile. $_;
}
close( CONF );
open( TMPCONF, ">$tmpconf" );
print TMPCONF $strFile;
close( TMPCONF );
# Parsing params.config (the same place as nexflow for sake of simplicity)
my $cfg = new Config::Simple($tmpconf);
#put config parameters into %config
my %config = $cfg->vars();
print Dumper( \%config );
# If MySQL mode
if ( lc( $config{"dbEngine"} ) eq 'mysql' ) {
# Check all MySQL params are there
if ( ! $config{"mysqlimg"} || ! -f $config{"mysqlimg"} ) {
$config{"mysqlimg"} = "docker://library/mariadb";
}
if ( $config{"dbuser"} && $config{"dbpass"} && $config{"dbport"} && $config{"mysqlimg"} ) {
if ( $config{"mysqllog"} ) {
$mysqllog = $config{"mysqllog"};
}
if ( $config{"mysqldata"} ) {
$mysqldata = $config{"mysqldata"};
}
if ( ! -d $mysqldata ) { make_path( $mysqldata ); }
if ( ! -d $mysqllog ) { make_path( $mysqllog ); }
# Avoid show IP of previous process
if ( -f "$mysqllog/DBHOST" ) {
unlink "$mysqllog/DBHOST";
}
# Generate files
# Mysqlconf
my $cnfcontent = "[mysqld]\nbind-address=0.0.0.0\nport=".$config{"dbport"}."\n";
open( CNF, ">$mysqllog/CNF" ); print CNF $cnfcontent; close( CNF );
$extra = $extra. " -e $mysqllog/ERR -o $mysqllog/OUT ";
if ( $engine eq 'sge' ) {
$extra = "qsub ". $extra;
} elsif ( $engine eq 'local' ) {
$extra = "bash";
} else {
die( "Not supported engine!" );
}
# Run MySQL qsub process. TODO: Allow more flexibility here
system( "$extra run.mysql.qsub.sh ".$config{"mysqlimg"}." $mysqldata $mysqllog/CNF $mysqllog/DBHOST $mysqllog/PROCESS ".$config{"dbuser"}." ".$config{"dbpass"}." ".$config{"dbport"}. " ". $random ." & " );
# Run nextflow
# TODO: To reconsider way of checking
while ( ! -d "$mysqldata/db" ) {
sleep( 5 );
}
if ( ! $mysqlonly ) {
while ( ! -f "$mysqllog/PROCESS" ) {
sleep( 5 );
}
my $myip=`cat "$mysqllog/DBHOST"`;
print "DBHOST: ".$myip."\n";
print( "Run NEXTFLOW\n") ;
system( "export NXF_VER=$nextflowver; $nextflow run $nfparams -bg $nfscript $resumeStr --config $confFile" );
} else {
while ( ! -f "$mysqllog/DBHOST" ) {
sleep( 5 );
}
my $myip=`cat "$mysqllog/DBHOST"`;
print "DBHOST: ".$myip."\n";
}
} else {
exit 1;
}
} else {
# Else, SQLite mode
# Run Nextflow pipeline
print( "Run NEXTFLOW\n") ;
system( "export NXF_VER=$nextflowver; $nextflow run $nfparams -bg $nfscript $resumeStr --config $confFile" );
}