Bio::Align Utilities
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Summary
Bio::Align::Utilities - A collection of utilities regarding converting
and manipulating alignment objects
Package variables
No package variables defined.
Included modules
Bio::Root::Version
Carp
Inherit
Exporter
Synopsis
  use Bio::Align::Utilities qw(:all);
# %dnaseqs is a hash of CDS sequences (spliced)
# Even if the protein alignments are local make sure the start/end # stored in the LocatableSeq objects are to the full length protein. # The CoDing Sequence that is passed in should still be the full # length CDS as the nt alignment will be generated. # my $dna_aln = &aa_to_dna_aln($aa_aln,\%dnaseqs); # generate bootstraps my $replicates = &bootstrap_replicates($aln,$count);
Description
This module contains utility methods for manipulating sequence
alignments ( Bio::Align::AlignI) objects.
The aa_to_dna_aln utility is essentially the same as the mrtrans
program by Bill Pearson available at
ftp://ftp.virginia.edu/pub/fasta/other/mrtrans.shar. Of course this
is a pure-perl implementation, but just to mention that if anything
seems odd you can check the alignments generated against Bill's
program.
Methods
BEGIN Code
aa_to_dna_alnDescriptionCode
bootstrap_replicatesDescriptionCode
Methods description
aa_to_dna_alncode    nextTop
 Title   : aa_to_dna_aln
Usage : my $dnaaln = aa_to_dna_aln($aa_aln, \%seqs);
Function: Will convert an AA alignment to DNA space given the
corresponding DNA sequences. Note that this method expects
the DNA sequences to be in frame +1 (GFF frame 0) as it will
start to project into coordinates starting at the first base of
the DNA sequence, if this alignment represents a different
frame for the cDNA you will need to edit the DNA sequences
to remove the 1st or 2nd bases (and revcom if things should be).
Returns : Bio::Align::AlignI object
Args : 2 arguments, the alignment and a hashref.
Alignment is a Bio::Align::AlignI of amino acid sequences.
The hash reference should have keys which are
the display_ids for the aa
sequences in the alignment and the values are a
Bio::PrimarySeqI object for the corresponding
spliced cDNA sequence.
See also: Bio::Align::AlignI, Bio::SimpleAlign, Bio::PrimarySeq
bootstrap_replicatescodeprevnextTop
 Title   : bootstrap_replicates
Usage : my $alns = &bootstrap_replicates($aln,100);
Function: Generate a pseudo-replicate of the data by randomly
sampling, with replacement, the columns from an alignment for
the non-parametric bootstrap.
Returns : Arrayref of Bio::SimpleAlign objects
Args : Bio::SimpleAlign object
Number of replicates to generate
Methods code
BEGINTop
BEGIN {
    use constant CODONSIZE => 3;
    $GAP = '-';
    $CODONGAP = $GAP x CODONSIZE;
}
aa_to_dna_alndescriptionprevnextTop
sub aa_to_dna_aln {
    my ($aln,$dnaseqs) = @_;
    unless( defined $aln && 
	    ref($aln) &&
	    $aln->isa('Bio::Align::AlignI') ) { 
	croak('Must provide a valid Bio::Align::AlignI object as the first argument to aa_to_dna_aln, see the documentation for proper usage and the method signature');
    }
    my $alnlen = $aln->length;
    my $dnaalign = new Bio::SimpleAlign;
    $aln->map_chars('\.',$GAP);

    foreach my $seq ( $aln->each_seq ) {    
	my $aa_seqstr = $seq->seq();
	my $id = $seq->display_id;
	my $dnaseq = $dnaseqs->{$id} || $aln->throw("cannot find ".
						     $seq->display_id);
	my $start_offset = ($seq->start - 1) * CODONSIZE;

	$dnaseq = $dnaseq->seq();
	my $dnalen = $dnaseqs->{$id}->length;
	my $nt_seqstr;
	my $j = 0;
	for( my $i = 0; $i < $alnlen; $i++ ) {
	    my $char = substr($aa_seqstr,$i + $start_offset,1);	    
	    if ( $char eq $GAP || $j >= $dnalen )  { 
		$nt_seqstr .= $CODONGAP;
	    } else {
		$nt_seqstr .= substr($dnaseq,$j,CODONSIZE);
		$j += CODONSIZE;
	    }
	}
	$nt_seqstr .= $GAP x (($alnlen * 3) - length($nt_seqstr));

	my $newdna = new Bio::LocatableSeq(-display_id  => $id,
					   -alphabet    => 'dna',
					   -start       => $start_offset+1,
					   -end         => ($seq->end * 
							    CODONSIZE),
					   -strand      => 1,
					   -seq         => $nt_seqstr);    
	$dnaalign->add_seq($newdna);
    }
    return $dnaalign;
}
bootstrap_replicatesdescriptionprevnextTop
sub bootstrap_replicates {
   my ($aln,$count) = @_;
   $count ||= 1;
   my $alen = $aln->length;
   my (@seqs,@nm);
   $aln->set_displayname_flat(1);
   for my $s ( $aln->each_seq ) {
       push @seqs, $s->seq();
       push @nm, $s->id;
   }
   my (@alns,$i);
   while( $count-- > 0 ) {
       my @newseqs;
       for($i =0; $i < $alen; $i++ ) {
	   my $index = int(rand($alen));
	   my $c = 0;
	   for ( @seqs ) {
	       $newseqs[$c++] .= substr($_,$index,1);
	   }
       }
       my $newaln = Bio::SimpleAlign->new();
       my $i = 0;
       for my $s ( @newseqs ) {

	   $newaln->add_seq( Bio::LocatableSeq->new
			     (-start         => 1,
			      -end           => $alen,
			      -display_id    => $nm[$i++],
			      -seq           => $s));
       }
       push @alns, $newaln;
   }
   return\@ alns;
}
General documentation
FEEDBACKTop
Mailing ListsTop
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to
the Bioperl mailing list. Your participation is much appreciated.
  bioperl-l@bioperl.org                  - General discussion
http://bioperl.org/wiki/Mailing_lists - About the mailing lists
Reporting BugsTop
Report bugs to the Bioperl bug tracking system to help us keep track
of the bugs and their resolution. Bug reports can be submitted via the
web:
  http://bugzilla.open-bio.org/
AUTHOR - Jason StajichTop
Email jason@bioperl.org
APPENDIXTop
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _