-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtree_tip_replacer.pl
More file actions
39 lines (30 loc) · 1.27 KB
/
tree_tip_replacer.pl
File metadata and controls
39 lines (30 loc) · 1.27 KB
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
use File::Basename;
my $name = basename($0);
my ($input, $treefile) = @ARGV;
if (not defined $input) {
print "\nFAILED TO RUN!\nMissing argument 'translation_file'\n";
print "USAGE: perl $name [translation_file] [treefile]\n\n'Translation file' is a tab delimited file formated like this:\nCURRENT_NAME\tDESIRED_NAME\n\n";
exit;
}
if (not defined $treefile) {
print "\nFAILED TO RUN!\nMissing argument 'treefile'\n";
print "USAGE: perl $name [translation_file] [treefile]\n\n'Tree file' is NEWICK format treefile\n\n";
exit;
}
open (INPUT, $input) || die "\n\Translation file $input is missing.\nPlace \"$input\" in this directory and try again.\nThis is a tab delimited file formated like this:\nCURRENT_NAME\tDESIRED_NAME\n\n\n";
($name,$dir,$ext) = fileparse($treefile,'\..*');
open (TREEFILE, $treefile) || die "cannot open $treefile check the filename and ensure correct extention\n";
open (PRINTOUT, ">".$name."_rename.tre") || die "cannot open the output file\n";
while (<INPUT>) {
chomp $_;
@split = split(/\t/, $_);
$nammer{$split[0]} = $split[1];
}
foreach (<TREEFILE>) {
$line = $_;
foreach $name (sort keys %nammer) {
$line =~ s/\b$name\b/$nammer{$name}/g;
}
print PRINTOUT "$line";
}
print "\nCreated $name\_rename.tre\n\nDONE!\n\n";