Bio::NEXUS::SetsBlock - Represents SETS block of a NEXUS file


NAME

Bio::NEXUS::SetsBlock - Represents SETS block of a NEXUS file


SYNOPSIS

$block_object = new Bio::NEXUS::SetsBlock($block_type, $block, $verbose);


DESCRIPTION

Parses Sets block of NEXUS file and stores Sets data.


FEEDBACK

All feedback (bugs, feature enhancements, etc.) are greatly appreciated.


AUTHORS

 Thomas Hladish (tjhladish at yahoo)


VERSION

$Revision: 1.26 $


METHODS

new

 Title   : new
 Usage   : $block_object = new Bio::NEXUS::SetsBlock($block_type, $commands, $verbose)
 Function: Creates a new Bio::NEXUS::SetsBlock object
 Returns : Bio::NEXUS::SetsBlock object
 Args    : type (string), the commands/comments to parse (array ref), and a verbose flag (0 or 1)

set_taxsets

 Title   : set_taxsets
 Usage   : $block->set_taxsets($taxsets);
 Function: Set the taxsets hash
 Returns : none
 Args    : hash of set name keys and element arrays

add_taxsets

 Title   : add_taxsets
 Usage   : $block->add_taxsets($taxsets);
 Function: add taxa sets
 Returns : none
 Args    : a reference to a hash of taxa sets

get_taxsets

 Title   : get_taxsets
 Usage   : $block->get_taxsets();
 Function: Returns a hash of taxa sets
 Returns : taxa sets
 Args    : none

get_taxset

 Title   : get_taxset
 Usage   : $block->get_taxset($setname);
 Function: Returns a list of OTU's
 Returns : OTU's
 Args    : none

get_taxset_names

 Title     : get_taxset_names
 Usage     : $block->get_taxset_names()
 Function: gets the names of all sets
 Returns : array of names
 Args     : none

=cut

sub get_taxset_names { my ($self) = @_; return [ sort keys %{ $self->{'taxsets'} } ]; }

print_all_taxsets

 Title     : print_all_taxsets
 Usage     : $block->print_all_taxsets($outfile)
 Function: prints set names and elements
 Returns : none
 Args     : filename or filehandle

=cut

sub print_all_taxsets { my ( $self, $outfile ) = @_; my $fh; if ( $outfile eq ``-'' || $outfile eq \*STDOUT ) { $fh = \*STDOUT; } else { open( $fh, ``>$outfile'' ) || croak ``Could not open $outfile for writing\n''; }

    for my $setname ( sort keys %{ $self->{'taxsets'} } ) {
        print $fh "$setname = [@{$self->{'taxsets'}->{$setname}}]\n\n";
    }
}

delete_taxsets

 Title     : delete_taxsets
 Usage     : $block->delete_taxsets($set1 [$set2 $set3 ...])
 Function: Removes the named sets from the Sets block
 Returns : none
 Args     : Names of sets to be deleted

exclude_otus

 Title     : exclude_otus
 Usage     : $block->exclude_otus($otu_array_ref)
 Function: Finds and deletes each of the given otus from any sets they appear in
 Returns : none
 Args     : Names of otus to be removed

=cut

sub exclude_otus { my ( $self, $otus_to_remove ) = @_; for my $setname ( keys %{ $self->{'taxsets'} } ) { for ( my $i = 0; $i < @{ $self->{'taxsets'}{$setname} }; $i++ ) { for my $otu_to_remove (@$otus_to_remove) { if ( $self->{'taxsets'}->{$setname}[$i] eq $otu_to_remove ) { splice( @{ $self->{'taxsets'}{$setname} }, $i, 1 ); } } } } }

select_otus

 Title     : select_otus
 Usage     : $block->select_otus($otu_array_ref)
 Function: Finds the given otus and removes all others from any sets they appear in
 Returns : none
 Args     : Names of otus to be removed

=cut

sub select_otus { my ( $self, $otus_to_keep ) = @_; my $newsets; for my $setname ( keys %{ $self->{'taxsets'} } ) { $$newsets{$setname} = []; for my $otu_element ( @{ $self->{'taxsets'}{$setname} } ) { for my $otu_to_keep (@$otus_to_keep) { if ( $otu_element eq $otu_to_keep ) { push( @{ $$newsets{$setname} }, $otu_to_keep ); } } } } $self->set_taxsets($newsets); }

rename_otus

 Title   : rename_otus
 Usage   : $block->rename_otus($names);
 Function: rename all OTUs
 Returns : none
 Args    : hash of OTU names

rename_taxsets

 Title     : rename_taxsets
 Usage     : $block->rename_taxsets($oldsetname1, $newsetname1, ...)
 Function: Renames sets
 Returns : none
 Args     : Oldname, newname pairs

equals

 Name    : equals
 Usage   : $setsblock->equals($another);
 Function: compare if two Bio::NEXUS::SetsBlock objects are equal
 Returns : boolean 
 Args    : a Bio::NEXUS::SetsBlock object

 Bio::NEXUS::SetsBlock - Represents SETS block of a NEXUS file