diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/phyloconversion/tnt2phytab.pl	Tue Mar 11 12:19:13 2014 -0700
@@ -0,0 +1,58 @@
+#!/usr/bin/perl
+
+use strict;
+
+my $file = $ARGV[0];
+
+# read file with genes
+open FILE, $file or die "ERROR: Cannot open file $file\n";
+my $firstline=0;
+my $datatype;
+my $taxa;
+while (<FILE>) {
+       my $currentinput = "$_";
+       if($firstline==0){
+               if($currentinput =~ m/nstates/){
+                       my @splitlines=split(' ',$currentinput);
+                       $splitlines[2] =~ s/\;//;
+                       if($splitlines[2] == 2){
+                               $datatype = "binary";
+                       }elsif($splitlines[2] > 2){
+                               $datatype = "multi";
+                       }
+               }else{
+                       die "ERROR: file does not begin with nstates line. Must be TNT file exported from MorphoBank.org";
+               }
+       }
+       if($firstline==1){
+               if($currentinput =~ m/xread/){
+               }else{
+                       die "ERROR: file does not contain xread line. Must be TNT file exported from MorphoBank.org";
+               }
+       }
+       if($firstline==2){
+               if($currentinput =~ m/Morpho/){
+               }else{
+                       die "ERROR: file does not contain Morphobank Comment line. Must be TNT file exported from MorphoBank.org";
+               }
+       }
+       if($firstline==3){
+               if($currentinput =~ m/\d/){
+                       my @splitlines=split(' ',$currentinput);
+                       $taxa = $splitlines[1]."\n";
+               }else{
+                       die "ERROR: file does not contain number of taxa. Must be TNT file exported from MorphoBank.org";
+               }
+       }
+       if($firstline==4){
+               if($currentinput =~ m/\d/){
+                       die "ERROR: file does not contain empty line after taxa numbers . Must be TNT file exported from MorphoBank.org";
+               }else{
+               }
+       }
+       if(($firstline>4)&&($firstline<(3+2+$taxa))){
+               my @splitlines=split(' ',$currentinput);
+               print $splitlines[0]."\t".$datatype."\t".$splitlines[0]."_".$datatype."\t".$splitlines[1]."\n";
+       }
+       $firstline++;
+}