[Bioperl-l] Reverse Comp Coding Puzzler
shawnh at fugu-sg.org
shawnh@fugu-sg.org
Mon Jan 13 17:01:37 EST 2003
Interesting..had a look around perlmonks.com, adopting a solution found here:
http://perlmonks.thepen.com/154008.html
my @M = qw(ATG);
my @P = qw(CCA CCC CCG CCT);
my @V = qw(GTA GTC GTG GTT);
my @A = qw(GCA GCC GCG GCT);
my @R = qw(CGA CGC CGG CGT AGA AGG);
my @D = qw(GAC GAT);
my @I = qw(ATA ATC ATT);
my @aoa = ([(0)],[(0..3)],[(0..3)],[(0..3)],[(0..5)],[(0..1)],[(0..2)] );
my $iter = make_permutator(@aoa);
while (my ($m,$p,$v,$a,$r,$d,$i) = $iter->() ){
print $M[$m].$P[$p].$V[$v].$A[$a].$R[$r].$D[$d].$I[$i]."\n";
}
sub make_permutator{
my @arefs = @_;
my @arrayindexes = ();
foreach (@arefs){
push @arrayindexes,[$_,0,$#{$_}];
}
return sub {
return if $arrayindexes[0]->[1] > $arrayindexes[0]->[2];
my @els = map { $_->[0]->[ $_->[1]] } @arrayindexes;
# Check for out of bounds....
$arrayindexes[$#arrayindexes]->[1]++;
for (my $i = $#arrayindexes; $i > 0; $i--){
if ($arrayindexes[$i]->[1] > $arrayindexes[$i]->[2]){
$arrayindexes[$i]->[1] = 0;
$arrayindexes[$i-1]->[1]++;
}else{
last;
}
}
return @els;
};
}
This might do the trick.
cheers,
shawn
On Mon, 13 Jan 2003, David Nix wrote:
> Hello Folks,
> I'm working on a perl program that identifies all restriction sites that
> can be inserted or deleted from an oligo used for site directed mutagenesis
> without changing the encoded amino acid sequence. One problem that I need
> to overcome is how to get all unique oligo permutations of a 7 amino acid
> peptide, preferably one at a time. These will be restriction mapped,
> compared to the original sequence one is mutating, and any differences
> ranked and returned to the user.
>
> At first pass this seems like it should be easy, I can do it with pencil and
> paper, but getting it into a perl script is proving challenging for my
> novice programming skills. Any suggestions or pointers you would have would
> be greatly appreciated!
>
> Here's an example:
>
> Take a peptide like...
>
> M P V A R D I
>
> Each amino acid is encoded by the following (I've got them in arrays)...
> my @M = qw(ATG);
> my @P = qw(CCA CCC CCG CCT);
> my @V = qw(GTA GTC GTG GTT);
> my @A = qw(GCA GCC GCG GCT);
> my @R = qw(CGA CGC CGG CGT AGA AGG);
> my @D = qw(GAC GAT);
> my @I = qw(ATA ATC ATT);
>
> A few oligo permutation would be...
> $oligo1 = $M[0] . $P[0] . $V[0] . $A[0] . $R[0] . $D[0] . $I[0];
> $oligo2 = $M[0] . $P[0] . $V[0] . $A[0] . $R[0] . $D[0] . $I[1];
> $oligo3 = $M[0] . $P[0] . $V[0] . $A[0] . $R[0] . $D[0] . $I[2];
>
> Now how would one write a script that gets at all the other 2301
> permutations (1 x 4 x 4 x 4 x 6 x 2 x 3)! Ugg! I've been at this for a day
> without much luck! Suggestions?
>
> Cheers,
> Dave
>
>
--
********************************
* Shawn Hoon
* http://www.fugu-sg.org/~shawnh
********************************
More information about the Bioperl-l
mailing list