Mercurial > repos > ucsb-phylogenetics > osiris_phylogenetics
comparison phyloconversion/change_sp.pl @ 0:5b9a38ec4a39 draft default tip
First commit of old repositories
author | osiris_phylogenetics <ucsb_phylogenetics@lifesci.ucsb.edu> |
---|---|
date | Tue, 11 Mar 2014 12:19:13 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:5b9a38ec4a39 |
---|---|
1 #!/usr/bin/perl -w | |
2 use strict; | |
3 | |
4 my $infile = $ARGV[0]; | |
5 my $changefile = $ARGV[1]; | |
6 my $outfile = $ARGV[2]; | |
7 | |
8 open(IN, "$infile") or exit; | |
9 open(CHANGE, "$changefile"); | |
10 open(OUT, ">$outfile") or exit; | |
11 | |
12 | |
13 my %speciesFor; #Hash to associate code with species name | |
14 | |
15 while (<CHANGE>) | |
16 { | |
17 chomp; | |
18 my $currentinput = "$_"; | |
19 if($currentinput =~m /\t/){ #must have a tab otherwise wrong file format | |
20 if($currentinput =~m /\t\t/){ | |
21 print OUT "ERROR: file contains 2 tabs in a row. Check phytab format.\n"; | |
22 die("ERROR: file contains 2 tabs in a row. Check it is in phytab format"); | |
23 }else{ | |
24 my @changepair = split(/\t/, $currentinput); | |
25 my $codename=$changepair[0]; | |
26 my $sp_name = $changepair[1]; | |
27 if (exists $speciesFor{$codename}) { | |
28 print OUT "ERROR: Species name specification for $codename is duplicated\n"; | |
29 die("ERROR: Species name specifiation for for $codename is duplicated\n"); | |
30 }else{ | |
31 $speciesFor{$codename}=$sp_name; | |
32 } | |
33 } | |
34 }else{ | |
35 die "ERROR: Species conversion table must be genefamily\tmodel and contain no blank lines\n"; | |
36 } | |
37 } | |
38 while (<IN>) { | |
39 chomp; | |
40 my $currentinput = "$_"; | |
41 if($currentinput =~m /\t/){ #must have a tab otherwise wrong file format | |
42 if($currentinput =~m /\t\t/){ | |
43 print OUT "ERROR: file contains 2 tabs in a row. Check phytab format.\n"; | |
44 die; | |
45 }else{ | |
46 my @changepair = split(/\t/, $currentinput); | |
47 my $sp_name=$changepair[0]; | |
48 | |
49 if (exists $speciesFor{$sp_name}) { | |
50 $currentinput =~s /$sp_name/$speciesFor{$sp_name}/ ; | |
51 print OUT $currentinput."\n"; | |
52 }else{ | |
53 print OUT $currentinput."\n"; | |
54 } | |
55 } | |
56 }else{ | |
57 die "ERROR: Input a PHYTAB file in Tabular format\n"; | |
58 } | |
59 } | |
60 close(IN); | |
61 close(OUT); | |
62 close(CHANGE); | |
63 | |
64 sub change | |
65 { | |
66 | |
67 my $changetext = shift; | |
68 $changetext =~ s/ /_/g; | |
69 return $changetext; | |
70 } |