-
Notifications
You must be signed in to change notification settings - Fork 7
/
CSBB-v3.0_Linux.pl
2102 lines (2046 loc) · 84.5 KB
/
CSBB-v3.0_Linux.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
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/perl
use Capture::Tiny ':all';
use English qw' -no_match_vars ';
print "\nOperating System is $OSNAME\n";
##### Computational Suite For Bioinformaticians and Biologists ########
print "\n\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\n";
print "\nCSBB \- Computational Suite For Bioinformaticians and Biologists\n";
print "\n\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\n";
print "\nVersion\_3.0\n";
print "\nDeveloped and maintained by Praneet Chaturvedi\!\!\n";
print "\nPlease report issues and bugs on https://github.com/csbbcompbio/CSBB-v3.0\n";
################# TIME STAMP START ##################
my @timestamp;
open(TS,"TimeStamp_CSBB-v3.0.txt");
while(my $data = <TS>)
{
chomp $data;
push(@timestamp,$data);
}
close TS;
my $lastruncsbb=pop(@timestamp);
if($lastruncsbb eq "")
{
my $timestamp_first = localtime(time);
print "\nCSBB-v3.0 First run on $timestamp_first\n";
}
else
{
print "\nCSBB-v3.0 Last run \: $lastruncsbb\n";
}
open(TS,">>TimeStamp_CSBB-v3.0.txt");
my $timestamp = localtime(time);
print "\nCurrent Run: $timestamp\n";
print TS "$timestamp\n";
close TS;
################# TIME STAMP END ##################
################ Log Directory ###################
use Cwd;
my $cwd = getcwd;
my $log_dir=$cwd."\/".'CSBB-v3.0_Logs';
if(-d $log_dir)
{
print "\n$log_dir directory is already present\, CSBB will use the same to write module logs\n";
sleep(1);
}
else
{
mkdir($log_dir);
print "\n$log_dir directory is created\, CSBB will use this directory to write module logs\n";
sleep(1);
}
############### Log Directory End ###############
###Asking user input###
my $user_input=$ARGV[0]; chomp $user_input; ###user input through command line ##
#######################################################################
#######################################################################
############ CALLING MODULES BASED ON USER INPUT ###########
if(($user_input eq "--install")||($user_input eq "install"))
{
&install;
}
if(($user_input eq "--help")||($user_input eq "help"))
{
&help;
}
if(($user_input eq "UpperQuantile")||($user_input eq "--UpperQuantile")||($user_input eq "UQ"))
{
my $file=$ARGV[1];
&upperquantile($file);
}
if(($user_input eq "ExpressionToZscore")||($user_input eq "--ExpressionToZscore")||($user_input eq "E2Z"))
{
my $file=$ARGV[1];
&expressiontozscore($file);
}
if(($user_input eq "BasicStats")||($user_input eq "--BasicStats")||($user_input eq "BS"))
{
my $file=$ARGV[1];
&basicstats($file);
}
if(($user_input eq "ExtractGeneInfo")||($user_input eq "--ExtractGeneInfo")||($user_input eq "EGI"))
{
my $file=$ARGV[1];
my $file1=$ARGV[2];
&extractgeneinfo($file,$file1);
}
if(($user_input eq "ExpressionPlot")||($user_input eq "--ExpressionPlot")||($user_input eq "EP"))
{
my $file=$ARGV[1];
&expressionplot($file);
}
if(($user_input eq "InteractiveHeatmap")||($user_input eq "--InteractiveHeatmap")||($user_input eq "IH"))
{
my $file=$ARGV[1];
my $clustering_type=$ARGV[2];
my $color_theme=$ARGV[3];
&interactiveheatmap($file,$clustering_type,$color_theme);
}
if(($user_input eq "CorrelationProfiles")||($user_input eq "--CorrelationProfiles")||($user_input eq "CP"))
{
my $file=$ARGV[1];
my $threshold=$ARGV[2];
my $genesofinterest=$ARGV[3];
my $typeOfCorr=$ARGV[4];
&correlationprofile($file,$threshold,$genesofinterest,$typeOfCorr);
}
if(($user_input eq "Biogrid-Gene-Protein-Search")||($user_input eq "--Biogrid-Gene-Protein-Search")||($user_input eq "Biogrid"))
{
my $organism=$ARGV[1];
my $file=$ARGV[2];
&biogrid($organism,$file);
}
if(($user_input eq "DifferentialExpression")||($user_input eq "--DifferentialExpression")||($user_input eq "DE"))
{
my $file=$ARGV[1];
my $numbercontrol=$ARGV[2];
my $numbertreatment=$ARGV[3];
my $countsthreshold=$ARGV[4];
my $numbersamples=$ARGV[5];
my $typeOfNormalization=$ARGV[6];
&de($file,$numbercontrol,$numbertreatment,$countsthreshold,$numbersamples,$typeOfNormalization);
}
if(($user_input eq "PCA")||($user_input eq "--PCA"))
{
my $file=$ARGV[1];
&pca($file);
}
if(($user_input eq "NMF")||($user_input eq "--NMF"))
{
my $file=$ARGV[1];
&nmf($file);
}
if(($user_input eq "ProcessPublicData")||($user_input eq "--ProcessPublicData"))
{
my $file=$ARGV[1];
my $path=$ARGV[2];
&ProcessPublic($file,$path);
}
if(($user_input eq "InteractiveScatterPlot")||($user_input eq "--InteractiveScatterPlot")||($user_input eq "IPS"))
{
$file=$ARGV[1];
$colx=$ARGV[2];
$coly=$ARGV[3];
$colenrichment=$ARGV[4];
&interactivesp($file,$colx,$coly,$colenrichment);
}
if(($user_input eq "Process-RNASeq_SingleEnd")||($user_input eq "--Process-RNASeq_SingleEnd")||($user_input eq "RNASeq-Single"))
{
my $file=$ARGV[1]; ####### Fastq File
my $species=$ARGV[2]; ########### Works for human, mouse, frog and zebrafish
my $Output_folder_name=$ARGV[3]; ######## Output folder name
my $phred_qual=$ARGV[4]; #### Phred quality 33 or 64 [[[[ 33 if Ilumina encoding 1.8+ and rest 64]
&ProcessRNASeqSingle($file,$species,$Output_folder_name,$phred_qual);
}
if(($user_input eq "Process-RNASeq_PairedEnd")||($user_input eq "--Process-RNASeq_PairedEnd")||($user_input eq "RNASeq-Paired"))
{
my $file1=$ARGV[1]; ####### Fastq File pair 1
my $file2=$ARGV[2]; ####### Fastq File pair 2
my $species=$ARGV[3]; ########### Works for human, mouse, frog and zebrafish
my $Output_folder_name=$ARGV[4]; ######## Output folder name
my $phred_qual=$ARGV[5]; #### Phred quality 33 or 64 [[[[ 33 if Ilumina encoding 1.8+ and rest 64]
&ProcessRNASeqPaired($file1,$file2,$species,$Output_folder_name,$phred_qual);
}
if(($user_input eq "Process-ChIP-ATAC_SingleEnd")||($user_input eq "--Process-ChIP-ATAC_SingleEnd")||($user_input eq "ChIP-ATAC-Single"))
{
my $file=$ARGV[1]; ####### Fastq File
my $species=$ARGV[2]; ########### Works for human, mouse, frog and zebrafish
my $Output_folder_name=$ARGV[3]; ######## Output folder name
my $phred_qual=$ARGV[4]; #### Phred quality 33 or 64 [[[[ 33 if Ilumina encoding 1.8+ and rest 64]
my $exp_type=$ARGV[5]; #### Experiment type : ATAC, CHIP-TF or CHIP-EPIGENETIC
&ProcessChIPATACSingleEnd($file,$species,$Output_folder_name,$phred_qual,$exp_type);
}
if(($user_input eq "Process-ChIP-ATAC_PairedEnd")||($user_input eq "--Process-ChIP-ATAC_PairedEnd")||($user_input eq "ChIP-ATAC-Paired"))
{
my $file1=$ARGV[1]; ####### Fastq File pair 1
my $file2=$ARGV[2]; ####### Fastq File pair 2
my $species=$ARGV[3]; ########### Works for human, mouse, frog and zebrafish
my $Output_folder_name=$ARGV[4]; ######## Output folder name
my $phred_qual=$ARGV[5]; #### Phred quality 33 or 64 [[[[ 33 if Ilumina encoding 1.8+ and rest 64]
my $exp_type=$ARGV[6]; #### Experiment type : ATAC, CHIP-TF or CHIP-EPIGENETIC
&ProcessChIPATACPairedEnd($file1,$file2,$species,$Output_folder_name,$phred_qual,$exp_type);
}
if(($user_input eq "Generate-TPM-Counts-Matrix")||($user_input eq "--Generate-TPM-Counts-Matrix")||($user_input eq "GenerateMatrix"))
{
my $RSEM_res_dir=$ARGV[1];
my $Species=$ARGV[2];
my $output_dir=$ARGV[3];
&GenerateTPMCounts($RSEM_res_dir,$Species,$output_dir);
}
if($user_input eq "")
{
sleep(1);
&help;
}
if($user_input eq "Citation")
{
&cite;
}
#########################################################################
#########################################################################
##### MODULES CODE DOWN HERE ##########
##################### HELP MODULE ####################
sub help
{
print "\nPlease See README and White-Paper for getting detailed instructions on running CSBB-v3.0\n";
print "\n\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\=\n";
print "\n Please See \: Please run install module if using CSBB\-v3\.0 for first time \[just one time process\] \n";
sleep(2);
print "\nPlease use options below to run CSBB \- Computational Suite For Bioinformaticians and Biologists\n";
print "\nOptions\:\:\n";
print "\nCitation \-\-\-\> for citing CSBB please use url : https://github.com/csbbcompbio/CSBB-v3.0\n\n";
print "\ninstall \-\-\-\> for installing all the required dependencies for Pipelines \:\:only one time process\n\n";
print "\nUpperQuantile \-\-\-\> for performing upper quantile normalization\n\n";
print "\nBasicStats \-\-\-\> for obtaining stats like mean\, median\, standard deviation\, variance\, Sum\, min and max for each Gene Expression profile\n\n";
print "\nExpressionToZscore \-\-\-\> for obtaining z-scores for Gene Expression in samples\n\n";
print "\nExtractGeneInfo \-\-\-\> for obtaining info\/expression of list genes from a huge matrix gene info\/expression\n\n";
print "\nExpressionPlot \-\-\-\> for generating line plot visualizing expression\/information of genes\/entities across samples\/objects\n\n";
print "\nInteractiveHeatmap \-\-\-\> for generating interactive heatmaps for expression data\. User has three options on clustering type and four choices on color theme\. Please read README for descriptions and run command\.\n\n";
print "\nCorrelationProfiles \-\-\-\> for obtaining genes correlation profile termed as positively and negatively correlated based on User threshold\. One can obtain profile for all genes or just genes of interest \(For genes of interest user needs to provide the path to gene list file\)\. Heatmap will only be displayed for genes of interest\n\n";
print "\nBiogrid\-Gene\-Protein\-Search \-\-\-\> for obtaining gene\-protein interactions for Human and Mouse for genes of interest\n\n";
print "\nDifferentialExpression \-\-\-\> for obtaining DE genes in RNA-SEQ expriments\. Uses RUVSeq package in R\n\n";
print "\nPCA \-\-\-\> for performing Principal Component Analysis\n";
print "\nNMF \-\-\-\> for performing Nonnegative Matrix Factorization on Samples in Expression dataset\n";
print "\nProcessPublicData \-\-\-\> for processing public data \[Includes downloading .sra files from SRA, mapping to reference genome and running processing pipelines based on Assay Type for human, mouse, frog and zebrafish\]\n";
print "\nInteractiveScatterPlot \-\-\-\> for generating Interactive Scatter plot based on user preference\. User needs to provide path to the file\, Column number for x\-axis values\, Column number for y\-axis values and Column number which user needs for color factorization \(If users provides No color factorization will not be done\) Please see README for extensive explanation\n";
print "\nProcess\-RNASeq\_SingleEnd \-\-\-\> for processing Single End RNASeq data using RSEM for human, mouse, frog and zebrafish\n";
print "\nProcess\-RNASeq\_PairedEnd \-\-\-\> for processing Paired End RNASeq data using RSEM for human, mouse, frog and zebrafish\n";
print "\nGenerate-TPM-Counts-Matrix \-\-\-\> for generating TPM and Counts Matrix for Both Isoforms and Genes using CSBB RNA-seq result directory and species of interest\n";
print "\nProcess-ChIP-ATAC_SingleEnd \-\-\-\> for processing Single End ChIP and ATAC Seq data for human, mouse and frog\n";
print "\nProcess-ChIP-ATAC_PairedEnd \-\-\-\> for processing Paired End ChIP and ATAC Seq data for human, mouse and frog\n";
}
##################### MODULE END #####################
##################### Log Module Start #####################
sub logCSBB
{
my $stdout=@_[0];chomp $stdout; my $stderr=@_[1]; chomp $stderr; my $exit=@_[2]; chomp $exit; my $module_name=@_[3]; chomp $module_name;
my $outfile1="CSBB"."\_".$module_name."\_"."LOG"; my $outfile2="CSBB"."\_".$module_name."\_"."ERROR"; my $outfile3="CSBB"."\_".$module_name."\_"."EXIT-STATUS";
open(LOG,">>CSBB-v3.0_Logs/$outfile1.txt"); open(ERROR,">>CSBB-v3.0_Logs/$outfile2.txt"); open(EXIT,">>CSBB-v3.0_Logs/$outfile3.txt");
print LOG "$stdout\n"; print ERROR "$stderr\n"; print EXIT "$exit\n";
close LOG; close ERROR; close EXIT;
}
##################### MODULE END #####################
#################### MODULE CITATION #################
sub cite
{
print "Please CITE CSBB using following url : https://github.com/csbbcompbio/CSBB-v3.0\n";
}
##################### MODULE END #####################
#################### Install MODULE ##################
sub install
{
use Cwd;
my $cwd = getcwd;
print "\nInstalling Required dependencies on your system \.\.\. Please allow access to CSBB when prompted \.\. This is one time installation\n";
sleep(0.5);
print "\nPlease Provide your Linux OS type \:\: Ubuntu or Redhat\n";
my $takeOS=<stdin>; chomp $takeOS;
if($takeOS eq "Ubuntu")
{
my $scripttoinstall=$cwd."\/"."Modules"."\/"."getbrew_Linux.pl";
my $dirto_install=$cwd."\/"."Modules";
system("perl","$scripttoinstall","$dirto_install") ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
print "\nRequired modules successfully insatlled\n";
}
if($takeOS eq "Redhat")
{
my $scripttoinstall=$cwd."\/"."Modules"."\/"."getbrew_Linux_Redhat.pl";
my $dirto_install=$cwd."\/"."Modules";
system("perl","$scripttoinstall","$dirto_install") ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
print "\nRequired modules successfully insatlled\n";
}
}
##################### MODULE END #####################
#################### UPPER QUANTILE MODULE ##################
sub upperquantile
{
use Cwd;
my $cwd = getcwd;
print "\nUpper Quantile Normalization module loaded\n";
my $file=@_[0];chomp $file;
if($file eq "")
{
print "\nPlease provide the path to the file \.\. You can drag and drop the file from finder window \.\. Please remove space at the end and quotes\n";
$file=<stdin>;chomp $file;
}
my $start_time=time();
my $header;my $path;
my $counter=0;
my $counter1=0;
open(F,$file);
while(my $data = <F>)
{
$data =~ s/^\s+|\s+$//g;
chomp $data;
$counter++;
if($counter==1)
{
$header=$data;
}
}
close F;
print "\nStored Header Info\n";
print "\nRunning R in Background \(please be patient\)\.\.\.\.\.\n";
my @filepath=split(/\//,$file);
my $filename=pop(@filepath);
foreach my $m(@filepath)
{
if($m eq "")
{}
else
{
$path=$path."\/".$m;
}
}
my $dirtoR=$cwd."\/"."Modules"."\/"."Uquantile_normalization.r";
print "\nPerforming Upper Quantile Normalization\n";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR,$path,$filename) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nR Run complete \.\.\. Now writing header with perl\n";
my $Rfile = $path."\/"."temporaryfile"."\."."txt";
my $outfile = "Quantile"."\_"."Normalized"."\_".$filename;
open(OUT,">$path/$outfile");
my $newhead=$header;
print OUT "$header\n";
open(F,"$Rfile");
while(my $data = <F>)
{
$data =~ s/^\s+|\s+$//g;
chomp $data;
$counter1++;
if($counter1==1)
{}
else
{
print OUT "$data\n";
}
}
close F;
close OUT;
unlink $Rfile;
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds \.\.\.\n";
print "\nPlease see file $outfile for results in $path\n";
}
############################ MODULE END ############################
########################### EXPRESSIONTOZSCORE MODULE ##################
sub expressiontozscore
{
print "\nExpressionToZscore module loaded\n";
use Cwd;
my $cwd = getcwd;
my $file=@_[0];chomp $file;
if($file eq "")
{
print "\nPlease provide the path to the file \.\. You can drag and drop the file from finder window \.\. Please remove space at the end and quotes\n";
$file=<stdin>;chomp $file;
}
my $start_time=time();
my $header;my $path;
my $counter=0;
my $counter1=0;
open(F,$file);
while(my $data = <F>)
{
$data =~ s/^\s+|\s+$//g;
chomp $data;
$counter++;
if($counter==1)
{
$header=$data;
}
}
close F;
print "\nStored Header Info\n";
print "\nRunning R in Background \(please be patient\)\.\.\.\.\.\n";
my @filepath=split(/\//,$file);
my $filename=pop(@filepath);
foreach my $m(@filepath)
{
if($m eq "")
{}
else
{
$path=$path."\/".$m;
}
}
my $dirtoR=$cwd."\/"."Modules"."\/"."Zscore_Calculator.r";
print "\nPerforming Zscore Normalization\n";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR,$path,$filename) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nR Run complete \.\.\. Now writing header with perl\n";
my $Rfile = $path."\/"."temporaryfile"."\."."txt";
my $outfile = "Zscores"."\_".$filename;
open(OUT,">$path/$outfile");
my $newhead=$header;
print OUT "$header\n";
open(F,"$Rfile");
while(my $data = <F>)
{
$data =~ s/^\s+|\s+$//g;
chomp $data;
$counter1++;
if($counter1==1)
{}
else
{
print OUT "$data\n";
}
}
close F;
close OUT;
unlink $Rfile;
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds \.\.\.\n";
print "\nPlease see file $outfile for results in $path\n";
}
################################## MODULE END #############################
################################# BASICSTATS MODULE ########################
sub basicstats
{
print "\nBasicStats module loaded\n";
use Cwd;
my $cwd = getcwd;
my $file=@_[0];chomp $file;
if($file eq "")
{
print "\nPlease provide the path to the file \.\. You can drag and drop the file from finder window \.\. Please remove space at the end and quotes\n";
$file=<stdin>;chomp $file;
}
my $start_time=time();
my $path;
my $counter1=0;
print "\nRunning R in Background \(please be patient\)\.\.\.\.\.\n";
my @filepath=split(/\//,$file);
my $filename=pop(@filepath);
foreach my $m(@filepath)
{
if($m eq "")
{}
else
{
$path=$path."\/".$m;
}
}
my $dirtoR=$cwd."\/"."Modules"."\/"."BasicStats.r";
print "\nCalculating Basic Stats for all entities in the $file\n";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR,$path,$filename) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nR Run complete \.\.\. Now writing header with perl\n";
my $Rfile = $path."\/"."temporaryfile"."\."."txt";
my $outfile = "BasicStats"."\_".$filename;
open(OUT,">$path/$outfile");
print OUT "Gene\tMean\tMedian\tMedian Adjusted Deviation\tStandard Deviation\tVariance\tMinimum\tMaximum\tSum\n";
open(F,"$Rfile");
while(my $data = <F>)
{
$data =~ s/^\s+|\s+$//g;
chomp $data;
$counter1++;
if($counter1==1)
{}
else
{
print OUT "$data\n";
}
}
close F;
close OUT;
unlink $Rfile;
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds \.\.\.\n";
print "\nPlease see file $outfile for results in $path\n";
}
###################################### MODULE END ################################
############################### EXTRACTGENEINFO MODULE ##########################
sub extractgeneinfo
{
use Cwd;
my $cwd = getcwd;
print "\nExtractGeneInfo module loaded\n";
my $file1=@_[0];chomp $file1;
my $file2=@_[1];chomp $file2;
if($file1 eq "")
{
print "\nPlease provide the path to the Expression\/Info file \.\. You can drag and drop the file from finder window \.\. Please remove space at the end and quotes\n";
$file1=<stdin>;chomp $file1;
}
if($file2 eq "")
{
print "\nPlease provide the path to the Gene List file \.\. Please use header in the file CSBB assumes first line as header\.\. You can drag and drop the file from finder window \.\. Please remove space at the end and quotes\n";
$file2=<stdin>;chomp $file2;
}
my $start_time=time();
print "\nRunning Extract Gene Info Module\n";
my $dirtoperl=$cwd."\/"."Modules"."\/"."extract_gene_info.pl";
($stdout, $stderr, $exit) = capture {
system("perl","$dirtoperl","$file1","$file2") ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds \.\.\.\n";
print "\nPlease see file $outfile for results\n";
}
##################################### MODULE END ##################################
##################################### MODULE EXPRESSION PLOT START ###########################
sub expressionplot
{
print "\nExpressionPlot Module loaded\n";
use Cwd;
my $cwd = getcwd;
my $file=@_[0];chomp $file;
if($file eq "")
{
print "\nPlease provide the path to the file \.\. You can drag and drop the file from finder window \.\. Please remove space at the end and quotes\n";
$file=<stdin>;chomp $file;
}
my $start_time=time();
my $path;
my @filepath=split(/\//,$file);
my $filename=pop(@filepath);
foreach my $m(@filepath)
{
if($m eq "")
{}
else
{
$path=$path."\/".$m;
}
}
my $dirtoR=$cwd."\/"."Modules"."\/"."Line_Graph.r";
print "\nGenerating Expression Plots\n";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR,$path,$filename) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nR Run Complete\n";
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds\n";
print "\nExpression plot is generated and is saved in $path\n";
}
######################################### MODULE END ###############################
#################################### INTERACTIVE HEATMAP MODULE ###################
sub interactiveheatmap
{
print "\nInteractive Heatmap module loaded\n";
use Cwd;
my $cwd = getcwd;
my $file=@_[0];chomp $file;my $clustering_type=@_[1];chomp $clustering_type;my $color_theme=@_[2];chomp $color_theme;
if($file eq "")
{
print "\nPlease provide the path to the Expression file \.\. You can drag and drop the file from finder window \.\. Please remove space at the end and quotes\n";
$file=<stdin>;chomp $file;
}
if($clustering_type eq "")
{
print "\nPlease provide Clustering type\. Options are 1\. Row\_Clust for only row clustering 2\. Col\_Clust for Column CLustering 3\. Row\_Col\_Clust for both way clustering\n";
$clustering_type=<stdin>;chomp $clustering_type;
}
if($color_theme eq "")
{
print "\nPlease provide Color theme\. Options are 1\. YellowGreenOrange 2\. BlueWhiteRed 3\. YellowBlackBlue 4\. GreenWhitePurple\n";
$color_theme=<stdin>;chomp $color_theme;
}
my $start_time=time();
my $path;
my @filepath=split(/\//,$file);
my $filename=pop(@filepath);
foreach my $m(@filepath)
{
if($m eq "")
{}
else
{
$path=$path."\/".$m;
}
}
print "\nRunning R in Background\n";
print "\n$file\n";
if($clustering_type eq "Row_Clust")
{
print "runing\n";
my $dirtoR=$cwd."\/"."Modules"."\/"."Row_Clust.r";
print "\nRunning Interactive Heatmap Module with Row Clust and $color_theme color theme\n";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR,$path,$filename,$color_theme) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nR Run Complete\n";
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds\n";
print "\nBoth Interactive and Static Heatmaps are saved in the folder $path\n";
}
if($clustering_type eq "Col_Clust")
{
my $dirtoR=$cwd."\/"."Modules"."\/"."Col_Clust.r";
print "\nRunning Interactive Heatmap Module with Col Clust and $color_theme color theme\n";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR,$path,$filename,$color_theme) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nR Run Complete\n";
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds\n";
print "\nBoth Interactive and Static Heatmaps are saved in the folder $path\n";
}
if($clustering_type eq "Row_Col_Clust")
{
my $dirtoR=$cwd."\/"."Modules"."\/"."Row_Col_Clust.r";
print "\nRunning Interactive Heatmap Module with Row-Col Clust and $color_theme color theme\n";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR,$path,$filename,$color_theme) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nR Run Complete\n";
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds\n";
print "\nBoth Interactive and Static Heatmaps are saved in the folder $path\n";
}
}
############################# MODULE END ######################################
############################# CORRELATION PROFILES ############################
sub correlationprofile
{
print "\nCorrelationProfiles module loaded\n";
use Cwd;
my $cwd = getcwd;
my $file=@_[0];my $threshold=@_[1];my $genesofinterest=@_[2];chomp $file;chomp $threshold;chomp $genesofinterest;my $negativethreshold=-1*$threshold; my $typeOfCorr=@_[3]; chomp ;$typeOfCorr;
if($file eq "")
{
print "\nPlease provide the path to the Gene Expression file \.\. You can drag and drop the file from finder window \.\. Please remove space at the end and quotes\n";
$file = <stdin>;chomp $file;
}
if($threshold eq "")
{
print "\nPlease provide correlation threshold \.\. Threshold Range is -1 to 1\n";
$threshold = <stdin>;chomp $threshold;
}
if($genesofinterest eq "")
{
print "\nPlease provide genes of interest\. Options are all or Path to gene list file \.\. You can drag and drop from finder window \.\. Please remove space at the end\n";
$genesofinterest = <stdin>;chomp $genesofinterest;
}
if($typeOfCorr eq "")
{
print "\nPlease provide Correlation type\. Options are pearson or spearman or kendall\n";
$typeOfCorr = <stdin>;chomp $typeOfCorr;
}
my $start_time=time();
my $path;
my @filepath=split(/\//,$file);
my $filename=pop(@filepath);
foreach my $m(@filepath)
{
if($m eq "")
{}
else
{
$path=$path."\/".$m;
}
}
if($genesofinterest eq "all")
{
print "\nRunning R in background to perform correlations \.\.\. please be patient\.\.\.\n";
my $dirtoR=$cwd."\/"."Modules"."\/"."Correlation_for_Matrix.r";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR,$path,$filename,$typeOfCorr) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nR Run complete \.\.\. Now writing header with perl\n";
my $Rfile = $path."\/"."temporaryfile"."\."."txt";
my $counter=0;my $header;my $counter1=0;
open(F,"$Rfile");
while(my $data = <F>)
{
chomp $data;
$counter++;
if($counter==1)
{
$header=$data;
}
}
close F;
my $mainhead="Entity"."\t".$header;
my $correlation_file_R=$path."\/"."Correlation"."\_"."Profiles"."\_".$filename;
open(OUT,">$correlation_file_R");
open(F,"$Rfile");
print OUT "$mainhead\n";
while(my $data = <F>)
{
chomp $data;
$counter1++;
if($counter1==1)
{}
else
{
print OUT "$data\n";
}
}
close OUT;
close F;
unlink $Rfile;
print "\nCorrelation Profiles outputted\.\. Now obtaining positive and negative correlated entities\n";
my $dirtoperl=$cwd."\/"."Modules"."\/"."obtain_positive_negative_correlation_set.pl";
($stdout, $stderr, $exit) = capture {
system("perl","$dirtoperl","$path","$filename","$correlation_file_R","$threshold") ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nPositive and Negative correlation profiles obtained\n";
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds\n";
print "\nCorrelation Profiles results are saved in $path\n";
}
if($genesofinterest =~/.txt/)
{
&extractgeneinfo($file,$genesofinterest);
my @filepath_new=split(/\//,$genesofinterest);
my $filename_new=pop(@filepath_new);
my $path_new;
foreach my $m(@filepath_new)
{
if($m eq "")
{}
else
{
$path_new=$path_new."\/".$m;
}
}
my $extractinfo_result="Expression"."\_".$filename_new;
my $temp=$path_new."\/".$extractinfo_result;
print "\nRunning R in background to perform correlations \.\.\. please be patient\.\.\.\n";
my $dirtoR=$cwd."\/"."Modules"."\/"."Correlation_for_Matrix.r";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR,$path_new,$extractinfo_result,$typeOfCorr) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
unlink $temp;
print "\nR Run complete \.\.\. Now writing header with perl\n";
my $Rfile = $path_new."\/"."temporaryfile"."\."."txt";
my $counter=0;my $header;my $counter1=0;
open(F,"$Rfile");
while(my $data = <F>)
{
chomp $data;
$counter++;
if($counter==1)
{
$header=$data;
}
}
close F;
my $mainhead="Entity"."\t".$header;
my $correlation_file_R=$path."\/"."Correlation"."\_"."Profiles"."\_".$filename_new;
open(OUT,">$correlation_file_R");
open(F,"$Rfile");
print OUT "$mainhead\n";
while(my $data = <F>)
{
chomp $data;
$counter1++;
if($counter1==1)
{}
else
{
print OUT "$data\n";
}
}
close OUT;
close F;
unlink $Rfile;
my $dirtoR1=$cwd."\/"."Modules"."\/"."Row_Col_Clust_Correlation_input.r";
print "\nInteractive Heatmap Module loaded\n";
print "\nRunning R for generating heatmap using Correlation values\n";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR1,$path_new,$correlation_file_R) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nR run complete \.\.\.\. Heatmap generated now finding positively and negatively correlated entity sets using perl\n";
my $dirtoperl=$cwd."\/"."Modules"."\/"."obtain_positive_negative_correlation_set.pl";
($stdout, $stderr, $exit) = capture {
system("perl","$dirtoperl","$path_new","$filename_new","$correlation_file_R","$threshold") ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds\n";
print "\nCorrelation Profiles files are saved in $path_new\n";
}
}
####################################### MODULE END ####################################
###################################### BIOGRID MODULE START ##########################
sub biogrid
{
print "\nBiogrid\-Gene\-Protein\-Search Module loaded\n";
use Cwd;
my $cwd = getcwd;
my $organism=@_[0];chomp $organism;my $file=@_[1]; chomp $file;
if($organism eq "")
{
print "\nPlease provide Oraganism of interest\.Options are 1\. Human 2\. Mouse\n";
$organism=<stdin>;chomp $organism;
}
if($file eq "")
{
print "\nPlease provide the path to the Gene list file \.\. You can drag and drop the file from finder window \.\. Please remove space at the end and quotes\n";
$file=<stdin>;chomp $file;
}
my $start_time=time();
my $path;
my @filepath=split(/\//,$file);
my $filename=pop(@filepath);
foreach my $m(@filepath)
{
if($m eq "")
{}
else
{
$path=$path."\/".$m;
}
}
if($organism eq "Human")
{
my $dirtoperl=$cwd."\/"."Modules"."\/"."Biogrid_ppi_Human.pl";
print "\nRunning BioGrid PPI extraction module\n";
($stdout, $stderr, $exit) = capture {
system("perl","$dirtoperl","$path","$filename") ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds\n";
print "\nGene Protein interaction results are saved in $path\n";
}
if($organism eq "Mouse")
{
my $dirtoperl=$cwd."\/"."Modules"."\/"."Biogrid_ppi_Mouse.pl";
print "\nRunning BioGrid PPI extraction module\n";
($stdout, $stderr, $exit) = capture {
system("perl","$dirtoperl","$path","$filename") ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds\n";
print "\nGene Protein interaction results are saved in $path\n";
}
}
################################### MODULE END ##########################
################################## DIFFERENTIAL EXPRESSION MODULE ###############
sub de
{
print "\nDifferentialExpression Module loaded\n";
use Cwd;
my $cwd = getcwd;
my $file=@_[0];my $numbercontrol=@_[1];my $numbertreatment=@_[2];my $countsthreshold=@_[3];my $numbersamples=@_[4];my $typeOfNorm=@_[5];
chomp $file;chomp $numbercontrol;chomp $numbertreatment;chomp $countsthreshold;chomp $numbersamples;
if($file eq "")
{
print "\nPlease provide the path to the Counts file \.\. Please place the all control samples before all treatment samples \.\. You can drag and drop the file from finder window \.\. Please remove space at the end and quotes\n";
$file=<stdin>;chomp $file;
}
if($numbercontrol eq "")
{
print "\nPlease provide the Number of Control Samples\n";
$numbercontrol=<stdin>;chomp $numbercontrol;
}
if($numbertreatment eq "")
{
print "\nPlease provide the Number of Treatment Samples\n";
$numbertreatment=<stdin>;chomp $numbertreatment;
}
if($countsthreshold eq "")
{
print "\nPlease provide the Counts threshold \n";
$countsthreshold=<stdin>;chomp $countsthreshold;
}
if($numbersamples eq "")
{
print "\nPlease provide the number of samples you want to apply counts filtering\n";
$numbersamples=<stdin>;chomp $numbersamples;
}
if($typeOfNorm eq "")
{
print "\nPlease provide the Type of Normalization you want to apply options : 1) UpperQuantile 2) UpperQuantile+Empirical \[\[ PLEASE SEE \:\:\: Normalization type is based on sequencing data quality\]\]\]\n";
$typeOfNorm=<stdin>;chomp $typeOfNorm;
}
if($typeOfNorm eq "UpperQuantile")
{
my $start_time=time();
my $path;
my @filepath=split(/\//,$file);
my $filename=pop(@filepath);
foreach my $m(@filepath)
{
if($m eq "")
{}
else
{
$path=$path."\/".$m;
}
}
my $dirtoR=$cwd."\/"."Modules"."\/"."RUVseq.r";
print "\nRunning R in background to perform DE using RUVSeq \[Normalization \: UpperQuantile\] \.\.\. \(please be patient\)\n";
($stdout, $stderr, $exit) = capture {
system(sudo,Rscript,$dirtoR,$path,$filename,$numbercontrol,$numbertreatment,$countsthreshold,$numbersamples) ==0 or die "\nExcecution Stopped because of errors \.\.\. Contact Praneet Chaturvedi for bugs and issues on github\n";
};
&logCSBB($stdout,$stderr,$exit,$user_input);
print "\nR Run complete \.\.\. Now writing header with perl\n";
my $Rfile = $path."\/"."temporaryfile"."\."."txt";
my $outfile = "DE_Using_UQ_Normalization"."\_".$filename;
open(OUT,">$path/$outfile");
print OUT "Gene\tlogFC\tlogCPM\tLR\tPvalue\tFDR\n";
open(F,"$Rfile");
while(my $data = <F>)
{
$data =~ s/^\s+|\s+$//g;
chomp $data;
$counter1++;
if($counter1==1)
{}
else
{
print OUT "$data\n";
}
}
close F;
close OUT;
unlink $Rfile;
my $end_time=time();
my $total_time=$end_time-$start_time;
print "\nRun Complete in $total_time seconds \.\.\.\n";
print "\nPlease see file $outfile in $path for results\n";
}
if($typeOfNorm eq "UpperQuantile+Empirical")
{
my $start_time=time();
my $path;
my @filepath=split(/\//,$file);
my $filename=pop(@filepath);
foreach my $m(@filepath)
{
if($m eq "")
{}
else
{
$path=$path."\/".$m;
}
}
my $dirtoR=$cwd."\/"."Modules"."\/"."RUVseq_with_empirical.r";