-
Notifications
You must be signed in to change notification settings - Fork 16
/
process_single_run_codeml_results.pl
623 lines (494 loc) · 19.3 KB
/
process_single_run_codeml_results.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
#!/usr/bin/env perl
#####################################
## Robin van der Lee ##
## robinvanderlee AT gmail DOT com ##
############################################################################################################
## Genome-scale detection of positive selection in 9 primates predicts human-virus evolutionary conflicts ##
## Robin van der Lee, Laurens Wiel, Teunis J.P. van Dam, Martijn A. Huynen ##
############################################################################################################
use warnings;
use strict;
use Bio::AlignIO;
require('functions.pl');
#####################
####### SETUP #######
#####################
### command line arguments
my $OUTPUT_SPECIFIC_DIRECTORY = "";
if(scalar @ARGV == 0){
die "Please provide a codeml output directory\n";
} else {
$OUTPUT_SPECIFIC_DIRECTORY = shift @ARGV;
}
### base output directory for codeml results directories
my $OUTPUT_ROOT = ".";
###
my $OUTPUT_DIRECTORY_FULL_PATH = "$OUTPUT_ROOT/$OUTPUT_SPECIFIC_DIRECTORY";
opendir(BASEDIR, $OUTPUT_DIRECTORY_FULL_PATH) or die $!;
### parse ensembl ID
$OUTPUT_DIRECTORY_FULL_PATH =~ /(ENSG\d+)/;
my $current_ensembl_id = $1;
### FILES WITH PARSED DATA
my $RESULTS_PARSED_OUTPUT_ROOT = "$OUTPUT_ROOT/codeml_results_parsed";
`mkdir $RESULTS_PARSED_OUTPUT_ROOT` unless -d $RESULTS_PARSED_OUTPUT_ROOT; # unless it already exists
# 1) general results on the alignment: e.g. kappa, omega, lnL, P values, etc.
my $PARSED_DATA_FILE_1__ALIGNMENT_CODEML_RESULTS = $RESULTS_PARSED_OUTPUT_ROOT . "/" . "$current_ensembl_id" . ".alignment_codeml_results";
open(PARSED_DATA_FILE_1, ">$PARSED_DATA_FILE_1__ALIGNMENT_CODEML_RESULTS");
# 2) residues with alternative model omegas, probabilities, etc.
my $PARSED_DATA_FILE_2__RESIDUES_CODEML_RESULTS = $RESULTS_PARSED_OUTPUT_ROOT . "/" . "$current_ensembl_id" . ".residues_codeml_results";
open(PARSED_DATA_FILE_2, ">$PARSED_DATA_FILE_2__RESIDUES_CODEML_RESULTS");
# R-E-S-U-L-T
# print PARSED_DATA_FILE_1 "alignment_ensembl_id\t" . $current_ensembl_id . "\n";
###########################
####### MAIN SCRIPT #######
###########################
print STDERR "Processing codeml results from directory $OUTPUT_DIRECTORY_FULL_PATH\n\n";
# print $current_ensembl_id . "\n";
### loop over all files in the codeml results directory
# but first I need to read the ctl file, otherwise I can't use the mapping stuff in the other functions below)
my %mapping_table__originalpos_char;
my %mapping_table__originalpos_gaplesspos;
while (my $basedir_file = readdir(BASEDIR)) {
my $basedir_file_full_path = "$OUTPUT_DIRECTORY_FULL_PATH/$basedir_file";
next unless(-f $basedir_file_full_path); # only loop over files
if( $basedir_file_full_path =~ /\.ctl$/ ){
eval {
my $alignment_file = parseCtlFile($basedir_file_full_path);
my $alignment_object = readAlignmentFile($alignment_file);
`cp $alignment_file $RESULTS_PARSED_OUTPUT_ROOT`;
# # see Bio::AlignIO::phylip
# my $AlignIO_out = Bio::AlignIO->new(-fh => \*STDOUT ,
# -format => 'phylip',
# -idlength => 30,
# # -longid => 1,
# -flag_SI => 1,
# -interleaved => 1,
# -wrap_sequential => 1,
# -idlinebreak => 1);
# $AlignIO_out->write_aln($alignment_object);
my @mappingTableRefs = calculatePositionMappingTables($current_ensembl_id, $alignment_object);
%mapping_table__originalpos_char = %{$mappingTableRefs[0]};
%mapping_table__originalpos_gaplesspos = %{$mappingTableRefs[1]};
};
if ($@){
print $@;
die; # next;
}
}
}
closedir BASEDIR;
# then I can do the rest
opendir(BASEDIR, $OUTPUT_DIRECTORY_FULL_PATH) or die $!;
while (my $basedir_file = readdir(BASEDIR)) {
my $basedir_file_full_path = "$OUTPUT_DIRECTORY_FULL_PATH/$basedir_file";
next unless(-f $basedir_file_full_path); # only loop over files
# next unless($basedir_file =~ /^(ENSG\d+)__cds$/); # only loop over relevant files
# print $basedir_file . "\n";
### PARSE & CHECKS & RESULTS
if( $basedir_file_full_path =~ /\.screen_output$/ ){
`cp $basedir_file_full_path $RESULTS_PARSED_OUTPUT_ROOT`;
eval { parseScreenOutput($basedir_file_full_path) };
if ($@){
print $@;
die; # next;
}
}
if( $basedir_file_full_path =~ /\.codeml_outfile$/ ){
`cp $basedir_file_full_path $RESULTS_PARSED_OUTPUT_ROOT`;
eval { parseCodemlOutfile($basedir_file_full_path, $current_ensembl_id, \%mapping_table__originalpos_char, \%mapping_table__originalpos_gaplesspos) };
if ($@){
print $@;
die; # next;
}
}
if( $basedir_file_full_path =~ /rub$/ ){
eval { parseRub($basedir_file_full_path, $current_ensembl_id) };
if ($@){
print $@;
die; # next;
}
}
}
### FINISH
closedir BASEDIR;
close(PARSED_DATA_FILE_1);
close(PARSED_DATA_FILE_2);
# print STDERR "\nFINISHED\n";
print STDERR "=" x 100 . "\n";
#########################
####### FUNCTIONS #######
#########################
###########################################################################
sub parseBEB_results{
my $file = shift @_;
my $current_ensembl_id = shift @_;
my $BEB_resultsString = shift @_;
my @BEB_resultsStringLines = split "\n+", $BEB_resultsString;
my %mapping_table__originalpos_char = %{shift @_};
my %mapping_table__originalpos_gaplesspos = %{shift @_};
# Bayes Empirical Bayes (BEB) analysis (Yang, Wong & Nielsen 2005. Mol. Biol. Evol. 22:1107-1118)
# Positively selected sites (*: P>95%; **: P>99%)
# (amino acids refer to 1st sequence: 9606__Homo_sapiens)
#
# Pr(w>1) post mean +- SE for w
#
# 101 N 0.620 2.040 +- 1.376
# 145 T 0.821 2.610 +- 1.276
# 182 A 0.693 2.249 +- 1.368
# 196 P 0.924 2.871 +- 1.102
my @residueNumber = ();
my @residueType = ();
my @residueProbabilityOmegaBiggerThanOne = ();
my @residueProbabilityOmegaBiggerThanOneSignificance = ();
my @residueOmegaBiggerThanOne = ();
# my $P_CUTOFF = 0.9;
# get reported residues (P > 0.5 are reported)
foreach my $line (@BEB_resultsStringLines){
if($line =~ /amino acids refer to 1st sequence/){
if($line !~ /9606__Homo_sapiens/){
die "Problem with sequence ordering in alignment: see $file";
}
}
if($line =~ /^\s+(\d+)\s+(\w)\s+(\S+?)(\**)\s+(\S+)/){
# print $line . "\n";
# select residues based on P cutoff
# if($3 > $P_CUTOFF){
push(@residueNumber, $1);
push(@residueType, $2);
push(@residueProbabilityOmegaBiggerThanOne, $3);
push(@residueProbabilityOmegaBiggerThanOneSignificance, $4);
push(@residueOmegaBiggerThanOne, $5);
# }
}
}
# printArray(@residueNumber);
# printArray(@residueType);
# renumbering / position mapping
my @gaplessResidueNumbers;
for(my $i = 0; $i < scalar(@residueType); $i++){
my $codemlResidueNumber = $residueNumber[$i];
my $codemlResidueType = $residueType[$i];
my $gaplessResidueNumber;
if($mapping_table__originalpos_char{$codemlResidueNumber} eq $codemlResidueType){
$gaplessResidueNumber = $mapping_table__originalpos_gaplesspos{$codemlResidueNumber};
# print $codemlResidueNumber . "\n";
# print $mapping_table__originalpos_char{$codemlResidueNumber} . "\n";
# print $codemlResidueType . "\n";
# print $gaplessResidueNumber . "\n";
# print "\n";
}
push(@gaplessResidueNumbers, $gaplessResidueNumber);
}
# R-E-S-U-L-T
for(my $i = 0; $i < scalar(@residueType); $i++){
print PARSED_DATA_FILE_2 $current_ensembl_id . "\t" .
$residueType[$i] . "\t" .
$residueNumber[$i] . "\t" .
$gaplessResidueNumbers[$i] . "\t" .
$residueProbabilityOmegaBiggerThanOne[$i] . "\t" .
$residueProbabilityOmegaBiggerThanOneSignificance[$i] . "\t" .
$residueOmegaBiggerThanOne[$i] . "\n";
}
}
###########################################################################
sub parseKappaOmegaResults{
my $kappaOmegaResultsString = shift @_;
my $file = shift @_;
my $current_ensembl_id = shift @_;
my @kw_resultsStringLines = split "\n+", $kappaOmegaResultsString;
my $kappa;
my $omega;
# ##OLD
# # Detailed output identifying parameters
# #
# # kappa (ts/tv) = 5.17988
# #
# # Parameters in M8 (beta&w>1):
# # p0 = 0.97489 p = 0.25380 q = 1.64252
# # (p1 = 0.02511) w = 2.56165
# foreach my $line (@kw_resultsStringLines){
# # print $line . "\n";
# if($line =~ /^kappa\s+\(ts\/tv\)\s+\=\s+(\S+)\s*$/){
# $kappa = $1;
# }
# if($line =~ /w\s+\=\s+(\S+)\s*$/){
# $omega = $1;
# }
# }
#### NEW
# M7vM8 ====================================== #
# Detailed output identifying parameters
# kappa (ts/tv) = 5.73281
# Parameters in M8 (beta&w>1):
# p0 = 0.99986 p = 0.64638 q = 13.98859
# (p1 = 0.00014) w = 985.33511
# dN/dS (w) for site classes (K=11)
# p: 0.09999 0.09999 0.09999 0.09999 0.09999 0.09999 0.09999 0.09999 0.09999 0.09999 0.00014
# w: 0.00060 0.00335 0.00764 0.01344 0.02100 0.03080 0.04379 0.06190 0.09015 0.15116 985.33609
#
# M1avM2a ====================================== #
# Detailed output identifying parameters
# kappa (ts/tv) = 3.84092
# dN/dS (w) for site classes (K=3)
# p: 0.76143 0.00000 0.23857
# w: 0.00000 1.00000 1.17980
#
foreach my $line (@kw_resultsStringLines){
# print $line . "\n";
if($line =~ /^kappa\s+\(ts\/tv\)\s+\=\s+(\S+)\s*$/){
$kappa = $1;
}
if($line =~ /^w\:\s+/){
my @s = split /\s+/, $line;
$omega = $s[$#s]; # get last element of split
}
}
# check omega values
if($omega == -1 || $omega == 89){
die "codeml problem, indicated by omega value $omega: see $file";
}
# R-E-S-U-L-T
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "alternative_model_kappa\t" . $kappa . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "alternative_model_omega\t" . $omega . "\n";
}
###########################################################################
sub parseLikelihoodsAndDoChi2{
my @models = @{shift @_};
my @likelihoodStrings = @{shift @_};
my $file = shift @_;
my $current_ensembl_id = shift @_;
my @numberParameters = ();
my @likelihoods = ();
foreach my $match (@likelihoodStrings){
if($match =~ /np\:\s+(\d+)\)\:\s+(-?[0-9]\d*(\.\d+)?)/){
# number of parameters
push(@numberParameters, $1);
push(@likelihoods, $2);
} else {
die "Problem with the chi2 likelihood ratio test: see $file";
}
}
# printArray(@likelihoodStrings);
# printArray(@numberParameters);
# printArray(@likelihoods);
# do chi2 test // likelihood ratio test
my $degreesOfFreedom = $numberParameters[1] - $numberParameters[0];
my $LRT_statistic = -2 * ($likelihoods[0] - $likelihoods[1]); # see notes
my $chi2_output = `chi2 $degreesOfFreedom $LRT_statistic`; # actually runs the PAML chi2 program
my $prob1;
my $prob2;
if($chi2_output =~ /prob\s+\=\s+(\S+)\s+\=\s+(\S+)\s*$/){
$prob1 = $1;
$prob2 = $2;
} elsif($chi2_output =~ /invalid/){
# this happens when the LRT statistic is below smaller than zero (i.e. alternative model lnL is SMALLER than simple model lnL.. which should actually not be possible since the alternative model has more parameters and hence should always be able to fit the data better)
$prob1 = "NA";
$prob2 = "NA";
} else {
die "Problem with the chi2 likelihood ratio test: see $file";
}
# # print table
# print "\t" .
# "likelihood\t" .
# "LRT_statistic [2x(lnL1 - lnL0)]\t" .
# "parameters\t" .
# "df\t" .
# "P value" . "\n";
# print $models[0] . "\t" .
# $likelihoods[0] . "\t" .
# $numberParameters[0] . "\t" .
# "\t" .
# "\t" .
# "\t" . "\n";
# print $models[1] . "\t" .
# $likelihoods[1] . "\t" .
# $numberParameters[1] . "\t" .
# $LRT_statistic . "\t" .
# $degreesOfFreedom . "\t" .
# "$prob1 ($prob2)" . "\n";
# R-E-S-U-L-T
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "null_model\t" . $models[0] . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "null_model_lnL\t" . $likelihoods[0] . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "null_model_np\t" . $numberParameters[0] . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "alternative_model\t" . $models[1] . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "alternative_model_lnL\t" . $likelihoods[1] . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "alternative_model_np\t" . $numberParameters[1] . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "LRT_statistic\t" . $LRT_statistic . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "LRT_degrees_of_freedom\t" . $degreesOfFreedom . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "LRT_P_value_full\t" . $prob1 . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "LRT_P_value_scientific\t" . $prob2 . "\n";
}
###########################################################################
sub parseCodemlOutfile{
my $file = shift @_;
my $current_ensembl_id = shift @_;
my $oref = shift @_;
my $gref = shift @_;
my %mapping_table__originalpos_char = %{ $oref };
my %mapping_table__originalpos_gaplesspos = %{ $gref };
#stop function if file doesn't exists
eval{ checkIfExists($file) };
die if($@);
#slurp file
local $/=undef;
open(FILE, "<$file");
my $filestring = <FILE>;
close FILE;
## test if file contains this stuff
my $countTimeUsed = () = $filestring =~ /Time used\:/gi;
if( $countTimeUsed != 2 ){ # check if this pattern occurs twice
die "codeml problem: see $file";
}
my $convergenceString = "check convergence\.\.";
my @matches = ( $filestring =~ /$convergenceString/g );
# R-E-S-U-L-T
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "codeml_outfile_convergence_warnings\t" . scalar(@matches) . "\n";
my @models = ( $filestring =~ /Model \d\: (.+)\n/g );
# printArray(@models);
if( scalar(@models) != 2 ){ # check if this pattern occurs twice
die "codeml problem: see $file";
}
## maximum likelihood estimations for the models
my @likelihoodLines = ( $filestring =~ /(lnL\(ntime\:.+)\n/g );
eval{ parseLikelihoodsAndDoChi2(\@models, \@likelihoodLines, $file, $current_ensembl_id) };
die if($@);
## get kappa and omega estimations for alternative model (the second occurence)
my @kappaOmegaResultsStrings = ( $filestring =~ /(Detailed output identifying parameters.*?)dN \& dS for each branch/sg );
eval{ parseKappaOmegaResults($kappaOmegaResultsStrings[1], $file, $current_ensembl_id) }; # only get the values for the second occurence (alternative model)
die if($@);
## get part of outfile with BEB results (positively selected residues)
my $BEB_resultsString = "";
if( $filestring =~ /(Bayes Empirical Bayes \(BEB\) analysis.*)The grid/s ){
$BEB_resultsString = $1;
eval{ parseBEB_results($file, $current_ensembl_id, $BEB_resultsString, \%mapping_table__originalpos_char, \%mapping_table__originalpos_gaplesspos) };
die if($@);
} else {
die "codeml problem, no BEB results reported: see $file";
}
}
###########################################################################
sub parseRub{
my $file = shift @_;
my $current_ensembl_id = shift @_;
#stop function if file doesn't exists
eval{ checkIfExists($file) };
die if($@);
#slurp file
local $/=undef;
open(FILE, "<$file");
my $filestring = <FILE>;
close FILE;
#test if file contains this stuff
my $convergenceString = "check convergence!";
my @matches = ( $filestring =~ /$convergenceString/g );
# R-E-S-U-L-T
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "rub_convergence_warnings\t" . scalar(@matches) . "\n";
}
###########################################################################
sub parseScreenOutput{
my $file = shift @_;
#stop function if file doesn't exists
eval{ checkIfExists($file) };
die if($@);
#slurp file
local $/=undef;
open(FILE, "<$file");
my $filestring = <FILE>;
close FILE;
#test if file contains this stuff
my $countTimeUsed = () = $filestring =~ /Time used\:/gi;
if( $countTimeUsed != 2 ){ # check if this pattern occurs twice
die "codeml problem: see $file";
}
if( $filestring =~ /This is a rooted tree, without clock\. Check\./ ){
die "Rooted tree problem: see $file";
}
if( $filestring !~ /Branch lengths in tree are fixed\./ ){
die "codeml problem: see $file";
}
my @matches = ( $filestring =~ /Model \d\: (\S+)/g );
# printArray(@matches);
if( scalar(@matches) != 2 ){ # check if this pattern occurs twice
die "codeml problem: see $file";
}
if( $filestring !~ /BEBing \(dim \= 4\)\. This may take several minutes\./ ){
die "codeml problem: see $file";
}
}
###########################################################################
sub calculatePositionMappingTables{
my $current_ensembl_id = shift @_;
my $alignment_object = shift @_;
my %mapping_table__originalpos_char;
my %mapping_table__originalpos_gaplesspos;
foreach my $seq ( $alignment_object->each_seq() ){
# get human sequence
next unless $seq->id =~ /^9606__Homo_sapiens/;
# print $seq->alphabet . "\n";
# print $seq->seq . "\n";
my $counter_original = 0;
my $counter_gapless = 0;
my @characters = split //, $seq->seq;
foreach my $char (@characters){
$counter_original = $counter_original + 1;
if($char !~ /\-/){
$counter_gapless = $counter_gapless + 1;
}
# print $char . "\t" . $counter_original . "\t" . $counter_gapless . "\n";
$mapping_table__originalpos_char{$counter_original} = $char;
$mapping_table__originalpos_gaplesspos{$counter_original} = $counter_gapless;
}
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "length_alignment\t" . $counter_original . "\n";
print PARSED_DATA_FILE_1 $current_ensembl_id . "\t" . "length_human_sequence\t" . $counter_gapless . "\n";
}
return (\%mapping_table__originalpos_char, \%mapping_table__originalpos_gaplesspos);
}
###########################################################################
sub readAlignmentFile{
my $file = shift @_;
# print $file;
#stop function if file doesn't exists
eval{ checkIfExists($file) };
die if($@);
#read alignment file
my $alignment;
my $AlignIO_in = Bio::AlignIO->new(-file => $file ,
-format => 'fasta');
$alignment = $AlignIO_in->next_aln(); # Returns : a Bio::Align::AlignI compliant object
$alignment->set_displayname_flat(); # Function : Makes all the sequences be displayed as just their name, not name/start-end
#throw error if file contains another alignment
my $alignment2 = $AlignIO_in->next_aln();
if(defined $alignment2){
die "$file contains multiple alignments";
}
return $alignment;
}
###########################################################################
sub parseCtlFile{
my $file = shift @_;
#stop function if file doesn't exists
eval{ checkIfExists($file) };
die if($@);
open(FILE, "<$file");
my $alignment_file_full_path;
while(<FILE>){
if(/seqfile\s+\=\s+(\S+)\s*/){
$alignment_file_full_path = $1; #../../../../sequences/prank-codon-masked/ENSG00000122965__cds.prank-codon-guidance-tcs-masked-species-sorted.aln.phy
}
}
close FILE;
my @s = split /\//, $alignment_file_full_path;
my $alignment_file = join("/", @s[2 .. $#s]);
# my $alignment_file = join("/", @s[3 .. $#s]);
# print $alignment_file;
my $translated_alignment_file = $alignment_file;
$translated_alignment_file =~ s/\.phy/.translated.fa/;
return $translated_alignment_file;
}
###########################################################################
sub checkIfExists{
my $file = shift @_;
if(! -f $file){
die "File $file does not exist";
}
}