#!perl -w use strict; =head1 NAME BioLibeg.pm - sample library =head1 DESCRIPTION A small testable function library. =head1 SYNOPSIS To use this module, add the line: use BioLibeg; Making sure the module is in the same directory or another place where Perl can find it. =head1 USAGE use BioLibeg qw/codon2aa count/; or use BioLibeg 0.001 qw/:all/; my $dna = "ATAGCATAG"; my $len = length $dna; my $protein = ""; for (my $index=0; $index<$len-2; $index=+3) { $protein .= codon2aa(substr($dna,$index,3); } print "DNA 2 PROTEIN: $dna => $protein\n"; my $count = count("t",$dna); print "Count of Ts: $count\n"; =head1 BUGS =head1 AUTHOR David Scott E<lt>leapingfrog@yahoo.comE<gt> =head1 Functions Functions follow in alphabetic order. =over 4 =cut package BioLibeg; use feature qw/switch/; BEGIN { use Exporter( ); our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = "0.001"; $VERSION = eval $VERSION; @ISA = qw/Exporter/; @EXPORT = ( ); %EXPORT_TAGS = ( all => [ qw/codon2aa count/ ], ); @EXPORT_OK = qw/codon2aa count/; } # functions needing a %genetic_code hash { my %genetic_code = ( 'TCA' => 'S', 'TCC' => 'S', 'TCG' => 'S', 'TCT' => 'S', # Serine 'TTC' => 'F', 'TTT' => 'F', # Phenylalanine 'TTA' => 'L', 'TTG' => 'L', # Leucine 'TAC' => 'Y', 'TAT' => 'Y', # Tyrosine 'TAA' => '_', 'TAG' => '_', # Stop 'TGC' => 'C', 'TGT' => 'C', # Cysteine 'TGA' => '_', # Stop 'TGG' => 'W', # Tryptophan 'CTA' => 'L', 'CTC' => 'L', 'CTG' => 'L', 'CTT' => 'L', # Leucine 'CCA' => 'P', 'CCC' => 'P', 'CCG' => 'P', 'CCT' => 'P', # Proline 'CAC' => 'H', 'CAT' => 'H', # Histidine 'CAA' => 'Q', 'CAG' => 'Q', # Glutamine 'CGA' => 'R', 'CGC' => 'R', 'CGG' => 'R', 'CGT' => 'R', # Arginine 'ATA' => 'I', 'ATC' => 'I', 'ATT' => 'I', # Isoleucine 'ATG' => 'M', # Methionine 'ACA' => 'T', 'ACC' => 'T', 'ACG' => 'T', 'ACT' => 'T', # Threonine 'AAC' => 'N', 'AAT' => 'N', # Asparagine 'AAA' => 'K', 'AAG' => 'K', # Lysine 'AGC' => 'S', 'AGT' => 'S', # Serine 'AGA' => 'R', 'AGG' => 'R', # Arginine 'GTA' => 'V', 'GTC' => 'V', 'GTG' => 'V', 'GTT' => 'V', # Valine 'GCA' => 'A', 'GCC' => 'A', 'GCG' => 'A', 'GCT' => 'A', # Alanine 'GAC' => 'D', 'GAT' => 'D', # Aspartic Acid 'GAA' => 'E', 'GAG' => 'E', # Glutamic Acid 'GGA' => 'G', 'GGC' => 'G', 'GGG' => 'G', 'GGT' => 'G', # Glycine ); =item $amino_acid = codon2aa($codon); Translate a DNA 3-character codon to an amino acid. Any missing entry translates to '*'. =cut sub codon2aa { my($codon) = @_; $codon = uc $codon; return $genetic_code{$codon} || "*"; } } =item $count = count($char, $dna); Return a count of $char in the $dna string. If it is not a dna nucleotide return -1. =cut sub count { my ($char, $dna) = @_; my $count = 0; given ($char) { when ( /t|T/ ) { $count = ($dna =~ tr/Tt//); } when ( /a|A/ ) { $count = ($dna =~ tr/Aa//); } when ( /g|G/ ) { $count = ($dna =~ tr/Gg//); } when ( /c|C/ ) { $count = ($dna =~ tr/Cc//); } default { $count = -1; } } return $count; } 1; __END__