Hi all,
I have defined some array variables a
*************** *************** *********** -
@L=('CTT','CTC','CTA','CTG','TTA','TTG');
-
-
@S=('TCT','TCC','TCA','TCG','AGT','AGC');
-
-
@R=('CGT','CGC','CGA','CGG','AGA','AGG');
-
-
@V=('GTT','GTC','GTA','GTG');
-
-
@A=('GCT','GCC','GCA','GCG');
-
-
@G=('GGT','GGC','GGA','GGG');
-
-
@P=('CCT','CCC','CCA','CCG');
-
-
@T=('ACT','ACC','ACA','ACG');
-
-
@I=('ATT','ATC','ATA');
-
-
@F=('TTT','TTC');
-
-
@C=('TGT','TGC');
-
-
@Y=('TAT','TAC');
-
-
@Q=('CAA','CAG');
-
-
@N=('AAT','AAC');
-
-
@H=('CAT','CAC');
-
-
@E=('GAA','GAG');
-
-
@D=('GAT','GAC');
-
-
@K=('AAA','AAG');
-
-
@M=('ATG');
-
-
@W=('TGG');
-
*************** *************** *************** **********
and also created a hash to store the arrays in it and finally I wanted to do a foreach loop over the desired input say for example input=VEFCDAMP and to create all possible permutation of the word taken from the definition from dictionary as defined in the array.
The following is the perl script that I conceived to do the job but I am confused here how to use the forloop here to iterate through this and make permutation,
*************** *************** *************** *************** -
print "\n\n\t\#################### AA 2 PROTEIN #################### \n\n";
-
-
print "This script will convert your amino acid sequence to DNA Sequence\n\n";
-
-
print "ENTER THE FILENAME OF THE Amino acid SEQUENCE:= ";
-
-
$aafilename = <STDIN>;
-
-
chomp $aafilename;
-
-
unless ( open(aaFILE, $aafilename) ) {
-
-
print "Cannot open file \"$aafilename\"\n\n";
-
-
}
-
-
@aa = <aaFILE>;
-
-
close aaFILE;
-
-
$aa = join( '', @aa);
-
-
print " \nThe original AA file is:\n$aa \n";
-
-
$aa =~ s/\s//g;
-
-
@aa=$aa;
-
-
my $protein='';
-
-
my $codon;
-
-
@L=('CTT','CTC','CTA','CTG','TTA','TTG');
-
-
@S=('TCT','TCC','TCA','TCG','AGT','AGC');
-
-
@R=('CGT','CGC','CGA','CGG','AGA','AGG');
-
-
@V=('GTT','GTC','GTA','GTG');
-
-
@A=('GCT','GCC','GCA','GCG');
-
-
@G=('GGT','GGC','GGA','GGG');
-
-
@P=('CCT','CCC','CCA','CCG');
-
-
@T=('ACT','ACC','ACA','ACG');
-
-
@I=('ATT','ATC','ATA');
-
-
@F=('TTT','TTC');
-
-
@C=('TGT','TGC');
-
-
@Y=('TAT','TAC');
-
-
@Q=('CAA','CAG');
-
-
@N=('AAT','AAC');
-
-
@H=('CAT','CAC');
-
-
@E=('GAA','GAG');
-
-
@D=('GAT','GAC');
-
-
@K=('AAA','AAG');
-
-
@M=('ATG');
-
-
@W=('TGG');
-
-
-
-
$L=\@L;
-
-
$S=\@S;
-
-
$R=\@R;
-
-
$V=\@V;
-
-
$A=\@A;
-
-
$G=\@G;
-
-
$P=\@P;
-
-
$T=\@T;
-
-
$I=\@I;
-
-
$F=\@F;
-
-
$C=\@C;
-
-
$Y=\@Y;
-
-
$Q=\@Q;
-
-
$N=\@N;
-
-
$H=\@H;
-
-
$E=\@E;
-
-
$D=\@D;
-
-
$K=\@K;
-
-
$M=\@M;
-
-
$W=\@W;
-
-
-
-
%hash = (L=>$L,S=>$S,R=>$R,V=>$V,A=>$A,G=>$G,P=>$P,T=>$T,I=>$I,F=>$F,C=>$C,Y=>$Y,Q=>$Q,N=>$N,H=>$H,E=>$E,D=>$D,K=>$K,M=>$M,W=>$W);
-
-
-
-
$hash_ref=\%hash;
-
-
-
my @aa_split = split //, $aa;
-
-
-
-
foreach my $val (@{hash{@aa_split}})
-
-
{
-
print "@{$val} ";
-
-
}
-
print " \n";
-
*************** *************** *************** *************** *****
to run this program please create and save a txt file with the content of word VEFCDAMP in it.
I want my program to perform simillar task what the following program does it for
*************** *************** *************** *************** **** -
use strict;
-
use warnings;
-
my @V=('GTT','GTC','GTA','GTG');
-
my @A=('GCT','GCC','GCA','GCG');
-
my @E=('GAA','GAG');
-
my @F=('TTT','TTC');
-
my @G=('GGT','GGC','GGA','GGG');
-
my @H=('CAT','CAC');
-
my $i = 1;
-
foreach my $v (@V) {
-
foreach my $a (@A) {
-
foreach my $e (@E) {
-
foreach my $f (@F) {
-
foreach my $g (@G) {
-
foreach my $h (@H) {
-
print "$i $v$a$e$f$g$h\n";
-
$i++;
-
}
-
}
-
}
-
}
-
}
-
}
-
*************** *************** *************** *************** **
Thanks in advance,
B.Nataraj
Oct 28 '08
28 3188 KevinADC 4,059
Recognized Expert Specialist
Heres a solution that does not use eval, but I would benchmark my code and nithinpes code when you get a chance and see if one is better than the other. -
use warnings;
-
use strict;
-
my $seq = 'VF';
-
my %hash = (
-
L => ['CTT','CTC','CTA','CTG','TTA','TTG'],
-
S => ['TCT','TCC','TCA','TCG','AGT','AGC'],
-
R => ['CGT','CGC','CGA','CGG','AGA','AGG'],
-
V => ['GTT','GTC','GTA','GTG'],
-
A => ['GCT','GCC','GCA','GCG'],
-
G => ['GGT','GGC','GGA','GGG'],
-
P => ['CCT','CCC','CCA','CCG'],
-
T => ['ACT','ACC','ACA','ACG'],
-
I => ['ATT','ATC','ATA'],
-
F => ['TTT','TTC'],
-
C => ['TGT','TGC'],
-
Y => ['TAT','TAC'],
-
Q => ['CAA','CAG'],
-
N => ['AAT','AAC'],
-
H => ['CAT','CAC'],
-
E => ['GAA','GAG'],
-
D => ['GAT','GAC'],
-
K => ['AAA','AAG'],
-
M => ['ATG'],
-
W => ['TGG'],
-
);
-
-
my @letters = split '', $seq;
-
my $loops = 1;
-
foreach my $L (@letters) {
-
$loops *= @{$hash{$L}};
-
}
-
my @perms;
-
foreach my $S (@letters) {
-
my @t = @{$hash{$S}};
-
for my $i (0..$loops-1) {
-
my $c = shift @t;
-
$perms[$i] .= $c;
-
push @t, $c;
-
}
-
}
-
my $i = 1;
-
foreach my $s (@perms) {
-
print $i++, " $s\n";
-
}
-
I'm not sure how efficient my use of "shift" and "push" is to loop through the arrays over and over the number of times necessary.
Heres a solution that does not use eval, but I would benchmark my code and nithinpes code when you get a chance and see if one is better than the other. -
use warnings;
-
use strict;
-
my $seq = 'VF';
-
my %hash = (
-
L => ['CTT','CTC','CTA','CTG','TTA','TTG'],
-
S => ['TCT','TCC','TCA','TCG','AGT','AGC'],
-
R => ['CGT','CGC','CGA','CGG','AGA','AGG'],
-
V => ['GTT','GTC','GTA','GTG'],
-
A => ['GCT','GCC','GCA','GCG'],
-
G => ['GGT','GGC','GGA','GGG'],
-
P => ['CCT','CCC','CCA','CCG'],
-
T => ['ACT','ACC','ACA','ACG'],
-
I => ['ATT','ATC','ATA'],
-
F => ['TTT','TTC'],
-
C => ['TGT','TGC'],
-
Y => ['TAT','TAC'],
-
Q => ['CAA','CAG'],
-
N => ['AAT','AAC'],
-
H => ['CAT','CAC'],
-
E => ['GAA','GAG'],
-
D => ['GAT','GAC'],
-
K => ['AAA','AAG'],
-
M => ['ATG'],
-
W => ['TGG'],
-
);
-
-
my @letters = split '', $seq;
-
my $loops = 1;
-
foreach my $L (@letters) {
-
$loops *= @{$hash{$L}};
-
}
-
my @perms;
-
foreach my $S (@letters) {
-
my @t = @{$hash{$S}};
-
for my $i (0..$loops-1) {
-
my $c = shift @t;
-
$perms[$i] .= $c;
-
push @t, $c;
-
}
-
}
-
my $i = 1;
-
foreach my $s (@perms) {
-
print $i++, " $s\n";
-
}
-
I'm not sure how efficient my use of "shift" and "push" is to loop through the arrays over and over the number of times necessary.
Hi Kevin,
Thanks for your new code and pointing out possible pitfall. In fact I am half way down my real work and another half way to pass on. I am making the remaining code and hopefully that wont be so difficult logic to make it out and all about string manipulation and once entire code is ready and I will be in a position to check yours and nithin for a real time problem and I hope can give you my feedback very soon.
B.Nataraj
Hi Kevin,
The last code you have posted, is in fact repeating the first four sequence as output but it make up to the desired 512 (for a input seqnence of VAEFGH) sequence as per rule. But the alternative code by Nithin is working just fine for creating all possible combination and there is no repetition.
I just happened to compare this bug in your code at the last stage of implementing in my entire code using your code as a starting point. I could not fix in it and possibly you can do it quickly so I am posting it to you once again.
Thanks,
B.Nataraj
(I tried to delete this message, but I could not do it)
Hi Kevin,
Sorry I did not mention my input sequence in my previous message, here it is "VAEFGH".
Thanks,
B.Nataraj
KevinADC 4,059
Recognized Expert Specialist
(I tried to delete this message, but I could not do it)
Hi Kevin,
Sorry I did not mention my input sequence in my previous message, here it is "VAEFGH".
Thanks,
B.Nataraj
hmmm...guess I made a logical error in the code I wrote. I'll look at it later today and see if I can find the error.
KevinADC 4,059
Recognized Expert Specialist
well, I can't get it to work. I think you are will need to use nithinpes code or wait and see if someone else can help or post on www.perlmonks.c om and see if one of the members there has a suggestion.
Hi Kevin,
Ok, I will use nithin's code then.
Thanks,
B.Nataraj
Here is one way of doing it. This code dynamically generates required foreach loops and executes the command. -
my $seq = 'VF';
-
my %hash = (
-
L => ['CTT','CTC','CTA','CTG','TTA','TTG'],
-
S => ['TCT','TCC','TCA','TCG','AGT','AGC'],
-
R => ['CGT','CGC','CGA','CGG','AGA','AGG'],
-
V => ['GTT','GTC','GTA','GTG'],
-
A => ['GCT','GCC','GCA','GCG'],
-
G => ['GGT','GGC','GGA','GGG'],
-
P => ['CCT','CCC','CCA','CCG'],
-
T => ['ACT','ACC','ACA','ACG'],
-
I => ['ATT','ATC','ATA'],
-
F => ['TTT','TTC'],
-
C => ['TGT','TGC'],
-
Y => ['TAT','TAC'],
-
Q => ['CAA','CAG'],
-
N => ['AAT','AAC'],
-
H => ['CAT','CAC'],
-
E => ['GAA','GAG'],
-
D => ['GAT','GAC'],
-
K => ['AAA','AAG'],
-
M => ['ATG'],
-
W => ['TGG'],
-
);
-
-
my @loops = split '', $seq;
-
my $cmd;
-
local $i=0;
-
my $vars;
-
-
foreach my $letter (@loops) {
-
my ($str,$v)= createloop($letter);
-
$vars.=$v;
-
$cmd.=$str;
-
}
-
$cmd=$cmd.'print'. " \"$vars\\n\";"; ## adding print statement
-
$cmd.= '}'x$i; ### ending statement blocks
-
-
eval {eval $cmd; }; ## first eval returns statement block
-
-
##creating foreach loops
-
sub createloop {
-
$i++;
-
my $var ='$a'.$i;
-
return ("foreach $var (qw(@{$hash{$_[0]}})) {",$var) ;
-
-
}
-
Hi Nithinpes,
I am using your code posted by you in this thread for my work. Now I had a little problem in using your code to direct the output to a file. I could not do it since I could not understand the code properly, especially the eval statement and its contribution. Kindly help me to add an extra code to direct the generated sequence to save in a text file.
Thanks,
B.Nataraj
Hi Nithinpes,
I am using your code posted by you in this thread for my work. Now I had a little problem in using your code to direct the output to a file. I could not do it since I could not understand the code properly, especially the eval statement and its contribution. Kindly help me to add an extra code to direct the generated sequence to save in a text file.
Thanks,
B.Nataraj
Hi Nithinpes,
Yes, I done it myself by following way. Please igonre my post. - print "\n\n\t\#################### AA 2 PROTEIN #################### \n\n";
-
print "This script will convert your amino acid sequence to DNA Sequence\n\n";
-
print "ENTER THE FILENAME OF THE Amino acid SEQUENCE:= ";
-
$aafilename = <STDIN>;
-
chomp $aafilename;
-
-
unless ( open(aaFILE, $aafilename) ) {
-
print "Cannot open file \"$aafilename\"\n\n";
-
}
-
@aa = <aaFILE>;
-
close aaFILE;
-
$aa = join( '', @aa);
-
-
my $seq = "$aa";
-
my %hash = (
-
L => ['CTT','CTC','CTA','CTG','TTA','TTG'],
-
S => ['TCT','TCC','TCA','TCG','AGT','AGC'],
-
R => ['CGT','CGC','CGA','CGG','AGA','AGG'],
-
V => ['GTT','GTC','GTA','GTG'],
-
A => ['GCT','GCC','GCA','GCG'],
-
G => ['GGT','GGC','GGA','GGG'],
-
P => ['CCT','CCC','CCA','CCG'],
-
T => ['ACT','ACC','ACA','ACG'],
-
I => ['ATT','ATC','ATA'],
-
F => ['TTT','TTC'],
-
C => ['TGT','TGC'],
-
Y => ['TAT','TAC'],
-
Q => ['CAA','CAG'],
-
N => ['AAT','AAC'],
-
H => ['CAT','CAC'],
-
E => ['GAA','GAG'],
-
D => ['GAT','GAC'],
-
K => ['AAA','AAG'],
-
M => ['ATG'],
-
W => ['TGG'],
-
);
-
open(OUT, ">>dna_outfile.txt");
-
-
my @loops = split '', $seq;
-
my $cmd;
-
local $i=0;
-
my $vars;
-
foreach my $letter (@loops) {
-
my ($str,$v)= createloop($letter);
-
$vars.=$v;
-
$cmd.=$str;
-
}
-
$cmd=$cmd.'print OUT'. " \"$vars\\n\";"; ## adding print statement
-
#$cmd=$cmd.'print'. " \"$vars\\n\";"; ## adding print statement
-
$cmd.= '}'x$i; ; ### ending statement blocks
-
-
eval {eval $cmd; }; ## first eval returns statement block
-
-
##creating foreach loops
-
sub createloop {
-
$i++;
-
my $var ='$a'.$i;
-
return ("foreach $var (qw(@{$hash{$_[0]}})) {",$var) ;
-
-
}
-
-
-
-
close OUT;
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bart Nessux |
last post by:
How is this done in php? I've tried several variations of the following:
contact_array =
($_POST,
$_POST,
$_POST,
$_POST,
$_POST);
The ultimate goal is to insert the array into a table in a Mysql db.
|
by: Gary |
last post by:
I haver a table of students - Say 100 students that I need to be able to
update/delete and amend. I know I can do this one student at a time which is
simple but lets say I want to see all the students on the screen at the same
time, modify some, mark some for deletion and even have blank fields at the
end to add a new record.
In HTML which is generated I label each row and input field with a
name/number combination i.e <input type=text...
|
by: Sjoerd |
last post by:
Summary: Use foreach(..) instead of while(list(..)=each(..)).
--==--
Foreach is a language construct, meant for looping through arrays.
There are two syntaxes; the second is a minor but useful extension
of the first:
foreach (array_expression as $value)
statement
|
by: khalidbaloch |
last post by:
hi every one, how are you folf , hope fine
dear Friends i want to get values of multi-dimensional arrays using foreach loop and after that print out the html using an other while loop ,
i tried alot but did not successed accutly i want to create an yahoo api websearch application i got a sample from developer.yahoo.com for this purpose ,this sample uses unserialize/serialize php
here is the code exapmle
<?php
// Parsing Yahoo! REST...
|
by: Akira |
last post by:
I noticed that using foreach is much slower than using for-loop, so I
want to change our current code from foreach to for-loop.
But I can't figure out how.
Could someone help me please?
Current code is here:
foreach ( string propertyName in ht.Keys )
{
this.setProperty( propertyName, ht );
| |
by: cheesecaker |
last post by:
Okay well, let's say you have a script that evaluates exam questions. Arrays are used for both the answer key and the test taker's provided answers. Repeated comparison is required, so obviously, a loop fits the bill.
I have the following (VERY basic) for loop set up. I'm supplying only a snippet, because the rest doesn't really matter. Two arrays have been filled, one with the answer key, one with the user's answers, with eight array...
|
by: nirmal1349 |
last post by:
Hi,
I have a hash in hash file in perl which looks some thing like this:
$FIELDS = {
'abc' => {
'Description' => {
'Purpose' => 'some data is present',
'Background' => 'something',
}
'Run Instructions' => {
'Data' => 'something',
|
by: fjm |
last post by:
For some reason, I have always had a hard time understanding arrays as they pertain to php and databases. I understand associative arrays just fine but when there are multidimensional arrays, I kinda don't.
I have gone over a few different examples but they were limited. I was able to find one piece of code that I would like to disect and ask questions about so I can gain a better understanding.
$characters = array
(
array (...
|
by: Dheeraj Joshi |
last post by:
Hi.. I wrote following code.
iindex = 0;
foreach (XmlNode Labelnodes1 in Labelnode)
{
countlab = Labelnodes1.Attributes.Count;
for (int i = 0; i < countlab; i++)
{
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |