Question: Perl help regarding hash
0
gravatar for ksi216
3.4 years ago by
ksi21660
ksi21660 wrote:

Hello, Ive created a hash, of codons and amino acids. My program should allow a user to input a DNA codon and then output the appropriate single letter code for the amino acid corresponding to that codon. If the input does not correspond to an amino acid, then the output should say so. im stuck. here is all my code

my %codon= (); while(<data>){ # while loop to read line by line was is in __DATA__ chomp; #remove newline characters my ($key, $lettercode)= split; #we split the key value pairs on each line $codon{$key} = $lettercode; # we assign the key value pairs to %codon in scalar fasion }

print out all pairs

while (my($k,$l)= each(%codon)){print"$k =>$l\n"; #print to see that hash was created with data sucessfully

input output command to generate letter code if (exists()

}

__DATA__ TTT F
CTT L
ATT I
GTT V TTC F
CTC L
ATC I
GTC V TTA L
CTA L
ATA I
GTA V TTG L
CTG L
ATG M
GTG V TCT S
CCT P
ACT T
GCT A TCC S
CCC P
ACC T
GCC A TCA S
CCA P
ACA T
GCA A TCG S
CCG P
ACG T
GCG A TAT Y
CAT H
AAT N
GAT D TAC Y
CAC H
AAC N
GAC D TAA Stop
CAA Q
AAA K
GAA E TAG Stop
CAG Q
AAG K
GAG E TGT C
CGT R
AGT S
GGT G TGC C
CGC R
AGC S
GGC G TGA Stop
CGA R
AGA R
GGA G TGG W
CGG R
AGG R
GGG G

bioinformatics perl • 1.3k views
ADD COMMENTlink modified 3.4 years ago by Zaag720 • written 3.4 years ago by ksi21660
2

Format your code to make it more readable and enclose it within code tags,

like this.
ADD REPLYlink written 3.4 years ago by h.mon26k
1

Check this program and try to find where your mistake is.

ADD REPLYlink written 3.4 years ago by venu6.2k

Please review the content before sharing links to sites like this. That code is awful (it won't even compile with a recent Perl, and doesn't answer the question) and the site is pretty sketchy. We can use github/gist for sharing code, that way you can embed the code in your post.

ADD REPLYlink modified 3.4 years ago • written 3.4 years ago by SES8.2k
2
gravatar for Zaag
3.4 years ago by
Zaag720
Amsterdam
Zaag720 wrote:
#!/usr/bin/perl -w

my %codon= (); while(<DATA>){ # while loop to read line by line was is in __DATA__ 
chomp; #remove newline characters 
my ($key, $lettercode)= split; #we split the key value pairs on each line 
$codon{$key} = $lettercode; # we assign the key value pairs to %codon in scalar fasion 
}

#print out all pairs
while (my($k,$l)= each(%codon)){

print"$k \t $l\n"; #print to see that hash was created with data sucessfully
}
#input output command to generate letter code 
print  " Please enter codon\n" ;
my $userin = <STDIN> ;
chomp $userin ;

if (exists($codon{$userin}) ) { 

    my $code = $codon{$userin} ;

    print  "$userin is $code \n"  ; exit ;
    }

else  { 

    print  "$userin does not exist\n"  ; exit ;
    }




__DATA__ 
TTT F 
CTT L 
ATT I 
GTT V TTC F 
CTC L 
ATC I 
GTC V TTA L 
CTA L 
ATA I 
GTA V TTG L 
CTG L 
ATG M 
GTG V TCT S 
CCT P 
ACT T 
GCT A TCC S 
CCC P 
ACC T 
GCC A TCA S 
CCA P 
ACA T 
GCA A TCG S 
CCG P 
ACG T 
GCG A TAT Y 
CAT H 
AAT N 
GAT D TAC Y 
CAC H 
AAC N 
GAC D TAA Stop 
CAA Q 
AAA K 
GAA E TAG Stop 
CAG Q 
AAG K 
GAG E TGT C 
CGT R 
AGT S 
GGT G TGC C 
CGC R 
AGC S 
GGC G TGA Stop 
CGA R 
AGA R 
GGA G TGG W 
CGG R 
AGG R 
GGG G
ADD COMMENTlink modified 3.4 years ago • written 3.4 years ago by Zaag720
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1266 users visited in the last hour