-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathpostimp_navi
executable file
·5130 lines (3679 loc) · 123 KB
/
postimp_navi
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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
use strict;
########################################
#
# version 24:
#
# chunk results and then meta-chunk
# area_plot_speed
# new manhattan plot
# new areator
# chrX
# new gwascatalog
# exclude refind: cat pi_sub/prephase_job_list_multi1 | awk '{print $3}' | sed 's/.*chr/chr/' | sed 's/.bed//' > refind.ex
#
# version 32:
# checkflip with fth
#
#
# version 5:
# with auto-het
# with --addcov#
#
#
#
# version 7:
# for LISA
#
# version 8:
# fam testing for after-joinimp
#
# version 9:
# danerdir_long into week queue
#
# version 10:
# ldscore
# prepare leave_one_out
#
# version 11:
# want to check for idin, addcov, idex (not implemeted yet)
#
# version 12:
# serial
#
# version 13
# plink2 also for dosages
# --noldsc
# error checking for result-files
#
# version 14
# --nolahunt
#
# version 15
# --fix some little things
# --clumper into clump-navi3
# --clumper out of --onlymeta and separate switch
#
# version 16
# danerdir_6: for covariates in trio data (important for conditional tests)
#
# version 17
# improvements for big datasets (danerdir_long and similar)
#
# version 18
# getting rid of pi_sub
# checking --idin
#
# verion 19
# metaber6 with checks of consistency of SNPs.
#
# version 20
# metaber7 with detailed samplesize per SNP
#
#
########################
# asked: actual sample size per SNP
# check if mds file fits to famfiles ( I thoughts thats done but apparently not, see swapnil and run1 and run2)
####################
#
#######################################
### working on 35, stopped at after chucker........
### get the stuff at the end of onlymeta
### look for here working (2 spots)
#############################
# load utility functions
#############################
use FindBin;
use lib "$FindBin::Bin";
use Ricopili::Utils qw(trans);
use Ricopili::Version;
#my $version = "1.0.30";
my $progname = $0;
$progname =~ s!^.*/!!;
my $command_line = "$progname @ARGV";
my $s2gr = 300;
my $jmem = 3000; ### memory for puter imputation job
my $jmem_sm = 1000; ### memory for smaller job
my $jnum = 7; ### number of imputation job per node
my $spliha_n = 1500; ## split haplotypes with N individuals
my $best_lahunt = 5;
my $multithread1 = 4;
my $multithread2 = 8;
my $nj = 4;
my $phas = 0;
my $walltime = 1;
my $chr =0;
my $gmodel = 0;
my $rseed = 0;
my $info_txt = "";
#my $homedir = "/home/gwas";
my $rootdir = "";
my $iname = "" ;
my $pheno_file = "NOPHENO";
my $suminfo = "infosum_pos";
my $suminfo_n = "$suminfo.nsnps";
my $suminfo_r = "$suminfo.reffiles";
my $suminfo_s = "$suminfo.sorted";
my $job_bn_th = 1000;
my @ref_coll = ();
my $info_th = "0.1";
#print "hmm\n";
#exit;
## permutation
## awk '{print $1,$2,int(2*rand())+1}' ....mds_cov > .....mds_cov.perm1
##
#my $hapmap_ref_root = "/home/gwas/pgc-samples/hapmap_ref/";
my $polyfrom_file = "";
my $danscore_file = "";
my $range_file = "";
my $polyto_file = "";
my $sepa = 1;
my $fth_th = 0.15;
use Sys::Hostname;
my $host = hostname;
my $serial = 0;
#my $broad = 1 if ($ENV{"DOMAINNAME"} =~ /broadinstitute/);
#############################
# read config file
#############################
my $hapmap_ref_root = &trans("hmloc");
#my $homedir = &trans("home");
my $qloc = &trans("queue");
my $i2loc = &trans("i2loc");
my $email = &trans("email");
my $loloc = &trans("loloc");
my $bcmd = &trans("batch_jobcommand");
###############################################
if ($bcmd eq "SERIAL") {
$serial = 1;
print "-----------------------------------------------------\n";
print "switched on SERIAL mode because of configuration file\n";
}
#exit;
my $sec_freq = .2; ## secure freq distance around 50%
my $r2th = .1;
my $wide_range = 1500000;
my $minthread = 0;
my $popname = "eur";
my $nohet_sw = 0;
my $prekno_file = "";
##### help message
my $usage = "
Usage : $progname [options]
version: $rp_version
--test testing with only one dosage file
--chr INT only one chromosome
--help print this text and exits
--s2gr chunk size, default=$s2gr
--nj INT number of jobs in one node, default: $nj (each gets 4GB of RAM)
--walltime INT walltime for imp-jobs : $walltime
--mem INT memory for puter-jobs, in MB, default $jmem
--trio for trio data.
--triset STRING for subset of trio datasets (can contain bimfiles)
--idin STRING ID inclusion list (before imputation, while ripping)
--sep_pca create and use a separate PCA for each cohort (will get better control over popstrat)
--sep_idin STRING use a different IDset than the separate
--mds STRING mds-file (with studyindicator, (if necessary),
NOMDS if no pcaer wished and analysis without covariates
--coco STRING comma separated PCA numbers
--addcov STRING additional covariates (be sure that ID names match the famfiles, all covariates in here will be used)
header is mandatory, starting with FID IID ....
--pheno STRING alternative pheno-file in 3rd column
--strip strip id-prefix when doing phenofiles
--rseed INT random seed, default: $rseed
--cox only conditional analysis on combined group, then exit
--spliha INT split haplotypes with N individuals
# --chrX only chr X
--metaset STRING for subsets of meta datasets, especially for fores-plots (can contain bimfiles)
--outname STRING name for outfiles (mandatory)
--addout STRING name for outfiles after imputation (different analysis runs)
--allsw take all SNPs in reffiles
--model INT genetic model in dosage phase
0 - allelic (default)
1 - dominant for first allele
2 - recessive for first allele
3 - heterocygote
# --nomega do a meta and work from there,
# must do with real big datasets
# --nocon do without conditional
# --nocovar analysis without covariates
--reparea STRING replicator out file with areas to show in each study
format: SNP,CHR,POS in each row.
# --sfh FLOAT secure frequency around 50% (default: $sec_freq)
# for checkflip
# --fth FLOAT frequency-diff to exclude SNPs, default $fth_th
# for checkflip
--perm INT INT permutations while danerdir
--siperm INT single permutation with seed INT
--remeta FILE print region plots and forest plots for replication data.
--test take only 1 daner-job-round for testing round.
--wide INT widerange in BP (default $wide_range)
--cdg cdg, currently the groups mdd, bip scz
# --keep STRING keep IDFILE
--idex STRING IDs to remove
--idin STRING IDs to include (does not work with sep_pca)
--result FILE start with result files, named in STRING, one each row
must have proper header in each file
still define a phase.
--onlymeta stop after meta-analysis while starting clump_nav2
--xdf do a metaber with xdf instead of weighted meta
--r2th FLOAT areator r2-threshold, default $r2th
--prekno STRING pre-known SNPs in first column
--mach use miniMACH instead of Beagle
--polyfrom STRING ID-pt-file containing training set, creates then a danscore-file.
--polyto STRING ID-pt-file containing target set
--score STRING score - file
--range STRING range - file
--bgscore use best guess for scoring (way faster)
--minthread INT minimum multithreading
--refiex file containing refinds to exclude
--bn_job INT submit INT jobs at a time
--popname STRING population for clumping, right now: eur, eas, sas, amr, afr
--regplot STRING additional regplot file
### --cond conditional analysis on areator output
--males only use males, famfile needs to be right
--females only use females, famfile needs to be right
--nohet no het qq, manhattatn, etc
--noclump no clump if inlymeta
--force1 do not exit if same fail, but do this only once
--serial no sending jobs to queue all in one run
-> usually only used for testing
--sepa INT use INT number of parallel jobs during serial
--sleep INT sleep for INT seconds, try this if you think there is a race condition
(hints: stops a different steps, --serial works)
try using 5 seconds first.
--noldsc do not do ldscore (if problems there)
--nolahunt do not do lahunt (speeds up the pipeline)
--gwclump do genome wide clumping in the end (for scoring)
--no_neff_filter do not do Neff filter
--info_th FLOAT filter for info prior to meta-analysis, will not work on single cohort analysis
defaut $info_th
!!! use zero before period !!!
--debug extended output
********
uses puter and subchromosomes in reference
************
created by Stephan Ripke 2009 at MGH, Boston, MA
";
use Getopt::Long;
GetOptions(
"s2gr=i"=> \ $s2gr,
"chr=i"=> \ $chr,
"nj=i"=> \ $nj,
"trio"=> \my $trio,
"triset=s"=> \my $trioset_file,
"metaset=s"=> \my $metaset_file,
"remeta=s"=> \my $remeta,
"test"=> \my $test,
"help"=> \my $help,
"mach"=> \my $mach_sw,
"mds=s"=> \my $mds_name,
"sep_pca"=> \my $sep_pca,
"sep_idin=s"=> \my $sep_idin_str,
"addcov=s"=> \my $addcov_name,
"idex=s"=> \my $idex_name,
"idin=s"=> \my $idin_name,
"coco=s"=> \my $mds_cols,
"allsw"=> \my $allsw,
"cox"=> \my $cox,
"outname=s"=> \my $outname,
"serial"=> \my $serial_sw,
"sepa=i"=> \$sepa,
"sleep=i"=> \my $sleep_sw,
"walltime=i"=> \ $walltime,
"mem=i"=> \ $jmem,
"model=i" => \$gmodel,
"pheno=s"=> \$pheno_file,
"strip"=> \my $strip_pt,
# "keep=s"=> \my $keep,
"addout=s"=> \my $addout,
"nocovar"=> \my $nocovar,
"reparea=s"=> \my $reparea,
"result=s"=> \my $result_name,
"onlymeta"=> \my $onlymeta,
"noclumper"=> \my $noclumper,
# "nomega"=> \my $nomega_sw,
# "nocon"=> \my $nocon,
"xdf"=> \my $xdf,
"sfh=f"=> \$sec_freq,
"fth=f"=> \$fth_th,
"perm=i"=> \my $permut,
"siperm=i"=> \my $siperm,
"cdg"=> \my $cdg,
"rseed=i"=> \$rseed,
"r2th=f"=> \$r2th,
"wide=i"=> \$wide_range,
"prekno=s"=> \$prekno_file,
"popname=s"=> \$popname,
"refiex=s"=> \my $refiex_file,
"score=s"=> \$danscore_file,
"bgscore"=> \my $bgscore,
"range=s"=> \$range_file,
"polyfrom=s"=> \$polyfrom_file,
"polyto=s"=> \$polyto_file,
"minthread=i"=> \$minthread,
"bn_job=i"=> \$job_bn_th,
"spliha_n=i"=> \$spliha_n,
"regplot=s"=> \my $regplot_file,
"males"=> \my $males,
"females"=> \my $females,
"nohet"=> \my $nohet,
"force1"=> \my $force1,
"noldsc"=> \my $noldsc,
"nolahunt"=> \my $nolahunt,
"no_neff_filter"=> \my $no_neff_filter,
"gwclump"=> \my $gwclump,
"info_th=s"=> \$info_th,
"debug"=> \my $debug,
# "cond"=> \my $cond,
# "chrX"=> \my $chrX,
);
if ($serial_sw) {
$serial = 1;
}
$popname = uc $popname;
if ($nohet) {
$nohet_sw = 1;
}
if ($sleep_sw) {
print "sleeping for $sleep_sw seconds (only use if suspect of race condition)\n";
sleep ($sleep_sw);
}
my $no_neff_filter_txt = "";
if ($no_neff_filter) {
$no_neff_filter_txt = "--no_neff_filter";
}
############################################################
## testing binaries
##############################################################
my @test_scripts;
my $metaber_script = "metaber7"; ### my.pipeline_tar
my $daner_script = "danerdir_6"; ### my.pipeline_tar
my $danscore_result_script = "danscore_result_3"; ### my.pipeline_tar
my $chunker_script = "chunker2"; ### my.pipeline_tar
my $danerhet2p_script = "my.daner_het2p"; ### my.pipeline_tar
my $topfilter_script = "topfilter"; ### my.pipeline_tar
my $areator_script = "areator_dan9"; ### my.pipeline_tar
my $areaplot_script = "area_plot_16_speed"; ### my.pipeline_tar
my $forestplot_script = "forest_plot8"; ### my.pipeline_tar
my $manhattanplot_script = "manhattan_p4"; ### my.pipeline_tar
my $manhattanplot2_script = "manhattan_plot2"; ### my.pipeline_tar
my $qqplot_script = "qqplot_5"; ### my.pipeline_tar
my $lahunt_script = "lahunt_9"; ### my.pipeline_tar
my $ldsc_script = "my.ldsc2"; ### my.pipeline_tar
my $blueprint_script = "blueprint"; ### my.pipeline_tar
#my $clumpnavi_script = "clump_navi"; ### my.pipeline_tar
my $clumpnavi2_script = "clump_nav3"; ### my.pipeline_tar
my $shrinkpdf_script = "shrinkpdf"; ### my.pipeline_tar
my $comp1mhc_script = "comp1mhc2"; ### my.pipeline_tar
#my $comp1mhc1_script = "comp1mhc";
my $comp1mhcreg_script = "comp1mhc_reg"; ### my.pipeline_tar
my $pdfjoin_script = "pdfjoin"; ### my.pipeline_tar
my $pdfnup_script = "pdfnup"; ### my.pipeline_tar
my $senddropbox_script = "send_dropbox"; ### my.pipeline_tar
my $linksub_script = "my.linksub"; ### my.pipeline_tar
my $sb_script = "sb"; ### my.pipeline_tar
my $placeholder_script = "placeholder"; ### my.pipeline_tar
my $numbers_script = "my.numbers"; ### my.pipeline_tar
my $pdflatex_script = "pdflatex"; ### my.pipeline_tar
my $mystart_script = "my.start_job"; ### my.pipeline_tar
my $replicator_script = "replicator13"; ### my.pipeline_tar
my $replicmeta_script = "replicator_meta11"; ### my.pipeline_tar
my $damecat_script = "my.dameta_cat"; ### my.pipeline_tar
my $plot_or_reg_script = "plot_or_regressions"; ### my.pipeline_tar
my $mutt_script = "mail";
push @test_scripts, $pdflatex_script ;
push @test_scripts, $metaber_script ;
push @test_scripts, $daner_script ;
push @test_scripts, $danscore_result_script ;
push @test_scripts, $chunker_script ;
push @test_scripts, $danerhet2p_script ;
push @test_scripts, $topfilter_script ;
push @test_scripts, $areator_script ;
push @test_scripts, $areaplot_script ;
push @test_scripts, $forestplot_script ;
push @test_scripts, $manhattanplot_script ;
push @test_scripts, $manhattanplot2_script ;
push @test_scripts, $qqplot_script ;
push @test_scripts, $lahunt_script ;
push @test_scripts, $ldsc_script ;
push @test_scripts, $blueprint_script ;
#push @test_scripts, $clumpnavi_script ;
push @test_scripts, $clumpnavi2_script ;
push @test_scripts, $shrinkpdf_script ;
push @test_scripts, $comp1mhc_script ;
push @test_scripts, $damecat_script ;
#push @test_scripts, $comp1mhc1_script ;
push @test_scripts, $comp1mhcreg_script ;
push @test_scripts, $pdfjoin_script ;
push @test_scripts, $pdfnup_script ;
push @test_scripts, $senddropbox_script ;
push @test_scripts, $linksub_script ;
push @test_scripts, $sb_script ;
push @test_scripts, $placeholder_script ;
push @test_scripts, $numbers_script ;
push @test_scripts, $mystart_script;
$rp_header =~ s/MODULE/postimp_navi /;
print "$rp_header\n";
print ".......testing necessary binaries....\n" if ($debug);
my @miss_scripts;
#my $err_scr = 0;
foreach my $scr_name (@test_scripts) {
my $scr_path = '';
for my $path ( split /:/, $ENV{PATH} ) {
if ( -f "$path/$scr_name" && -x _ ) {
print "$scr_name\tfound in $path\n" if ($debug);
$scr_path = "$path/$scr_name";
last;
}
}
if ( $scr_path eq '') {
push @miss_scripts, "cp /home/unix/sripke/bin/$scr_name ./\n";
print "!!Error!! : No $scr_name command available\n" ;
}
}
#exit;
if (@miss_scripts > 0) {
if (-e "get_scripts_on_broad.txt") {
print "please remove this file and restart: get_scripts_on_broad.txt\n";
}
die $! unless open FILE1, "> get_scripts_on_broad.txt";
foreach (@miss_scripts) {
print FILE1 "$_";
}
close FILE1;
print "exiting now -> have a look at get_scripts_on_broad.txt\n";
exit;
}
print ".......testing email program....\n" if ($debug);
my $noti = 1;
my $err_scr = 0;
{
my $scr_path = '';
for my $path ( split /:/, $ENV{PATH} ) {
if ( -f "$path/$mutt_script" && -x _ ) {
print "$mutt_script\tfound in $path\n" if ($debug);
$scr_path = "$path/$mutt_script";
last;
}
}
unless ( $scr_path ) {
print "!!Warning!! : No $mutt_script command available, trying mutt\n" if ($debug);
$mutt_script = "mutt";
for my $path ( split /:/, $ENV{PATH} ) {
if ( -f "$path/$mutt_script" && -x _ ) {
print "$mutt_script\tfound in $path\n" if ($debug);
$scr_path = "$path/$mutt_script";
last;
}
}
unless ( $scr_path ) {
# $err_scr = 1;
print "!!Warning!! : No $mutt_script command available, no email notifications\n";
$noti = 0;
}
}
}
die if $err_scr == 1;
print "....all necessary binaries found....\n" if ($debug);
print "------------------------------------\n" if ($debug);
#push @scripts,"id_tager_3";
#####################################
# "testing environment variable rp_perlpackages
####################################
print "testing environment variable rp_perlpackages....\n" if ($debug);
unless (exists $ENV{rp_perlpackages}) {
print "Error: no environment variable for perl-packages, please re-install ricopili and make sure to follow all instructions\n";
print "------------------------------------\n";
exit;
}
print "....all set....\n" if ($debug);
print "------------------------------------\n" if ($debug);
my $nomega_sw = 1;
srand($rseed);
my $nomega = 0;
$nomega = 1 if ($nomega_sw);
$nomega = 1 if ($result_name);
my $machstr = "";
$machstr = "--mach" if ($mach_sw);
die $usage if $help;
die $usage unless $outname;
my $xdf_txt = "";
$xdf_txt = "--xdf" if ($xdf);
#my ($xsnp,$xchr,$xbeg,$xend);
#($xsnp,$xchr,$xbeg,$xend)= split ',', $xareastr if ($xareastr);
my %refiex;
if ($refiex_file) {
print "read $refiex_file...\n" if ($debug);
die $!." <$refiex_file>" unless open IN, "< $refiex_file";
while (my $line = <IN>){
chomp($line);
$refiex{$line} = 1;
# print "$line\n";
}
close IN;
print "...finished\n" if ($debug);
}
#my $impute_dir = "pi_sub";
#my $postimp_dir = "$impute_dir/postimp_data";
if ($trio) {
die "please use size (--s2gr) compatible for trios, keep in mind, size will be n*4" unless ($s2gr % 3 == 0 || $s2gr > 200);
}
sub fisher_yates_shuffle {
my $deck = shift; # $deck is a reference to an array
my $i = @$deck;
while ($i--) {
my $j = int rand ($i+1);
@$deck[$i,$j] = @$deck[$j,$i];
}
}
#####################################
# print array to file
####################################
sub a2file {
my ($file, @lines)=@_;
die $! unless open FILE, "> $file";
foreach (@lines){
print FILE $_;
}
close FILE;
}
###################################################
### system call with test if successfull
###################################################
sub mysystem(){
my ($systemstr)="@_";
system($systemstr);
my $status = ($? >> 8);
die "----\n->system call failed: $status\ncommand: $systemstr\n" if ($status != 0);
}
###################################################
### system call with test if successfull
###################################################
sub mysystem_nodie(){
my ($systemstr)="@_";
system($systemstr);
my $status = ($? >> 8);
print "----\n->Warning: system call problem: $status\ncommand: $systemstr\n" if ($status != 0);
}
##########################################
# subroutine to split a plink-output-line
##########################################
sub split_line {
my ($line)=@_;
chomp($line);
$line =~ s/^[\s]+//g;
my @cols= split /\s+/, $line;
}
##########################################
# subroutine to split a plink-output-line with references
##########################################
sub split_line_ref {
my ($line)=${$_[0]};
chomp($line);
$line =~ s/^[\s]+//g;
my @cols= split /\s+/, $line;
\@cols;
}
#####################################
# print array to file with newline
####################################
sub a2filenew {
my ($file, @lines)=@_;
die $! unless open FILE, "> $file";
foreach (@lines){
print FILE "$_\n";
}
close FILE;
}
#####################################
# append array to file with newline
####################################
sub a2filenew_app {
my ($file, @lines)=@_;
die "$!: $file" unless open FILE, ">> $file";
foreach (@lines){
print FILE "$_\n";
}
close FILE;
}
#####################################
# subroutine to count lines of a file
#####################################
sub count_lines {
my ($file)=@_;
my $lc=0;
die "$file: ".$! unless open FILE, "< $file";
while (<FILE>){
$lc++;
}
close FILE;
$lc;
}
#####################################
# subroutine to re-invoke this script
#####################################
#sub reinvo_b {
# my ($message, $wt_file)=@_;
# my $now = localtime time;
# my $old_cmd = `tail -3 $homedir/postimp_navi_35_test | head -1`;#
# my $message_part = $info_txt."\t$message";
# $message = $info_txt."\t$message\t$now";
# &a2filenew_app("$homedir/postimp_navi_35_test",$message);
# die "2 times already" if ($old_cmd =~ /$message_part/);
# chdir "$rootdir" or die "something strange";
# if ($qloc eq "bsub") {#
# $wt_file =~ s/.*blueprint_joblist_file-//;
# }
# my $sys_re = "blueprint --njob $job_bn_th -b \"$command_line\" --wa 4 --di -j --fwt $wt_file --na _if_$outname";
# print "$sys_re\n";
# &mysystem ($sys_re);
# exit;
#}
#####################################
# send jobs to cluster and also send navi again
#####################################
my $sjadir = "";
my $sjaweek = 0;
my $sjaname = "";
my $sjarow = "";
my @sjaarray;
my $sjamem = 0;
my $sjatime = -1;
my $sjamaxjobs = 30000;
#my $sjainfofile = "$homedir/impute_dir_info";
my $sjainfofile = "$loloc/postimp_navi_info";
unless (-e $sjainfofile) {
print "log-file ($sjainfofile) is not existing\n";
print "please check loloc in ~/ricopili.conf\n";
exit;
}
my $sjainfotxt = "";
my $sjamulti = 0;
sub send_jobarray {
die "send_jobarray with undefined variables, dir" if ($sjadir eq "");
die "send_jobarray with undefined variables, name" if ($sjaname eq "");
die "send_jobarray with undefined variables, array" if (@sjaarray == 0);
die "send_jobarray with undefined variables, mem" if ($sjamem == 0);
die "send_jobarray with undefined variables, time" if ($sjatime < 0);
die "send_jobarray with undefined variables, info" if ($sjainfotxt eq "");
print "Running job: $sjaname\n";
my $now = localtime time;
$now =~ s/ /_/g;
if ($sjaname eq "finished") {
my $fini_message ;
$fini_message .= "\n\n##################################################################\n";
$fini_message .= "##### CONGRATULATIONS: \n";
$fini_message .= "##### rp_pipeline_postimp finished successfully:\n";
$fini_message .= "##### $sjainfotxt\n";
$fini_message .= "##### have a look at the distributions subdir for output files\n";
$fini_message .= "##### have a look at the wiki page for more details\n";
$fini_message .= "##### https://sites.google.com/a/broadinstitute.org/ricopili/\n";
$fini_message .= "##################################################################\n";
print "$fini_message\n";
die $! unless open SUC, "> success_file";
print SUC $fini_message."\n";
close SUC;
if ($noti == 1) {
my $sys_email = 'cat success_file | '.$mutt_script.' -s RP_postimp_finished '.$email;
print "$sys_email\n";
&mysystem ($sys_email) ;
}
my $sjarow = $sjainfotxt."\t$sjaname\t$now";
&a2filenew_app("$sjainfofile",$sjarow);
exit;
}
if ($sjaname eq "paused") {
my $fini_message ;
$fini_message .= "\n\n##################################################################\n";
$fini_message .= "##### rp_pipeline_postimp paused\n";
$fini_message .= "##### $sjainfotxt\n";
$fini_message .= "##### please read and follow instructions above then restart\n";
$fini_message .= "##### have a look at the wiki page for more details\n";
$fini_message .= "##### https://sites.google.com/a/broadinstitute.org/ricopili/\n";
$fini_message .= "##################################################################\n";
print "$fini_message\n";
die $! unless open SUC, "> success_file";
print SUC $fini_message."\n";
close SUC;
if ($noti == 1) {
my $sys_email = 'cat success_file | '.$mutt_script.' -s RP_postimp_paused '.$email;
print "$sys_email\n";
&mysystem ($sys_email) ;
}
my $sjarow = $sjainfotxt."\t$sjaname\t$now";
&a2filenew_app("$sjainfofile",$sjarow);
exit;
}
chdir ($sjadir);
my $jobfile = "$sjaname.job_list";
while (-e $jobfile) {
$jobfile .= ".s";
}
&a2filenew ($jobfile, @sjaarray);
# print "$jobfile\n";
# print "sleep\n";
# sleep(10);
$walltime = $sjatime;
my $nsja = @sjaarray;
my $nsja_loc = $nsja;
if ($nsja_loc > 30000) {
$nsja_loc = 30000;
}
my $multi_txt = "";
if ($sjamulti > 0) {
$multi_txt = "--multi $nsja_loc,$sjamulti";