-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreroot_newick.pl
71 lines (51 loc) · 1.58 KB
/
reroot_newick.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
#!/usr/bin/perl
use strict;
use Carp qw (cluck confess croak);
use warnings;
use File::Basename;
my $dir_input = shift;
my $dir_output = shift;
if (!-e $dir_input)
{
confess("directory does not exist");
}
##find core_output/ -name '*.nwk.out' -exec cp {} ./trees \;
my $get_files_cmd = 'find ' . $dir_input . " -name \'*.nwk.out\'";
my @output = qx($get_files_cmd);
#print "DEBGUG $output[0]\n";
my $skipped_trees = 0;
#load on files
foreach my $newick_file (@output)
{
chomp $newick_file;
my($filename, $dirs, $suffix) = fileparse($newick_file , '.nwk.out');
#open file
open (FH, $newick_file) or die "cannot open $newick_file : $!";
while (<FH>)
{
my $tree = $_;
#print "DEBGUG $tree \n";
my @musba = $tree =~ m/(Musba[\w_]+):/g;
if (scalar(@musba) > 1)
{
print "WARNING: Skipped tree : $filename \n $tree \n";
$skipped_trees++;
next;
}
my $outgroup = $musba[0];
# reroot file
my $reroot_cmd = '/homedir/rouard/bin/newick-utils-1.6/bin/nw_reroot ' . $newick_file . " $outgroup";
#print "DEBGUG: $reroot_cmd \n";
my $rooted_tree = qx($reroot_cmd);
#print "DEBGUG: $rooted_tree \n";
# create file
my $rooted_tree_file = $dir_output . $filename . '.rooted.nwk';
#print "DEBGUG: $rooted_tree_file \n";
open (OUT, ">$rooted_tree_file") or die "cannot create file : $!";
print OUT $rooted_tree . "\n";
close OUT;
}
#close file
close FH;
}
print "DEBGUG Number of skipped trees : $skipped_trees\n";