-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvargenius.pl
executable file
·3743 lines (3269 loc) · 181 KB
/
vargenius.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
#vargenius.pl path
use lib '/pico/work/TELET_TIGEM/VarGeniusBeta/';
####PLATFORM_SPECIFIC_SETTINGS_TERMINATED
#VarGenius - Variant Discovery and Annotation Tool
#Copyright (C) <2017> <Francesco Musacchia>
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
=head1 NAME
VarGenius - Variant Discovery and Annotation Tool
=head1 SYNOPSIS
VarGenius is a tool for the detection and annotation of variants
Please read carefully the user Readme and User Guide before to start executing it.
=cut
=head1 OPTIONS
=over 8
=item B<--help>
Shows the brief help informations
=item B<--version>
Shows the version
=back
=cut
=head1 EXAMPLES
Write the config.txt file and give it in input to this script. In the config file you have to specify the locations of the data
that you want to manage.
The following is an example of call to this script:
vargenius.pl -c config.txt
=cut
=head1 DESCRIPTION
Here you have the descriptions of the elements that you have to write on the file config.txt
=cut
=head1 AUTHORS
Francesco Musacchia
--
http://www.tigem.it
$Id: VarGenius, 2017/06/01 11:00:12 Exp $
=cut
# NEEDED LIBRARIES
use strict;
use warnings;
#use FindBin;#To search libraries
#use lib $FindBin::Bin;#To search libraries
use Getopt::Long;
use Cwd;#To change work directory
use Data::Dumper;#To print the hashes
use Pod::Usage;#Used to write an usage
use File::Copy;#To manage files
use IO::Handle;#To immediately print with autoflush
use Time::HiRes qw( time ); #To compute the running time of jobs
#Using a library to manage files
use LIB::files_management qw( delete_file save_hash load_hash file_not_present
file_name_wostrange_chars print_file extract_name
append_file_2_file separate_bed_auto_and_sex_chr
get_only_first_on_col_from_BED split_bedfile);
#Using a library to manage configuration files and their global variables
use LIB::programs_management qw(hash2ConfigFile configFile2Hash try_exec_command
try_exec_job initialize_folders print_and_log log_and_exit
separate_input_ids remove_sample_sheet show_analyses_from_sample_sheet
get_ped_file remove_analyses clean_folders save_analyses checkConfigVariables
separate_bed_perchr show_analysesids_from_analysesnames show_samples_from_group
check_config_parameters check_genedb_links get_flowcell_and_lane
get_ped_file_for_enlarged_analysis store_and_compress_analyses
exec_store_and_compress_analyses check_datasets_links
show_samplesids_from_samplesnames get_extended_regions
JOB_get_status_field JOB_is_active_queue);
#Using a library to manage configuration files and their global variables
use LIB::db_management qw(createDBAndTables getSampleConfiguration copyTable2DB
exists_ss_locked insert_into_table_locked get_id_if_exists_from_db
select_all_from_db db_present select_distinct_samples createTables
do_query_select_all update_table update_table_2
insert_only_if_not_exists_locked get_count_from_selected);
#Using a library for picard functions management
use LIB::picard_management qw(run_PICARD_BedToIntervalList);
#Using a library for bedtools functions management
use LIB::bedtools_management qw(run_BEDTOOLS_intersectBed run_BEDTOOLS_sortBed);
#Using a library for standard utilities
use LIB::std_lib qw(print_hash print_array correct_type);
#Using a library for managing CNVs
use LIB::cnv_management qw( calculate_gc_content );
#GLOBAL VARIABLES COMMON TO MANY PROGRAMS
my $configHash;#This hash substain all the life of the program
my $program_name = "vargenius.pl";
my $readme = "README.me";#Readme filename
my $run = 1;#Determines if the program should execute tasks or not (used to print the help)
my $program_config = "program_config.txt";#The path to the configuration file for the program
my $variables_file = "variables.txt";#The file with all the variables that must be present in the config files
my $config_folder = "CONFIGURATION";
my $license_file = "COPYRIGHT";
my $working_folder = '';#Folder where to work
my $session_folder = '';#Folder where all the analyses will be written
my $program_folder = '';#Folder of the program
my $foldersFile = "folders.txt";
my $program_version = "0.1";
my $libFolder = "LIB/";#folder with all the libraries
my $logFolder = "LOG";
my $dataFolder = "DATA";
my $main_data_folder = "";
my $main_log_folder = "";
my $log_file = "";
my $timesFile = "";
my $user_config = "";
#LOG nice printings
my $niceClosure = "\n=================================================\n";
my $configClosure = "\n*************************************************\n";
my $vargenius_title = ' _ _ _______ ______ ______ _______ __ _ _____ _ _ _______'."\n".
' \ / |_____| |_____/ | ____ |______ | \ | | | | |______'."\n".
' \/ | | | \_ |_____| |______ | \_| __|__ |_____| ______|'."\n";
#Global variables
my $inputFolder = "";
my $paramFile = "";
my $sample_sheet = "";
my $create_database = "";
my $create_tables = "";
my $qualityCheck = "";
my $trimming = "";
my $assemQual = "";
my $alignment = "";
my $refining = "";
my $mergesam = "";
my $varcall = "";
my $genot = "";
my $varfilt = "";
my $phasing = "";
my $stats = "";
my $anstats = "";
my $annotate = "";
my $finalout = "";
my $fastfout = "";
my $vcfimport = "";
my $start_all = "";
my $genedb = "";
my $dldatasets = "";
my $geneann = "";
my $reannote = "";
my $remove_sample_sheet = "";
my $remove_analyses = "";
my $store_analyses = "";
my $vg_store_analyses = "";#Used to re-execute the command as a job
my $save_analyses = "";
my $show_analyses = "";
my $show_samples = "";
my $get_analyses_ids = "";
my $get_samples_ids = "";
my $clean_analyses = "";
my $clean_folder = "";
my $overwrite_conf = "";
my $update_freqs = "";
my $cnv_detection = "";#Flag to activate the CNV pipeline
my $cnv_out = "";#Flag to activate the CNV output generation
my $profile = "";
my $license = "";# Shows Open Source GNU GPL license
my $pipeline = "pipeline";
#This variable is useful to understand if the user runs an analysis or something
#other (like: --genedb )
my $do_pipeline_tasks = 1;
my $outFolder;
my $cpus = 0;
my $run_samples = "";#samples identifiers
my $run_analyses = "";#analyses identifiers
my $force_run = "";#Use this to force runs
my $run_name = "";#Name of the run with which you are working
my $exec_utils = 0;
#Configuration hash
my $cfg_hash;
my $config_file = "";
#Sample information hash
my $ss_hash;
my $sampleID_field = "sampleID";
my @ss_samples = ();
#Hash that contains the analyses and the samples to execute
my $exec_hash;
#Dependencies hash
my $deps_f;
my $qsub_command = "qsub";
my $programs_runner = "programs_runner.pl";
#my $jobs_cleaner = "jobs_cleaner.pl";
###############DB TABLES
my $sample_conf_table = "sample_conf";
#Tasks names
my @pipeline_tasks = ('qc','trim','align','refine','MS','varcall','genot','varfilt','phasing','stats',
'anstats','finalout','fastfout');
#Tasks to exec
my @tasks_to_exec = ();
#####################################################MAIN#############################################
######################################################################################################
#LOG FILE CREATION
#Here we take the current time to get a log name different at each computation
my $time = scalar(localtime);
$time =~ s/ /_/g;
$time =~ s/:/-/g;
#$log_file = $program_name."_exec_$time.log";
#$timesFile = $program_name."_times_$time.log";
STDOUT->autoflush(1);#This makes STDOUT "hot" in the sense that everything will be print immediately
parse_command_line_args();
#VarGenius permits both the usage of some utilities and the run of an analysis pipeline
#we set here the log file name depending on what is doing
if ( $exec_utils > 0){
$log_file = "utils_$time.log";
}else{
$log_file = join("_",@tasks_to_exec)."_$time.log";
}
if ( -e $user_config and $user_config ne ''){
#print_and_log("\nStore configuration files parameters..\n",$log_file);#DEBUGCODE
#Sets useful directories and stores the content of the configuration files
set_global_var_and_confighash($user_config);
#Print license
if ( $license ){
print_file($program_folder."/".$license_file);
log_and_exit("Exiting..\n",$log_file);
}
#Utilities execution
if ( $exec_utils > 0){
#Other tasks to execute like utilities
print_and_log("No tasks to execute! Checking if you want to make utils...\n\n",$log_file);
#Remove completely a run
if ( $remove_sample_sheet ne '' ){
remove_sample_sheet($cfg_hash,$log_file,$remove_sample_sheet);
}
#Remove a single analysis
if ( $remove_analyses ne '' ){
remove_analyses($cfg_hash,$log_file,$remove_analyses);
}
#Given a run name (sample sheet file) gives all the analysis ids
if ( $show_analyses ne '' ){
show_analyses_from_sample_sheet($cfg_hash,$show_analyses,$log_file);
}
#Given a analysis name or a analysis id returns all the sample ids
if ( $show_samples ne '' ){
show_samples_from_group($cfg_hash,$show_samples,$log_file);
}
#Given a set of analysis names gives all the analysis ids
if ( $get_analyses_ids ne '' ){
show_analysesids_from_analysesnames($cfg_hash,$get_analyses_ids,$log_file);
}
#Given a set of sample names gives all the samples ids
if ( $get_samples_ids ne '' ){
show_samplesids_from_samplesnames($cfg_hash,$get_samples_ids,$log_file);
}
#Given analysis ids stores and compresses the output files into the storage area
if ( $vg_store_analyses ne '' ){
exec_store_and_compress_analyses($cfg_hash,$store_analyses,$force_run,$log_file);
}
#Given analysis ids stores and compresses the output files into the storage area
if ( $store_analyses ne '' ){
store_and_compress_analyses($cfg_hash,$working_folder,$store_analyses,$force_run,$log_file);
}
#Given analysis ids stores the output files into the storage area and makes a symbolic link
if ( $save_analyses ne '' ){
save_analyses($cfg_hash,$working_folder,$store_analyses,$force_run,$log_file);
}
#Clean all the folders refine,varcall,genotype completely and
#the useless bam and sam in alignment
if ( $clean_folder ne '' ){
my $sep = ",";
my @analyses = split($sep,separate_input_ids($clean_folder,$sep));
clean_folders($cfg_hash,\@analyses,$working_folder,$log_file);
}
}else {
preliminary_configuration();
#print_and_log("The selected pipeline is $pipeline...\n",$log_file);
if (scalar ( @tasks_to_exec) > 0 ) {
if ( $pipeline eq 'pipeline'){
print_and_log("Pipeline execution...\n",$log_file);
pipeline_execution();
}
}
}
}else{
log_and_exit("Cannot open configuration file. Please give a correct parameter for user_config! Exiting...\n",$log_file);
}
#We also remove all the other remaining log file in the folder created by user's interruptions
system("rm -f $working_folder/*.log");
#####################################################################################################
#
#####################################################################################################
=head2 make_analysis_folders
Title : make_analysis_folders
Usage : make_analysis_folders( );
Function: Creates all the folders needed for the analyses. Needs the config
has been generated.
Returns : nothing
=cut
sub make_analysis_folders{
$cfg_hash->{'all_analysis_ids'} = "";
#For each analysis generates a folder with all the analyses
foreach my $analysis_id (keys %$exec_hash ){
#Fill a variable in cfg_hash with all the analysis ids
$cfg_hash->{'all_analysis_ids'} .= "$analysis_id,";
#print "Creating folders for analysis: $analysis_id\n";#DEBUGCODE
#Obtain the analysis name from the database given the group id
my $analysis_name = get_id_if_exists_from_db($cfg_hash->{'db_name'},$cfg_hash->{'db_dsn'},$cfg_hash->{'db_user'},
$cfg_hash->{'db_pass'},$cfg_hash->{'db_analyses_table'},$cfg_hash->{'db_analysis_name'},
$cfg_hash->{'db_analysis_id'},$analysis_id);
#Create the analysis folder
$cfg_hash->{$analysis_id."_f"} = $working_folder."/".$analysis_name;
#Check if directory exists, otherwise it creates it
unless(-d $cfg_hash->{$analysis_id."_f"} ){
print_and_log("Creating folder ".$cfg_hash->{$analysis_id."_f"}."...\n",$log_file);
mkdir $cfg_hash->{$analysis_id."_f"} or die "ERROR: can't create folder ".$cfg_hash->{$analysis_id."_f"}.". Check permissions. \n";
}
#data folder will go in the analysis folder
my $dataFolder = $cfg_hash->{$analysis_id."_f"}."/".$cfg_hash->{'data_fold'};
$cfg_hash->{$analysis_id."_data_fold"} = $dataFolder;
#Check if directory exists, otherwise it creates it
unless(-d $dataFolder){
print_and_log("Creating folder $dataFolder...\n",$log_file);
mkdir $dataFolder or die "ERROR: can't create folder $dataFolder. Check permissions. \n";
}
#Set a file name to be used to list the links to output files
$cfg_hash->{$analysis_id."_outlist_file"} = $dataFolder."/".$analysis_name."_".$cfg_hash->{'outlist_file'};
#Set a file name to be used to enrich the output page with statistics obtained during the computation
$cfg_hash->{$analysis_id."_outstats_file"} = $dataFolder."/".$analysis_name."_".$cfg_hash->{'outstats_file'};
#print_and_log("Setting paths for outlist and outstats files for analysis $analysis_id:\n",$log_file);#DEBUGCODE
#print_and_log("Outlist: ".$cfg_hash->{$analysis_id."_outlist_file"}."\n",$log_file);#DEBUGCODE
#print_and_log("Outstats: ".$cfg_hash->{$analysis_id."_outstats_file"}."\n",$log_file);#DEBUGCODE
#For each task generates a folder if it does not exist
foreach my $task (@pipeline_tasks){
#print "Creating the folder for $analysis_id and task: $task\n";#DEBUGCODE
my $outFolder = $cfg_hash->{$analysis_id."_f"}."/".$cfg_hash->{$task.'_out_f'};
$cfg_hash->{$analysis_id.'_'.$task.'_out_f'} = $outFolder;
#Check if directory exists, otherwise it creates it
unless(-d $outFolder){
print_and_log("Creating folder $outFolder...\n",$log_file);
mkdir $outFolder or die "ERROR: can't create folder $outFolder. Check permissions. \n";
}
#Log folder will go in the output folder
my $logFolder = $outFolder."/".$cfg_hash->{'log_fold'};
$cfg_hash->{$analysis_id.'_'.$task.'_log_fold'} = $logFolder;
#Check if directory exists, otherwise it creates it
unless(-d $logFolder){
print_and_log("Creating folder $logFolder...\n",$log_file);
mkdir $logFolder or die "ERROR: can't create folder $logFolder. Check permissions. \n";
}
#Only into the final output folder, make also the folder for images
if ( $task eq 'finalout'){
#Log folder will go in the output folder
my $imgFolder = $outFolder."/".$cfg_hash->{'img_fold'};
$cfg_hash->{$analysis_id.'_'.$task.'_img_fold'} = $imgFolder;
#Check if directory exists, otherwise it creates it
unless(-d $imgFolder){
print_and_log("Creating folder $imgFolder...\n",$log_file);
mkdir $imgFolder or die "ERROR: can't create folder $imgFolder. Check permissions. \n";
}
#CNV analysis folder
my $cnvFolder = $outFolder."/".$cfg_hash->{'cnv_out_f'};
$cfg_hash->{$analysis_id.'_cnv_out_f'} = $cnvFolder;
#Check if directory exists, otherwise it creates it
unless(-d $cnvFolder){
print_and_log("Creating folder $cnvFolder...\n",$log_file);
mkdir $cnvFolder or die "ERROR: can't create folder $cnvFolder. Check permissions. \n";
}
#CNV analysis folder: results for SEX chromosomes
my $sexFolder = $cnvFolder."/".$cfg_hash->{'cnv_sex_f'};
#Check if directory exists, otherwise it creates it
unless(-d $sexFolder){
print_and_log("Creating folder $sexFolder...\n",$log_file);
mkdir $sexFolder or die "ERROR: can't create folder $sexFolder. Check permissions. \n";
}
#CNV analysis folder: results for AUTOsomes
my $autoFolder = $cnvFolder."/".$cfg_hash->{'cnv_auto_f'};
#Check if directory exists, otherwise it creates it
unless(-d $autoFolder){
print_and_log("Creating folder $autoFolder...\n",$log_file);
mkdir $autoFolder or die "ERROR: can't create folder $autoFolder. Check permissions. \n";
}
#CNV analysis Log folder will go in the CNV folder
$logFolder = $cnvFolder."/".$cfg_hash->{'log_fold'};
$cfg_hash->{$analysis_id.'_cnv_log_fold'} = $logFolder;
#Check if directory exists, otherwise it creates it
unless(-d $logFolder){
print_and_log("Creating folder $logFolder...\n",$log_file);
mkdir $logFolder or die "ERROR: can't create folder $logFolder. Check permissions. \n";
}
}
}
}
chop($cfg_hash->{'all_analysis_ids'});
}
=head2 get_modified_config_hash
Title : get_modified_config_hash
Usage : get_modified_config_hash( );
Function:
#Depending by the parameters something in the configuration may be changed
#The cfg_hash will be overwritten
Returns : returns the hash updated depending by the different situations
Sequencing type, research group particular interest, generic about configuration
at the end of the process if requested, overwrites the variables that
user wanted to change by using the command line
=cut
sub get_modified_config_hash{
my $cfg_hash = shift;
my $analysis_id = shift;
my ($cfg_hash_updated) = shift;
#my $overwrite_conf = shift;
#Copy the main in the updated hash so that it has all the initial values
foreach my $key (keys %$cfg_hash){
$$cfg_hash_updated->{$key} = $cfg_hash->{$key};
}
if ( $analysis_id eq 'dummy'){
#my $dummy_cfg_f = $config_folder."/".$cfg_hash->{'dummy_profile'};
#configFile2Hash($dummy_cfg_f,\$$cfg_hash_updated);
#Add the dummy profile with the specific time and resources requests for the jobcleaner
if ( $profile ne '' ){
$profile .= ",".$cfg_hash->{'dummy_profile'};
}else{
$profile = $cfg_hash->{'dummy_profile'};
}
#Get the configuration for the jobcleaner from input
my @profiles = split(",",$profile);
foreach my $profile (@profiles){
my $new_config = $config_folder."/".$profile;
if ( -e $new_config ){
print_and_log("Changing the configuration hash using the specific profile at $new_config..\n",$log_file);
configFile2Hash($new_config,\$$cfg_hash_updated);
}else{
print_and_log("WARNING: Cannot open non existent profile $new_config\n",$log_file);
}
}
}else{
#Research group specific requests
my $userid = get_id_if_exists_from_db($cfg_hash->{'db_name'},$cfg_hash->{'db_dsn'},$cfg_hash->{'db_user'},
$cfg_hash->{'db_pass'},$cfg_hash->{'db_analyses_table'},$cfg_hash->{'db_analysis_userid'},
$cfg_hash->{'db_analysis_id'},$analysis_id);
if ( correct_type($userid,"positiveint")){
my @pieces = split(/\./, $cfg_hash->{'profile_file_suff'});
my $param_cfg_f = $config_folder."/".$pieces[0]."_$userid.".$pieces[1];
#The specific configuration file should exist or nothing will change
if ( -e $param_cfg_f){
#print_and_log("Changing the configuration hash for User id: $userid using $param_cfg_f..\n",$log_file);#DEBUGCODE
configFile2Hash($param_cfg_f,\$$cfg_hash_updated);
}else{
print_and_log("WARNING: Cannot find a profile for user id: $userid using $param_cfg_f.\n",$log_file);
}
}
#Other specific profiles that the user wants to load using the input variable --profile
if ( $profile ne '' ){
#They could be separated by comma
my @profiles = split(",",$profile);
foreach my $profile (@profiles){
my $new_config = $config_folder."/".$profile;
if ( -e $new_config ){
print_and_log("Changing the configuration hash using the specific profile at $new_config..\n",$log_file);
configFile2Hash($new_config,\$$cfg_hash_updated);
}else{
print_and_log("WARNING: Cannot open non existent profile $new_config\n",$log_file);
}
}
}
####CONFIGURATION ADJUSTMENT
#Depending by the parameters something in the configuration may be changed
#The cfg_hash will be overwritten
#Here we change configuration depending by the run per chromosome or per sample
my $perchrom = get_id_if_exists_from_db($cfg_hash->{'db_name'},$cfg_hash->{'db_dsn'},$cfg_hash->{'db_user'},
$cfg_hash->{'db_pass'},$cfg_hash->{'db_analyses_table'},$cfg_hash->{'db_perchrom'},
$cfg_hash->{'db_analysis_id'},$analysis_id);
if ($perchrom == 1){
my $mem_cfg_f = $config_folder."/".$cfg_hash->{'perchrom_profile'};
configFile2Hash($mem_cfg_f,\$$cfg_hash_updated);
}else{
my $mem_cfg_f = $config_folder."/".$cfg_hash->{'persample_profile'};
configFile2Hash($mem_cfg_f,\$$cfg_hash_updated);
}
###Sequencing Types
#Right now we have only exomes and amplicons panels sequencing
my $sequencingtype = get_id_if_exists_from_db($cfg_hash->{'db_name'},$cfg_hash->{'db_dsn'},$cfg_hash->{'db_user'},
$cfg_hash->{'db_pass'},$cfg_hash->{'db_analyses_table'},$cfg_hash->{'db_sequencingtype'},
$cfg_hash->{'db_analysis_id'},$analysis_id);
#Overwrite the config hash with parameters specific for Haloplex Technology
if ($sequencingtype eq 'targeted'){
print_and_log("Changing the configuration hash for sequencing type: $sequencingtype..\n",$log_file);
my $param_cfg_f = $config_folder."/".$cfg_hash->{'targeted_profile'};
configFile2Hash($param_cfg_f,\$$cfg_hash_updated);
}
elsif ($sequencingtype eq 'rna'){
print_and_log("Changing the configuration hash for sequencing type: $sequencingtype..\n",$log_file);
my $param_cfg_f = $config_folder."/".$cfg_hash->{'rna_profile'};
configFile2Hash($param_cfg_f,\$$cfg_hash_updated);
}elsif ($sequencingtype eq 'wgs'){
print_and_log("Changing the configuration hash for sequencing type: $sequencingtype..\n",$log_file);
my $param_cfg_f = $config_folder."/".$cfg_hash->{'wgs_profile'};
configFile2Hash($param_cfg_f,\$$cfg_hash_updated);
}
#print "Hash obtained after configuration modification: \n";
#print Dumper\$$cfg_hash_updated;
}
#Overwrite the configuration using input command
if ($overwrite_conf ne ''){
print_and_log("Changing the configuration hash using inputed variables..\n",$log_file);
my $sep = $cfg_hash->{'mult_ann_sep'};
my @vars_to_ow = split(/\Q$sep\E/,$overwrite_conf);
foreach my $var_to_ow (@vars_to_ow){
$var_to_ow =~ s/\s//;
my @parts = split("=",$var_to_ow);
if ( defined $$cfg_hash_updated->{$parts[0]} ){
if ( defined $parts[1] ){
$$cfg_hash_updated->{$parts[0]} = $parts[1];
print_and_log($parts[0]." = ".$parts[1]."...\n",$log_file);
}else{
delete($$cfg_hash_updated->{$parts[0]});
}
}else{
print_and_log("Parameter ".$parts[0]." does not exist...\n",$log_file);
}
}
}
print_and_log("Finished modifying configuration..\n",$log_file);#DEBUGCODE
#Set additional variables of the config hash now with the new params
set_other_global_var_into_hash($$cfg_hash_updated);
#After having modified the configuration check it
check_config_parameters($$cfg_hash_updated,$log_file);
#############
}
=head2 pipeline_execution
Title : pipeline_execution
Usage : pipeline_execution( );
Function: Executes the pipeline
N.B. THE CONFIG HASH HERE ONLY CHANGES TO cfg_hash_gr BECAUSE
FOR EACH analysis THERE WILL BE A DIFFERENT ONE.
PLEASE USE ALWAYS THAT AFTER THE LOOP ON analysis IDS
Returns : nothing
=cut
sub pipeline_execution{
#An hash that considers for each job its dependencies before than it can be run
my $dependence_hash;
my $dep_clean_hash;
#Path to the programs runner
my $program_call = $program_folder."/".$cfg_hash->{'programs_runner_script'};
#Path to the job cleaner script
my $jobclean_prog = $program_folder."/".$cfg_hash->{'jobclean_prog'};
#Put variables in a configuration file. It will be used in each job
#save_hash(\$cfg_hash,$config_file);
#The following are tasks that must be executed with jobs but they are not analysis
#tasks. Thus, if they are executed the pipeline tasks cannot be
###N.B. FOR THESE JOBS THAT ARE RUN INDEPENDENTLY THE CONFIG FILE AT THE END OF THE
# SUBROUTINE MUST NOT BE REMOVED!!!
#####################DOWNLOAD THE DATASETS###################
if ($dldatasets){
#Creation of support tables used for the output generation
my $task = "dldatasets";
print_and_log($niceClosure,$log_file);
print_and_log("(".scalar(localtime)."): $task step \n",$log_file);
#Checks the links containing information for gene annotation
check_datasets_links($cfg_hash,$log_file);
#Get dependencies
my $dependency = "no_depend";
print_and_log("Launching a job for $task \n",$log_file);
#Call the program using qsub and giving it parameters for the job and
my $job_name = $task;
my $job_err = $main_log_folder."/".$task.'.err';
my $job_log = $main_log_folder."/".$task.'.log';
my $env_vars = "CONFIG_FILE=$config_file,TASK=$task,SAMPLE_ID=-1,ANALYSIS_ID=-1,LOG_FILE=$log_file,PIPE=$pipeline ";
my $job_id = try_exec_job( $cfg_hash,$env_vars,$task,$program_call,$job_name,$dependency,$job_log,$job_err,$log_file);
print_and_log("Qsub id: $job_id\n",$log_file);
##Put this job id in the hash for dependencies
$dependence_hash->{$job_name} = $job_id;
print_and_log($niceClosure,$log_file);
}
##################################################
#####################GENE TABLES###################
if ($genedb){
#Creation of support tables used for the output generation
my $task = "genedb";
print_and_log($niceClosure,$log_file);
print_and_log("(".scalar(localtime)."): $task step \n",$log_file);
#Checks the links containing information for gene annotation
check_genedb_links($cfg_hash,$log_file);
#Get dependencies
my $dependency = "no_depend";
print_and_log("Launching a job for $task \n",$log_file);
#Call the program using qsub and giving it parameters for the job and
my $job_name = $task;
my $job_err = $main_log_folder."/".$task.'.err';
my $job_log = $main_log_folder."/".$task.'.log';
my $env_vars = "CONFIG_FILE=$config_file,TASK=$task,SAMPLE_ID=-1,ANALYSIS_ID=-1,LOG_FILE=$log_file,PIPE=$pipeline ";
my $job_id = try_exec_job( $cfg_hash,$env_vars,$task,$program_call,$job_name,$dependency,$job_log,$job_err,$log_file);
print_and_log("Qsub id: $job_id\n",$log_file);
##Put this job id in the hash for dependencies
$dependence_hash->{$job_name} = $job_id;
print_and_log($niceClosure,$log_file);
}
##################################################
#####################GENE ANNOTATION###################
if ($geneann){
#Creation of support tables used for the output generation
my $task = "geneann";
print_and_log($niceClosure,$log_file);
print_and_log("(".scalar(localtime)."): $task step \n",$log_file);
#Get dependencies
my $dependency = "no_depend";
print_and_log("Launching a job for $task \n",$log_file);
#Call the program using qsub and giving it parameters for the job and
my $job_name = $task;
my $job_log = $main_log_folder."/".$task.'.log';
my $env_vars = "CONFIG_FILE=$config_file,TASK=$task,SAMPLE_ID=-1,ANALYSIS_ID=-1,LOG_FILE=$log_file,PIPE=$pipeline ";
my $job_id = try_exec_job( $cfg_hash,$env_vars,$task,$program_call,$job_name,$dependency,$job_log,$job_log,$log_file);
print_and_log("Qsub id: $job_id\n",$log_file);
##Put this job id in the hash for dependencies
$dependence_hash->{$job_name} = $job_id;
print_and_log($niceClosure,$log_file);
}
##################################################
#####################REANNOTATION###################
if ($reannote){
#Creation of support tables used for the output generation
my $task = "reannote";
print_and_log($niceClosure,$log_file);
print_and_log("(".scalar(localtime)."): $task step \n",$log_file);
#Get dependencies
my $dependency = "no_depend";
print_and_log("Launching a job for $task \n",$log_file);
#Call the program using qsub and giving it parameters for the job and
my $job_name = $task;
my $job_log = $main_log_folder."/".$task.'.log';
my $env_vars = "CONFIG_FILE=$config_file,TASK=$task,SAMPLE_ID=-1,ANALYSIS_ID=-1,LOG_FILE=$log_file,PIPE=$pipeline ";
my $job_id = try_exec_job( $cfg_hash,$env_vars,$task,$program_call,$job_name,$dependency,$job_log,$job_log,$log_file);
print_and_log("Qsub id: $job_id\n",$log_file);
#Put this job id in the hash for dependencies
$dependence_hash->{$job_name} = $job_id;
print_and_log($niceClosure,$log_file);
}
##################################################
#####################RECOMPUTE FREQUENCIES###################
if ($update_freqs){
my $task = "update_freqs";
print_and_log($niceClosure,$log_file);
print_and_log("(".scalar(localtime)."): $task step \n",$log_file);
#Get dependencies
my $dependency = "no_depend";
print_and_log("Launching a job for $task \n",$log_file);
#Call the program using qsub and giving it parameters for the job and
my $job_name = $task;
my $job_log = $main_log_folder."/".$task.'.log';
$cfg_hash->{'qsub_walltime'} = "100:00:00";
my $env_vars = "CONFIG_FILE=$config_file,TASK=$task,SAMPLE_ID=-1,ANALYSIS_ID=-1,LOG_FILE=$log_file,PIPE=$pipeline ";
my $job_id = try_exec_job( $cfg_hash,$env_vars,$task,$program_call,$job_name,$dependency,$job_log,$job_log,$log_file);
print_and_log("Qsub id: $job_id\n",$log_file);
#Put this job id in the hash for dependencies
$dependence_hash->{$job_name} = $job_id;
print_and_log($niceClosure,$log_file);
}
##################################################
#N.B. THE CONFIG HASH HERE CHANGES TO cfg_hash_gr AND THE LOG FILE
#CHANGE TO log_file_gr BECAUSE
#FOR EACH GROUP THERE WILL BE A DIFFERENT ONE.
#PLEASE USE ALWAYS THAT AFTER THE LOOP ON GROUP IDS
#An array to know which folder are to clean
my @tasks_for_clean = ();
#########################
##########Start the Analyses
#########################
my $tot_analyses = scalar ( keys %{$exec_hash});
my $num_analysis = 0;
#Execute the tasks only if no other job is executed: update_freqs, gene_db, etc..
if ( $do_pipeline_tasks ){
#print_and_log("\n\nStarting the execution of the pipeline...\n",$log_file);#DEBUGCODE
#For each analysis it executes the pipeline separately
foreach my $analysis_id ( keys %{$exec_hash}){
my $analysis_indication2 = "[an:$analysis_id ](".scalar(localtime)."): ";
#print_and_log("Working with analysis: $analysis_id..\n",$log_file);
##CHECKS AND CONFIGURATION PER-ANALYSIS
#Obtain an hash specific for the analysis we are executing <---N.B.!!
#print_and_log("[an:$analysis_id ](".scalar(localtime).") Changing the configuration hash \n",$log_file);#DEBUGCODE
my $cfg_hash_gr;
get_modified_config_hash($cfg_hash,$analysis_id,\$cfg_hash_gr);
##Parameters that are modified based on the current set of analyses
$num_analysis++;
if ( $num_analysis < $tot_analyses){
#If there is more than one analysis in progress,
#the update of frequencies must be performed only at the last analysis
$cfg_hash_gr->{'update_frequencies'} = "NO";
}
#Generate a log file to be used per group that will go in the data folder
my $log_file_gr = $cfg_hash->{$analysis_id."_data_fold"}."/$analysis_id\_$time.log";
#print_and_log("Copy $log_file to $log_file_gr ..\n",$log_file);#DEBUGCODE
#Copy the content of the main LOG file to the group log file
append_file_2_file($log_file,$log_file_gr);
#Here I remove the main log file because there are the group ones
#and jobclean wil use its own
delete_file($log_file);
###PEDIGREE FILE
#################DB
#Get the count of distinct samples where the genotype has been predicted (must be in use for frequency calculation and for this type of sequencing)
my $query_num_samples = "SELECT ".$cfg_hash->{'db_sample_id'}." FROM ".$cfg_hash->{'db_sample_table'}.
" WHERE ".$cfg_hash->{'db_analysis_id'}."=$analysis_id";
#Connect to database
my $dsn = $cfg_hash->{'db_dsn'}."dbname=".$cfg_hash->{'db_name'}.";";
# PERL DBI CONNECT
my $dbh = DBI->connect($dsn, $cfg_hash->{'db_user'}, $cfg_hash->{'db_pass'}, { RaiseError => 1, AutoCommit => 1 });
my $num_samples = get_count_from_selected($dbh,$query_num_samples," ",$log_file);
#Disconnect db
$dbh->disconnect();
#################
#Obtain the analysis name from the database given the analysis id
my $analysis_name = get_id_if_exists_from_db($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},$cfg_hash_gr->{'db_user'},
$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_analyses_table'},$cfg_hash_gr->{'db_analysis_name'},
$cfg_hash_gr->{'db_analysis_id'},$analysis_id);
#Set the path of the file
my $out_ped = $cfg_hash_gr->{$analysis_id."_data_fold"}."/$analysis_name.".$cfg_hash->{'ped_ext'};
if ( $cfg_hash_gr->{'get_ped_file'} eq 'YES' ){
#Verifying if your are doing a joint analysis of many samples
if ( $num_samples > $cfg_hash_gr->{'min_samples_4_joint'}){
print_and_log("[an:$analysis_id ](".scalar(localtime).") Obtaining a PED file for $num_samples samples : $out_ped \n",$log_file);
get_ped_file_for_enlarged_analysis($cfg_hash_gr,$analysis_id,$out_ped,$log_file);
#Change the time needed for the final steps to the maximum
$cfg_hash_gr->{'genot_walltime'} = $cfg_hash_gr->{'qsub_walltime_max'};
$cfg_hash_gr->{'varfilt_walltime'} = $cfg_hash_gr->{'qsub_walltime_max'};
$cfg_hash_gr->{'finalout_walltime'} = $cfg_hash_gr->{'qsub_walltime_max'};
#Here we set perchrom=1 because if the analysis is a JOINT one, the user is constrict to run it per chromosome
print_and_log("[an:$analysis_id ](".scalar(localtime).") Since you are using $num_samples samples, the database will be updated with: ".$cfg_hash->{'db_perchrom'}."=1 \n",$log_file_gr);
my $fields = $cfg_hash_gr->{'db_perchrom'};
my $values = "1";
update_table_2($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},$cfg_hash_gr->{'db_user'},
$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_analyses_table'},$fields,$values,$cfg_hash_gr->{'db_analysis_id'},$analysis_id);
}
#I create here the pedfile, if there is a trio (M,F,P) then also the phasing can be done
#unless the user decides to avoid it
else{
my $trios = get_ped_file($cfg_hash_gr,$analysis_id,$out_ped,$log_file_gr);
#print_and_log("Created the Pedigree file $out_ped..\n",$log_file_gr);#DEBUGCODE
if( $cfg_hash_gr->{'phasing'} eq 'YES' and $trios == 2){
print_and_log("[an:$analysis_id ](".scalar(localtime).") The analysis is of a TRIO. Phasing will be performed \n",$log_file_gr);
$phasing = 1;
}else{
print_and_log("[an:$analysis_id ](".scalar(localtime).") The analysis is not of a TRIO. Phasing will not be performed \n",$log_file_gr);
$phasing = 0;
}
}
}
####Management of operation with a target file.
#Avoid to do this if the sequencing type is WGS
my $sequencingtype = get_id_if_exists_from_db($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},$cfg_hash_gr->{'db_user'},
$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_analyses_table'},$cfg_hash_gr->{'db_sequencingtype'},
$cfg_hash_gr->{'db_analysis_id'},$analysis_id);
if ( $sequencingtype ne 'wgs'){
####TARGET FILE
#Check if the target file is present in the targets_table
my $target_bed = get_id_if_exists_from_db($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},$cfg_hash_gr->{'db_user'},
$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_analyses_table'},$cfg_hash_gr->{'db_targetbed'},
$cfg_hash_gr->{'db_analysis_id'},$analysis_id);
my $target_bed_path = $cfg_hash_gr->{'target_reg_f'}."/".$target_bed;
#Check if it exists
if (file_not_present($target_bed_path) > 0 ){ print_and_log("[an:$analysis_id ](".scalar(localtime).") WARNING: $target_bed_path does not exist. Please put the target file into ".$cfg_hash_gr->{'target_reg_f'}." ...\n",$log_file_gr);}
##TARGET EXTENSION
#If the user wants to use the extended target, in this step we call a function to create a new target
#the database is also updated
my $target_extended = get_id_if_exists_from_db($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},$cfg_hash_gr->{'db_user'},
$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_analyses_table'},$cfg_hash_gr->{'db_targetextended'},
$cfg_hash_gr->{'db_analysis_id'},$analysis_id);
if ( $cfg_hash_gr->{'target_extension'} eq 'YES' ){
if ($target_extended == 0){
my $target_bed_ext_path = extract_name($target_bed_path,"noext")."_plus".$cfg_hash_gr->{'target_extens_dim'}.".".$cfg_hash_gr->{'bed_ext'};
if (!(-e $target_bed_ext_path) or (-z $target_bed_ext_path) ) {
print_and_log("[an:$analysis_id ](".scalar(localtime).") Generating the extended target into: $target_bed_ext_path \n",$log_file_gr);
print_and_log("[an:$analysis_id ](".scalar(localtime).") Extending ".$cfg_hash_gr->{'target_extens_dim'}."nt on both 3' an 5' \n",$log_file_gr);
get_extended_regions($target_bed_path,$target_bed_ext_path,$cfg_hash_gr->{'target_extens_dim'});
}else{
print_and_log("[an:$analysis_id ](".scalar(localtime).") Extended target file $target_bed_ext_path have been already produced\n",$log_file_gr);
}
#Update table
$target_bed = extract_name($target_bed_ext_path,0);
$target_bed_path = $cfg_hash_gr->{'target_reg_f'}."/".$target_bed;
print_and_log("[an:$analysis_id ](".scalar(localtime).") The database will be updated with: $target_bed \n",$log_file_gr);
my $fields = $cfg_hash_gr->{'db_targetbed'}.",".$cfg_hash_gr->{'db_targetextended'};
my $values = "'$target_bed',1";
update_table_2($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},$cfg_hash_gr->{'db_user'},
$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_analyses_table'},$fields,$values,$cfg_hash_gr->{'db_analysis_id'},$analysis_id);
}else{
#The target extended should already exist
if (!(-e $target_bed_path) or (-z $target_bed_path) ) {
print_and_log("[an:$analysis_id ](".scalar(localtime).") The extended target $target_bed_path does not exist. Please correct... \n",$log_file_gr);
print_and_log("[an:$analysis_id ](".scalar(localtime).") Update the db with: 1. row target file 2. targetextended=0 \n",$log_file_gr);
}
print_and_log("[an:$analysis_id ](".scalar(localtime).") $target_bed has been already extended.\n",$log_file_gr);
}
}
#Getting the target bed file using the folder for targets and the name contained in the database
my $target_id = get_id_if_exists_from_db($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},
$cfg_hash_gr->{'db_user'},$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_target_files_table'},$cfg_hash_gr->{'db_targetid'},
$cfg_hash_gr->{'db_targetname'},"'".$target_bed."'");
#If it does not exist, insert
if ($target_id < 0 ){
$target_id = insert_into_table_locked($cfg_hash->{'db_name'},$cfg_hash->{'db_dsn'},$cfg_hash->{'db_user'},
$cfg_hash->{'db_pass'},$cfg_hash->{'db_target_files_table'},$cfg_hash_gr->{'db_targetname'},"'".$target_bed."'");
}
#PER-CHROMOSOME: Any analysis could be executed per-chromosome, hence we generate the bed files for each cromosome
#Get the perchrom flag
my $perchrom = get_id_if_exists_from_db($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},$cfg_hash_gr->{'db_user'},
$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_analyses_table'},$cfg_hash_gr->{'db_perchrom'},
$cfg_hash_gr->{'db_analysis_id'},$analysis_id);
#Get the flag for status
my $db_target_perchrdiv = get_id_if_exists_from_db($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},$cfg_hash_gr->{'db_user'},
$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_target_files_table'},$cfg_hash_gr->{'db_target_perchrdiv'},
$cfg_hash_gr->{'db_targetname'},"'".$target_bed."'");
my $dest_folder = $main_data_folder."/".$cfg_hash_gr->{'target_perchr_fold'}."/$target_bed\_".$cfg_hash_gr->{'chrom_reg_f'};
print_and_log("[an:$analysis_id ](".scalar(localtime).") Target $target_bed per chromomsome folder: in $dest_folder (flag $db_target_perchrdiv)...\n",$log_file_gr);
if ( $db_target_perchrdiv == 0 ){
#If folder does not exists, creates it
unless(-d $dest_folder){
print_and_log("[an:$analysis_id ](".scalar(localtime).") Creating folder $dest_folder...\n",$log_file_gr);
mkdir $dest_folder or die "[an:$analysis_id ](".scalar(localtime).") ERROR: can't create folder $dest_folder. Check permissions. \n";
}
print_and_log("[an:$analysis_id ](".scalar(localtime).") Separating $target_bed_path per chromomsome in $dest_folder...\n",$log_file_gr);
separate_bed_perchr($target_bed_path,$dest_folder);
#Additionally some chromosome can be further separated in two parts
if ( length($cfg_hash_gr->{'chroms_to_split'}) > 0 ){
print_and_log("[an:$analysis_id ](".scalar(localtime).") Separating in two bed chr:".$cfg_hash_gr->{'chroms_to_split'}."...\n",$log_file_gr);
my @chroms_to_split = split(",",$cfg_hash_gr->{'chroms_to_split'});
foreach my $chrom_to_split (@chroms_to_split) {
my $bed_in = $dest_folder."/".$cfg_hash->{'chr_suff'}."$chrom_to_split.".$cfg_hash->{'bed_ext'};
my $bed_out1 = $dest_folder."/".$cfg_hash->{'chr_suff'}."$chrom_to_split\_1.".$cfg_hash->{'bed_ext'};
my $bed_out2 = $dest_folder."/".$cfg_hash->{'chr_suff'}."$chrom_to_split\_2.".$cfg_hash->{'bed_ext'};
#QUESTA FUNZIONE ANDRA FATTA IN MODO DA FARE UNO SPLIT IN N PARTI INVECE CHE SOLO 2
split_bedfile ($bed_in,$bed_out1,$bed_out2);
}
}
#Update the chromosome regions folder for this analysis
$cfg_hash_gr->{'chrom_reg_f'} = $dest_folder;
#Update table
my $fields = $cfg_hash_gr->{'db_target_perchrdiv'}.";".$cfg_hash_gr->{'db_target_perchrdivdir'};
my $values = "1;'$dest_folder'";
update_table($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},$cfg_hash_gr->{'db_user'},
$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_target_files_table'},$fields,$values,$cfg_hash_gr->{'db_targetname'},"'".$target_bed."'");
}else{
##Getting the target_bed
$dest_folder = get_id_if_exists_from_db($cfg_hash_gr->{'db_name'},$cfg_hash_gr->{'db_dsn'},$cfg_hash_gr->{'db_user'},
$cfg_hash_gr->{'db_pass'},$cfg_hash_gr->{'db_target_files_table'},$cfg_hash_gr->{'db_target_perchrdivdir'},
$cfg_hash_gr->{'db_targetname'},"'".$target_bed."'");
}