Bio::Tools::Alignment
Trim
Toolbar
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
use Bio::Tools::Alignment::Trim;
$o_trim = new Bio::Tools::Alignment::Trim;
$o_trim->set_reverse_designator("R");
$o_trim->set_forward_designator("F");
Description
This is a specialized module designed by Chad for Chad to trim sequences
based on a highly specialized list of requirements. In other words, write
something that will trim sequences 'just like the people in the lab would
do manually'.
I settled on a sliding-window-average style of search which is ugly and
slow but does _exactly_ what I want it to do.
Mental note: rewrite this.
It is very important to keep in mind the context in which this module was
written: strictly to support the projects for which Consed.pm was
designed.
Methods
Methods description
_get_end($r_qual,$windowsize,$phreds,$count) | code | | next | Top |
Title : _get_end($r_qual,$windowsize,$phreds,$count) Usage : my $end_base = &_get_end($r_windows,20,20,$start_base); Function: Get the end trim point for this sequence. Returns : A scalar representing the end trim point for this sequence. Args : $r_qual : A reference to an array containing quality values. In context, this array of values has been smoothed by then sliding window-look ahead algorithm. $windowsize : The size of the window used when the sliding window look-ahead average was calculated. $phreds : <fill in what this does here> $count : Start looking for the end of the sequence here. |
Title : _get_end_old($r_qual,$windowsize,$phreds,$count) Usage : Deprecated. Don't use this! Returns : Deprecated. Don't use this! Args : Deprecated. Don't use this! |
Title : _get_start($r_quals,$windowsize,$phreds,$offset) Usage : $start_base = $self->_get_start($r_windows,5,20); Function: Provide the start trim point for this sequence. Returns : a scalar representing the start of the sequence Args : $r_quals : A reference to an array containing quality values. In context, this array of values has been smoothed by then sliding window-look ahead algorithm. $windowsize : The size of the window used when the sliding window look-ahead average was calculated. $phreds : <fill in what this does here> $offset : <fill in what this does here> |
Title : _print_formatted_qualities(\@quals) Usage : &_print_formatted_qualities(\@quals); Returns : Nothing. Prints. Args : A reference to an array containing quality values. Notes : An internal procedure used in debugging. Prints out an array nicely. |
Title : _sliding_window($r_quals,$windowsize) Usage : my $r_windows = &_sliding_window(\@qual,$windowsize); Function: Create a sliding window, look-forward-average on an array of quality values. Used to smooth out differences in qualities. Returns : A reference to an array containing the smoothed values. Args : $r_quals: A reference to an array containing quality values. $windowsize : The size of the sliding window. Notes : This was written before PrimaryQual objects existed. They should use that object but I haven't rewritten this yet. |
Title : chop_sequence($name,$class,$sequence,@points) Usage : ($start_point,$end_point,$chopped_sequence) = $o_trim->chop_sequence($name,$class,$sequence,@points); Function: Chop a sequence based on its name, class, and sequence. Returns : an array containing three scalars: 1- the start trim point 2- the end trim point 3- the chopped sequence Args : $name : the name of the sequence $class : The class of the sequence. One of qw(singlet singleton doublet pair multiplet) $sequence : A sequence @points : An array containing two elements- the first contains the start trim point and the second conatines the end trim point. |
Title : count_doublet_trailing_zeros($r_qual) Usage : my $start_of_trailing_zeros = &count_doublet_trailing_zeros(\@qual); Function: Find out when the trailing zero qualities start. Returns : A scalar representing where the zeros start. Args : A reference to an array of quality values. Notes : Again, this should be rewritten to use PrimaryQual objects. A more detailed explanation of why phrap puts these zeros here should be written and placed here. Please email and hassle the author. |
Title : dump_hash() Usage : $o_trim->dump_hash() Function: Unimplemented. Returns : Nothing. Args : None. Notes : Does nothing. |
Title : get_designators() Usage : $o_trim->get_designators() Returns : A string describing the current designators. Args : None Notes : Really for informational purposes only. Duh. |
Title : new() Usage : $o_trim = Bio::Tools::Alignment::Trim->new(); Function: Construct the Bio::Tools::Alignment::Trim object. No parameters are required to create this object. It is strictly a bundle of functions, as far as I am concerned. Returns : A reference to a Bio::Tools::Alignment::Trim object. Args : (optional) -windowsize (default 10) -phreds (default 20) |
Title : set_designators(<forward>,<reverse>) Usage : $o_trim->set_designators("F","R") Function: Set the string by which the system determines whether a given sequence represents a forward or a reverse read. Returns : Nothing. Args : two scalars: one representing the forward designator and one representing the reverse designator |
Title : set_forward_designator($designator) Usage : $o_trim->set_forward_designator("F") Function: Set the string by which the system determines if a given sequence is a forward read. Returns : Nothing. Args : A string representing the forward designator of this project. |
Title : set_reverse_designator($reverse_designator) Function: Set the string by which the system determines if a given sequence is a reverse read. Usage : $o_trim->set_reverse_designator("R") Returns : Nothing. Args : A string representing the forward designator of this project. |
Title : trim_doublet($sequence,$quality,$name,$class) Usage : ($r_trim_points,$trimmed_sequence) = @{$o_trim->trim_singlet($sequence,$quality,$name,$class)}; Function: Trim a singlet based on its quality. Returns : a reference to an array containing the forward and reverse Args : $sequence : A sequence $quality : A _scalar_ of space-delimited quality values. $name : the name of the sequence $class : The class of the sequence. One of qw(singlet singleton doublet pair multiplet) Notes : At the time this was written the bioperl objects SeqWithQuality and PrimaryQual did not exist. This is what is with the clumsy passing of references and so on. I will rewrite this next time I have to work with it. I also wasn't sure whether this function should return just the trim points or the points and the sequence. I decided that I always wanted both so that's how I implemented it. |
Title : trim_leading_polys() Usage : $o_trim->trim_leading_polys() Function: Not implemented. Does nothing. Returns : Nothing. Args : None. Notes : This function is not implemented. Part of something I wanted to do but never got around to doing. |
Title : trim_singlet($sequence,$quality,$name,$class) Usage : ($r_trim_points,$trimmed_sequence) = @{$o_trim->trim_singlet($sequence,$quality,$name,$class)}; Function: Trim a singlet based on its quality. Returns : a reference to an array containing the forward and reverse trim points and the trimmed sequence. Args : $sequence : A sequence (SCALAR, please) $quality : A _scalar_ of space-delimited quality values. $name : the name of the sequence $class : The class of the sequence. One of qw(singlet singleton doublet pair multiplet) Notes : At the time this was written the bioperl objects SeqWithQuality and PrimaryQual did not exist. This is what is with the clumsy passing of references and so on. I will rewrite this next time I have to work with it. I also wasn't sure whether this function should return just the trim points or the points and the sequence. I decided that I always wanted both so that's how I implemented it. - Note that the size of the sliding windows is set during construction of the Bio::Tools::Alignment::Trim object. |
Methods code
BEGIN { %DEFAULTS = ( 'f_designator' => 'f',
'r_designator' => 'r',
'windowsize' => '10',
'phreds' => '20'); } |
sub _get_end
{ my ($r_qual,$windowsize,$phreds,$count) = @_;
my @quals = @$r_qual;
my $total_bases = scalar(@quals);
my ($count2,$qualsum,$end_of_quals,$bases_counted);
if (!$count) { $count=0; }
BASE: for (; $count < $total_bases; $count++) {
$bases_counted = 0;
$qualsum = 0;
POSITION: for($count2 = $count; $count2 < $total_bases; $count2++) {
$bases_counted++;
if ($count2 == $total_bases-1) {
$qualsum += $quals[$count2];
$bases_counted++;
last BASE;
}
elsif ($bases_counted == $windowsize) {
$qualsum += $quals[$count2];
if ($qualsum < $bases_counted*$phreds) {
return $count+$bases_counted+$windowsize;
}
next BASE;
}
else {
$qualsum += $quals[$count2];
}
}
if ($qualsum < $bases_counted*$phreds) {
return $count+$bases_counted+$windowsize;
}
else { }
$qualsum = 0;
} if ($end_of_quals) {
my $bases_for_average = $total_bases-$count2;
return $count2;
}
else { }
if ($qualsum) { } return $total_bases;
}
} |
sub _get_end_old
{ my ($r_qual,$windowsize,$phreds,$count) = @_;
warn("Do Not Use this function (_get_end_old)");
my $target = $windowsize*$phreds;
my @quals = @$r_qual;
my $total_bases = scalar(@quals);
my ($count2,$qualsum,$end_of_quals);
if (!$count) { $count=0; }
BASE: for (; $count < $total_bases; $count++) {
for($count2 = $count; $count2 < $count+$windowsize; $count2++) {
if ($count2 == scalar(@quals)-1) {
$qualsum += $quals[$count2];
$end_of_quals = 1;
last BASE;
}
$qualsum += $quals[$count2];
}
if ($qualsum < $windowsize*$phreds) {
return $count+$windowsize;
}
$qualsum = 0;
} }
1;
__END__ } |
sub _get_start
{ my ($self,$r_quals,$windowsize,$phreds,$offset) = @_;
print("Using $phreds phreds\n") if $self->verbose > 0;
my @quals = @$r_quals;
my ($count,$count2,$qualsum);
if ($offset) { $count = $offset; } else { $count = 0; }
for (; ($count+$windowsize) <= scalar(@quals); $count++) {
my $cumulative=0;
for($count2 = $count; $count2 < $count+$windowsize; $count2++) {
if (!$quals[$count2]) {
}
else {
$qualsum += $quals[$count2];
}
$cumulative++;
}
if ($qualsum && $qualsum >= $windowsize*$phreds) { return $count; }
$qualsum = 0;
}
return $count; } |
sub _print_formatted_qualities
{ my $rquals = shift;
my @qual = @$rquals;
for (my $count=0; $count<scalar(@qual) ; $count++) {
if (($count%10)==0) { print("\n$count\t"); }
if ($qual[$count]) { print ("$qual[$count]\t");}
else { print("0\t"); }
}
print("\n"); } |
sub _sliding_window
{ my ($r_quals,$windowsize) = @_;
my (@window,@quals,$qualsum,$count,$count2,$average,@averages,$bases_counted);
@quals = @$r_quals;
my $size_of_quality = scalar(@quals);
for ($count=0; $count <= $size_of_quality; $count++) {
$bases_counted = 0;
BASE: for($count2 = $count; $count2 < $size_of_quality; $count2++) {
$bases_counted++;
if ($count2 == $size_of_quality) {
$qualsum += $quals[$count2];
last BASE;
}
elsif ($bases_counted == $windowsize) {
$qualsum += $quals[$count2];
last BASE;
}
unless (!$quals[$count2]) {
$qualsum += $quals[$count2];
}
}
unless (!$qualsum || !$windowsize) {
$average = $qualsum / $bases_counted; if (!$average) { $average = "0"; }
push @averages,$average;
}
$qualsum = 0;
}
return\@ averages; } |
sub chop_sequence
{ my ($self,$name,$class,$sequence,@points) = @_;
print("Coming into chop_sequence,\@ points are @points\n");
my $fdesig = $self->{'f_designator'};
my $rdesig = $self->{'r_designator'};
if (!$points[0] && !$points[1]) {
$sequence = "junk";
return $sequence;
}
if ($class eq "singlet" && $name =~ /$fdesig$/) {
$sequence = substr($sequence,$points[0],$points[1]-$points[0]);
}
elsif ($class eq "singlet" && $name =~ /$rdesig$/) {
$sequence = substr($sequence,$points[0],$points[1]-$points[0]);
}
elsif ($class eq "singleton" && $name =~ /$fdesig$/) {
$sequence = substr($sequence,$points[0],$points[1]-$points[0]);
}
elsif ($class eq "singleton" && $name =~ /$rdesig$/) {
$sequence = substr($sequence,$points[0],$points[1]-$points[0]);
}
elsif ($class eq "doublet") {
$sequence = substr($sequence,$points[0],$points[1]-$points[0]);
}
my $length_before_trimming = length($sequence);
my $subs_Xs = $sequence =~ s/^.*[Xx]{5,}//g;
if ($subs_Xs) {
my $length_after_trimming = length($sequence);
my $number_Xs_trimmed = $length_before_trimming - $length_after_trimming;
$points[0] += $number_Xs_trimmed;
}
$length_before_trimming = length($sequence);
my $subs_Ns = $sequence =~ s/[Nn]{1,}$//g;
if ($subs_Ns) {
my $length_after_trimming = length($sequence);
my $number_Ns_trimmed = $length_before_trimming - $length_after_trimming;
$points[1] -= $number_Ns_trimmed;
$points[1] -= 1;
}
push @points,$sequence;
print("chop_sequence\@ points are @points\n");
return @points; } |
sub count_doublet_trailing_zeros
{ my ($r_qual) = shift;
my $number_of_trailing_zeros = 0;
my @qualities = @$r_qual;
for (my $current=scalar(@qualities);$current>0;$current--) {
if ($qualities[$current] && $qualities[$current] != 0) {
$number_of_trailing_zeros = scalar(@qualities)-$current;
return $current+1;
}
}
return scalar(@qualities);
}
} |
sub dump_hash
{ my $self = shift;
my %hash = %{$self->{'qualities'}};
}
} |
sub get_designators
{ my $self = shift;
return("forward: ".$self->{'f_designator'}." reverse: ".$self->{'r_designator'}); } |
sub new
{ my ($class,@args) = @_;
my $self = $class->SUPER::new(@args);
my($windowsize,$phreds) =
$self->_rearrange([qw(
WINDOWSIZE
PHREDS
)],
@args);
$self->{windowsize} = $windowsize || $DEFAULTS{'windowsize'};
$self->{phreds} = $phreds || $DEFAULTS{'phreds'};
$self->set_designators($DEFAULTS{'f_designator'},
$DEFAULTS{'r_designator'});
return $self; } |
sub set_designators
{ my $self = shift;
($self->{'f_designator'},$self->{'r_designator'}) = @_; } |
sub set_forward_designator
{ my ($self,$desig) = @_;
$self->{'f_designator'} = $desig; } |
sub set_reverse_designator
{ my ($self,$desig) = @_;
$self->{'r_designator'} = $desig; } |
sub trim_doublet
{ my ($self,$sequence,$quality,$name,$class) = @_;
my @qual = split(' ',$quality);
my @points;
my $sequence_length = length($sequence);
my ($returnstring,$processed_sequence);
my $r_windows = &_sliding_window(\@qual,$self->{windowsize});
my $offset = 0;
for (my $current = 0; $current<$sequence_length;$current++) {
if ($qual[$current] != 0) {
$offset = $current;
last;
}
}
my $start_base = $self->_get_start($r_windows,$self->{windowsize},$self->{phreds},$offset);
if ($start_base > ($sequence_length - 100)) {
$points[0] = ("FAILED");
$points[1] = ("FAILED");
return @points;
}
$points[0] = $start_base;
my $end_base = $sequence_length;
my $start_of_trailing_zeros = &count_doublet_trailing_zeros(\@qual);
$points[1] = $end_base;
return @points;
}
} |
sub trim_leading_polys
{ my ($self, $sequence) = @_; } |
sub trim_singlet
{ my ($self,$sequence,$quality,$name,$class) = @_;
my @qual = split(' ',$quality);
my @points;
my $sequence_length = length($sequence);
my ($returnstring,$processed_sequence);
my $r_windows = &_sliding_window(\@qual,$self->{windowsize});
my $start_base = $self->_get_start($r_windows,$self->{windowsize},$self->{phreds});
my (@new_points,$trimmed_sequence);
$points[0] = $start_base;
my $end_base = &_get_end($r_windows,$self->{windowsize},
$self->{phreds},$start_base);
$points[1] = $end_base;
return\@ points; } |
General documentation
Bio::Tools::Alignment::Trim - A kludge to do specialized trimming of
sequence based on quality.
User feedback is an integral part of the evolution of this and other
Bioperl modules. Send your comments and suggestions preferably to one
of the Bioperl mailing lists. Your participation is much appreciated.
bioperl-l@bioperl.org - General discussion
http://bio.perl.org/MailList.html - About the mailing
lists
Report bugs to the Bioperl bug tracking system to help us keep track
the bugs and their resolution. Bug reports can be submitted via
email or the web:
bioperl-bugs@bio.perl.org
http://bugzilla.bioperl.org/
AUTHOR - Chad Matsalla | Top |
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _