Bio::Tools::SeqPattern
Backtranslate
Toolbar
Summary
Bio::Tools::SeqPattern::Backtranslate
Package variables
Privates (from "my" definitions)
( @codon_library, $ct );
%convert;
Included modules
Carp qw ( croak )
List::MoreUtils qw ( uniq )
Inherit
Synopsis
No synopsis!
Description
This module should not be used directly. It provides helper methods to
Bio::Tools::SeqPattern to reverse translate protein patterns.
Methods
| _reverse_translate_motif | No description | Code |
| _parse_motif | No description | Code |
| _tokenize_motif | No description | Code |
| _contract_codons | No description | Code |
| _expand_codon | No description | Code |
| _convert | No description | Code |
| _uniq_string | No description | Code |
| _negated_aas_to_codon | No description | Code |
Methods description
None available.
Methods code
| _reverse_translate_motif | description | prev | next | Top |
sub _reverse_translate_motif
{
my $motif = shift;
$motif =~ s/\./X/g;
$motif = uc $motif;
my ( $ordered, $classified ) = _parse_motif($motif);
my $ct = Bio::Tools::CodonTable->new;
foreach my $seq ( @{ $classified->{plain} } ) {
my $seqO
= Bio::Seq->new( -seq => $$seq, -alphabet => 'protein' );
$$seq = $ct->reverse_translate_all($seqO);
}
foreach my $token ( @{ $classified->{ambiguous} } ) {
my ($aas) = $$token =~ m(([A-Za-z\.]+));
my @codons_to_contract;
foreach my $residue ( split '', $aas ) {
push @codons_to_contract, $ct->revtranslate($residue);
}
my $ambiguous_codon = _contract_codons(@codons_to_contract);
$$token = $ambiguous_codon;
}
foreach my $token ( @{ $classified->{negated} } ) {
my ($aas) = $$token =~ m(([A-Za-z\.]+));
my $ambiguous_codon = _negated_aas_to_codon($aas);
$$token = $ambiguous_codon;
}
return join '', map {$$_} @{$ordered}; } |
sub _parse_motif
{
my $motif = shift;
my $parser = _tokenize_motif($motif);
my ( %tokens, @tokens );
while ( my $token = $parser->() ) {
croak ("Unknown syntax token: <", $token->[1], ">")
if ( $token->[0] eq 'UNKNOWN' );
push @{ $tokens{ $token->[0] } },\$ token->[1];
push @tokens,\$ token->[1];
}
return (\@ tokens,\% tokens ); } |
sub _tokenize_motif
{
my $target = shift;
return sub {
return [ 'ambiguous', $1 ]
if $target =~ /\G (\[[A-Za-z\.]+\]) /gcx;
return [ 'negated', $1 ]
if $target =~ /\G (\[\^[A-Za-z\.]+\]) /gcx;
return [ 'plain', $1 ]
if $target =~ /\G ([A-Za-z\.]+) /gcx;
return [ 'open_par', $1 ]
if $target =~ /\G (\() /gcx;
return [ 'close_par', $1 ]
if $target =~ /\G (\)[\{\d+[,\d+]*\}]*) /gcx;
return [ 'UNKNOWN', $1 ]
if $target =~ /\G (.) /gcx;
return;
}; } |
sub _contract_codons
{
my @codons = map { uc $_ } @_;
my @by_letter = ( [], [], [], );
my $ambiguous_codon;
foreach my $codon (@codons) {
my @letters = split '', $codon;
for my $i ( 0 .. 2 ) {
push @{ $by_letter[$i] }, $letters[$i];
}
}
for my $i ( 0 .. 2 ) {
$ambiguous_codon
.= _convert( 'dna', _uniq_string( @{ $by_letter[$i] } ) );
}
return $ambiguous_codon; } |
sub _expand_codon
{
my $codon = shift;
die "Wrong codon length!\n" if length $codon != 3;
my ( @codons, @return_bases );
my @orig_bases = split '', $codon;
for my $i ( 0 .. 2 ) {
my @components = split '', _convert('dna', $orig_bases[$i] );
$orig_bases[$i] = [@components];
}
for my $i ( @{ $orig_bases[0] } ) {
for my $j ( @{ $orig_bases[1] } ) {
for my $k ( @{ $orig_bases[2] } ) {
push @return_bases, $i . $j . $k;
}
}
}
return @return_bases;
}
{
my %convert; } |
sub _convert
{
my ($alphabet, $letter) = @_;
unless (
$alphabet and $alphabet =~ /^dna$|^protein$/i
and $letter and length $letter <= 4
) { croak "Wrong arguments!\n"; }
unless (%convert) {
%convert = (
'dna' => {
qw(N ACGT B CGT D AGT H ACT V ACG K GT
M AC R AG S CG W AT Y CT A A C C T T G G)
},
'protein' => {
'.' => 'ACDEFGHIJKLMNOPQRSTUVWY',
X => 'ACDEFGHIJKLMNOPQRSTUVWY',
Z => 'QE',
B => 'ND',
},
);
foreach my $alphabet ( keys %convert ) {
map { $convert{$alphabet}->{ $convert{$alphabet}{$_} } = $_ }
keys %{ $convert{$alphabet} };
}
}
return $convert{$alphabet}{$letter};
} } |
sub _uniq_string
{
my @letters = @_;
return join '', sort { $a cmp $b } uniq @letters;
}
{
my ( @codon_library, $ct ); } |
| _negated_aas_to_codon | description | prev | next | Top |
sub _negated_aas_to_codon
{
my $aas_to_avoid = shift;
unless (@codon_library) {
while (<DATA>) { chomp; push @codon_library, split ' ', $_ }
}
unless ($ct) { $ct = Bio::Tools::CodonTable->new; }
my @unwanted_codons;
foreach my $aa ( split '', $aas_to_avoid ) {
push @unwanted_codons, $ct->revtranslate($aa);
}
foreach my $degenerate_codon (@codon_library) {
my @codons = _expand_codon($degenerate_codon);
my $success = 1;
foreach my $unwanted (@unwanted_codons) {
if ( grep { uc $unwanted eq $_ } @codons ) {
$success = 0;
}
}
if ($success) { return $degenerate_codon }
}
}
}
1;} |
General documentation
Copyright 2009 Bruno Vecchi, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.