Skip to content

Instantly share code, notes, and snippets.

@pcantalupo
Created February 18, 2013 14:22
Show Gist options
  • Save pcantalupo/4977773 to your computer and use it in GitHub Desktop.
Save pcantalupo/4977773 to your computer and use it in GitHub Desktop.
mono and dinucleotide frequency methods for Bio::SeqUtils
=head2 monofreq
Title : monofreq
Usage : $seq = Bio::SeqUtils->monofreq($seq)
Function: Method for determining the mononucleotide frequencies of
a DNA sequence
Returns : Array of mononucleotide frequencies T, C, G, A
Args : none
=cut
sub monofreq {
my ($self, $seq) = @_;
$seq->isa('Bio::PrimarySeqI') ||
$self->throw("Not a Bio::PrimarySeqI object but [$self]");
$seq->alphabet =~ /DNA/i ||
$self->throw('Not a DNA sequence');
my $DNA = $seq->seq;
my $Total = $seq->length;
my $T=($DNA=~tr/T//); my $C=($DNA=~tr/C//); my $G=($DNA=~tr/G//); my $A=($DNA=~tr/A//);
my $Tper = $T/$Total; my $Cper = $C/$Total; my $Gper = $G/$Total; my $Aper = $A/$Total;
return ($Tper, $Cper, $Gper, $Aper);
}
=head2 dinucbias
Title : dinucbias
Usage : $seq = Bio::SeqUtils->dinucbias($seq)
Function: Method for determining the dinucleotide bias
frequencies for a DNA sequence
Returns : Array of dinucleotide bias frequencies TT, TC, ...CT,..GT,..AT,AC,AG,AA
Args : none
=cut
sub dinucbias {
my ($self, $seq) = @_;
$seq->isa('Bio::PrimarySeqI') ||
$self->throw("Not a Bio::PrimarySeqI object but [$self]");
$seq->alphabet =~ /DNA/i ||
$self->throw('Not a DNA sequence');
# needs implemented
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment