[Bio] / FigKernelPackages / FIGV.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/FIGV.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5, Tue Nov 28 22:21:58 2006 UTC revision 1.6, Tue Nov 28 23:16:55 2006 UTC
# Line 17  Line 17 
17    
18  package FIGV;  package FIGV;
19    
20    use Carp;
21  use strict;  use strict;
22  use FIG;  use FIG;
23  use FIG_Config;  use FIG_Config;
# Line 56  Line 57 
57  {  {
58      my($self, @args) = @_;      my($self, @args) = @_;
59    
60        if (ref($self) ne "FIGV") {
61            confess "BAD FIGV object passed to AUTOLOAD";
62        }
63    
64      my $meth = $AUTOLOAD;      my $meth = $AUTOLOAD;
65      $meth =~ s/.*:://;      $meth =~ s/.*:://;
66    
# Line 581  Line 586 
586      $self->{_ann} = $ann;      $self->{_ann} = $ann;
587  }  }
588    
589    sub taxonomy_of {
590        my($self,$genome) = @_;
591        my $fig     = $self->{_fig};
592        my $newG    = $self->{_genome};
593        my $newGdir = $self->{_orgdir};
594    
595        if ($newG ne $genome)
596        {
597            return $fig->taxonomy_of($genome);
598        }
599    
600        my $tax;
601        if (open(TAX,"<$newGdir/TAXONOMY") && ($tax = <TAX>))
602        {
603            chop $tax;
604            return $tax;
605        }
606        else
607        {
608            return "unknown";
609        }
610    }
611    
612    sub build_tree_of_complete {
613        my($self,$min_for_label) = @_;
614        return $self->build_tree_of_all($min_for_label, "complete");
615    }
616    
617    sub build_tree_of_all {
618        my($self, $min_for_label, $complete)=@_;
619        my(@last,@tax,$i,$prefix,$lev,$genome,$tax);
620    
621        $min_for_label = $min_for_label ? $min_for_label : 10;
622        open(TMP,">/tmp/tree$$") || die "could not open /tmp/tree$$";
623        print TMP "1. root\n";
624    
625        @last = ();
626    
627    
628        foreach $genome (grep { ! $self->is_environmental($_) } $self->sort_genomes_by_taxonomy($self->genomes($complete)))
629        {
630            $tax = $self->taxonomy_of($genome);
631            @tax = split(/\s*;\s*/,$tax);
632            push(@tax,$genome);
633            for ($i=0; ((@last > $i) && (@tax > $i) && ($last[$i] eq $tax[$i])); $i++) {}
634            while ($i < @tax)
635            {
636                $lev = $i+2;
637                $prefix = " " x (4 * ($lev-1));
638                print TMP "$prefix$lev\. $tax[$i]\n";
639                $i++;
640            }
641            @last = @tax;
642        }
643        close(TMP);
644        my $tree = &tree_utilities::build_tree_from_outline("/tmp/tree$$");
645        $tree->[0] = 'All';
646        &FIG::limit_labels($tree,$min_for_label);
647        unlink("/tmp/tree$$");
648        return ($tree,&tree_utilities::tips_of_tree($tree));
649    }
650    
651    sub sort_genomes_by_taxonomy {
652        my($self,@genomes) = @_;
653    
654        return map     { $_->[0] }
655               sort    { $a->[1] cmp $b->[1] }
656               map     { [$_,$self->taxonomy_of($_)] }
657               @genomes;
658    }
659    
660    sub taxonomic_groups_of_complete {
661        my($self,$min_for_labels) = @_;
662    
663        my($tree,undef) = $self->build_tree_of_complete($min_for_labels);
664        return &FIG::taxonomic_groups($tree);
665    }
666    
667  1;  1;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3