comparison phyloconversion/tnt2phytab.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
2
3 use strict;
4
5 my $file = $ARGV[0];
6
7 # read file with genes
8 open FILE, $file or die "ERROR: Cannot open file $file\n";
9 my $firstline=0;
10 my $datatype;
11 my $taxa;
12 while (<FILE>) {
13 my $currentinput = "$_";
14 if($firstline==0){
15 if($currentinput =~ m/nstates/){
16 my @splitlines=split(' ',$currentinput);
17 $splitlines[2] =~ s/\;//;
18 if($splitlines[2] == 2){
19 $datatype = "binary";
20 }elsif($splitlines[2] > 2){
21 $datatype = "multi";
22 }
23 }else{
24 die "ERROR: file does not begin with nstates line. Must be TNT file exported from MorphoBank.org";
25 }
26 }
27 if($firstline==1){
28 if($currentinput =~ m/xread/){
29 }else{
30 die "ERROR: file does not contain xread line. Must be TNT file exported from MorphoBank.org";
31 }
32 }
33 if($firstline==2){
34 if($currentinput =~ m/Morpho/){
35 }else{
36 die "ERROR: file does not contain Morphobank Comment line. Must be TNT file exported from MorphoBank.org";
37 }
38 }
39 if($firstline==3){
40 if($currentinput =~ m/\d/){
41 my @splitlines=split(' ',$currentinput);
42 $taxa = $splitlines[1]."\n";
43 }else{
44 die "ERROR: file does not contain number of taxa. Must be TNT file exported from MorphoBank.org";
45 }
46 }
47 if($firstline==4){
48 if($currentinput =~ m/\d/){
49 die "ERROR: file does not contain empty line after taxa numbers . Must be TNT file exported from MorphoBank.org";
50 }else{
51 }
52 }
53 if(($firstline>4)&&($firstline<(3+2+$taxa))){
54 my @splitlines=split(' ',$currentinput);
55 print $splitlines[0]."\t".$datatype."\t".$splitlines[0]."_".$datatype."\t".$splitlines[1]."\n";
56 }
57 $firstline++;
58 }