This repository has been archived by the owner on Jun 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckData.pl
98 lines (86 loc) · 2.22 KB
/
checkData.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
#!/usr/local/bin/perl
#use LWP::UserAgent;
#use DBI;
use Getopt::Long;
use Pod::Usage;
$absoluteDirPath = '';
$fileIndivs = ''; # Input file
$maxProc = 50;
$libDir = '';
GetOptions('absolute_dir_path=s' => \$absoluteDirPath,
'indivs_file=s' => \$fileIndivs,
'max_procs=s' => \$maxProc,
'lib_dir=s' => \$libDir
)or pod2usage(1);
mkdir $absoluteDirPath."/logs";
$scriptCheck = $libDir."/checkData.R";
$scriptExtract = $libDir."/mergeDataChecks.R";
$nprocs = 0;
@indivs = ();
$k=0;
$step=10;
open (FHI, $fileIndivs)|| die ("cannot open file ".$fileIndivs);
while($line = <FHI>){
$line =~ s/\012//;
$line =~ s/\015//;
push @indivs, $line;
}
for $ind (@indivs){
$cmd = "nohup R --slave dir=".$absoluteDirPath."/".$ind." analysis=checkData < ".$scriptCheck." >& ".$absoluteDirPath."/logs/check_".$ind.".out &";
if($nprocs<$maxProc){
system($cmd);
$nprocs++;
$pct = $k/scalar(@indivs)*100;
if($pct >= $step){
print "\t".$step." % done\n";
$step=$step+10;
}
$k++;
#print "Number of processes running : ".$nprocs."\n";
}
else{
while($nprocs>=$maxProc){
system("ps ux > tmpfile");
open(FHps,"tmpfile") || die("cannot open file tmpfile");
$lin = <FHps>;
$nprocs = 0;
while($lin=<FHps>){
$lin =~ s/\012//;
$lin =~ s/\015//;
if($lin =~ m/analysis\=checkData/gi){
$nprocs ++;
}
}
close(FHps);
#print "Number of processes running : ".$nprocs."\n";
}
system($cmd);
$pct = $k/scalar(@indivs)*100;
if($pct >= $step){
print "\t".$step." % done\n";
$step=$step+10;
}
$k++;
}
}
close(FHI);
print "\n\tWaiting for all processes to finish ... \n\n";
$nprocs = 1;
while($nprocs > 0){
system("ps ux > tmpfile");
open(FHps,"tmpfile") || die("cannot open file tmpfile");
$lin = <FHps>;
$nprocs = 0;
while($lin=<FHps>){
$lin =~ s/\012//;
$lin =~ s/\015//;
if($lin =~ m/analysis\=checkData/gi){
$nprocs ++;
}
}
close(FHps);
}
system("rm -f tmpfile");
print "\n\tExtracting results ... \n";
$cmd = "R --slave dir=".$absoluteDirPath." indivsFile=".$fileIndivs." < ".$scriptExtract." > ".$absoluteDirPath."/logs/check_extraction.out ";
system($cmd);