I need help starting off this code and fleshing out the functions. Thanks --> Yo
ID: 3835008 • Letter: I
Question
I need help starting off this code and fleshing out the functions. Thanks -->
Your task is to write an interactive Perl program. The program will display a welcome message and then repeatedly display a prompt to its user, asking the user to either enter the letter q or Q to quit the program, or to enter c to continue. If the user enters a q or Q instead of a c the program should terminate Error checking: If the user enters any other character when it is waiting for the q 'Q' or the 'c', it should ignore it and display the prompt again. It should keep doing this until the user enters a valid character (q 'Q' or 'c'.) If the user enters c, the program should run two functions once (we covered functions in class): Function one: The task of this function is to take two three dimensional coordinates as input values and find the distance between them. This function prompts the user for the x-coordinate of the first point, then the y-coordinate, then the z-coordinate, and then prompts three more times for the x, y, and z coordinates of the second point. Once it has these values, it computes the distance between the two points and outputs that distance on the screen with a short message such as The distance between the two points is The distance between the points (z1,yi, zi) and (z2,y2,22) is given by the formula (a2 Perl has a function named sqrt that can be used for this purpose Error checking: Make sure the user input for the coordinates are numbers and no other characters. Your function should display an error message if the user input is incorrect. Function two: The task of this function is to prompt the user for a codon sequence. A codon sequence will be made up of the following characters: a, u, c, g. It will be 3 characters long. Your function should display the amino acid that corresponds to that sequence. Here is the table that shows that:Explanation / Answer
Code:
#!/usr/bin/perl
# script to calculate distance between coordinates and condon to amino acid sequence functions
# script name: test_math.pl
use strict;
use warnings;
# variable declaration
my ($choice, $dist, $amino_acid);
# initializing default value of $choice variable to c
$choice = 'c';
print " Welcome to the system user";
while( lc $choice ne 'q'){
print " Enter 'c' to continue and 'q' or 'Q' to terminate? ";
$choice = <STDIN>;
chomp($choice);
# only when choice equal to 'c' we will determine distance and condon to amino acid calculation
if(lc $choice eq 'c'){
print " PLEASE ENTER THE COORDINATES FOR CALCULATING DISTANCE";
$dist = cal_dist_coordinate();
# dist value will be -1 in case of any of the coordinates are invalid
if($dist != -1) {
print " Distance between the coordinates is $dist";
}
print " PLEASE ENTER THE CONDON SEQUENCE FOR DETERMINING AMINO ACID";
$amino_acid = get_amino_for_condon();
# amino_acid will be empty in case if correct sequence is not passed
if($amino_acid ne ""){
print " Amino acid for given condon sequence is $amino_acid";
}
}
print " ";
}
# function to calculate distance between the coordinates
sub cal_dist_coordinate
{
my ($x1, $x2, $y1, $y2, $z1, $z2);
my $distance;
print " Enter the first point for x-coordinate ";
$x1 = <STDIN>;
chomp($x1);
print " Enter the second point for x-coorindate ";
$x2 = <STDIN>;
chomp($x2);
print " Enter the first point for y-coordindate ";
$y1 = <STDIN>;
chomp($y1);
print " Enter the second point for y-coordinate ";
$y2 = <STDIN>;
print " Enter the first point for z-coordinate ";
$z1 = <STDIN>;
chomp($z1);
print " Enter the second point for z-coordinate ";
$z2 = <STDIN>;
chomp($z2);
# calling validate function to see if all the coordinates entered are numbers
foreach my $cord($x1, $x2, $y1, $y2, $z1, $z2){
if(validate($cord) == -1){
return -1;
}
}
# calculating distance for the given coordinates
$distance = sqrt ( ($x2 - $x1) * ($x2 - $x1) + ($y2 - $y1) * ($y2 - $y1) + ($z2 - $z1) * ($z2 - $z1) );
return $distance;
}
# function to validate if user entered non-numeric character
sub validate
{
my $value = shift;
# checking if given value is a number
if($value =~ /^[0-9.]+$/) {
return $value;
}
else {
print " '$value' entered is not a number. please try again";
return -1;
}
}
# function to identify corresponding amino acid for the condon sequence given
sub get_amino_for_condon
{
my ($condon, %con_to_amino);
# condon to amino acid mapping
%con_to_amino = (
'uuu'=>'Phe', 'uuc'=>'Phe', 'uua'=>'Leu', 'uug'=>'Leu', 'cuu'=>'Leu', 'cuc'=>'Leu', 'cua'=>'Leu', 'cug'=>'Leu', 'auu'=>'Ile', 'auc'=>'Ile', 'aua'=>'Ile', 'aug'=>'Met', 'guu'=>'Val', 'guc'=>'Val', 'gua'=>'Val', 'gug'=>'Val', 'ucu'=>'Ser', 'ucc'=>'Ser', 'uca'=>'Ser', 'ucg'=>'Ser', 'ccu'=>'Pro', 'ccc'=>'Pro', 'cca'=>'Pro', 'ccg'=>'Pro', 'acu'=>'Thr', 'acc'=>'Thr', 'aca'=>'Thr', 'acg'=>'Thr', 'gcu'=>'Ala', 'gcc'=>'Ala', 'gca'=>'Ala', 'gcg'=>'Ala', 'uau'=>'Tyr', 'uac'=>'Tyr', 'uaa'=>'TER', 'uag'=>'TER', 'cau'=>'His', 'cac'=>'His', 'caa'=>'Gln', 'cag'=>'Gln', 'aau'=>'Asn', 'aac'=>'Asn', 'aaa'=>'Lys', 'aag'=>'Lys', 'gau'=>'Asp', 'gac'=>'Asp', 'gaa'=>'Glu', 'gag'=>'Glu', 'ugu'=>'Cys', 'ugc'=>'Cys', 'uga'=>'TER','ugg'=>'Trp','cgu'=>'Arg', 'cgc'=>'Arg', 'cga'=>'Arg', 'cgg'=>'Arg', 'agu'=>'Ser', 'agc'=>'Ser', 'aga'=>'Arg', 'agg'=>'Arg', 'ggu'=>'Gly', 'ggc'=>'Gly', 'gga'=>'Gly', 'ggg'=>'Gly'
);
print " Enter a condon sequence of 3 characters(a, u, c, g) ";
$condon = <STDIN>;
chomp($condon);
# checking if condon sequence is of 3 characters
if(length($condon) == 3) {
# verifying if the 3 characters are any of a, u, c, g
if($condon =~ /[aucg]{3}/) {
return $con_to_amino{$condon};
}
else {
print " Condon sequence should be of characters a, u, c, g";
return "";
}
}
else {
print " Length of condon sequence should be 3 characters";
return "";
}
}
Execution and output:
186590cb0725:Perl bonkv$ ./test_math.pl
Welcome to the system user
Enter 'c' to continue and 'q' or 'Q' to terminate? c
PLEASE ENTER THE COORDINATES FOR CALCULATING DISTANCE
Enter the first point for x-coordinate 1
Enter the second point for x-coorindate 2
Enter the first point for y-coordindate 3
Enter the second point for y-coordinate 4
Enter the first point for z-coordinate 5
Enter the second point for z-coordinate 6
Distance between the coordinates is 1.73205080756888
PLEASE ENTER THE CONDON SEQUENCE FOR DETERMINING AMINO ACID
Enter a condon sequence of 3 characters(a, u, c, g) aug
Amino acid for given condon sequence is Met
Enter 'c' to continue and 'q' or 'Q' to terminate? c
PLEASE ENTER THE COORDINATES FOR CALCULATING DISTANCE
Enter the first point for x-coordinate 10
Enter the second point for x-coorindate 20
Enter the first point for y-coordindate 30
Enter the second point for y-coordinate 40
Enter the first point for z-coordinate 50
Enter the second point for z-coordinate 60
Distance between the coordinates is 17.3205080756888
PLEASE ENTER THE CONDON SEQUENCE FOR DETERMINING AMINO ACID
Enter a condon sequence of 3 characters(a, u, c, g) ucg
Amino acid for given condon sequence is Ser
Enter 'c' to continue and 'q' or 'Q' to terminate? c
PLEASE ENTER THE COORDINATES FOR CALCULATING DISTANCE
Enter the first point for x-coordinate 1000
Enter the second point for x-coorindate a
Enter the first point for y-coordindate b
Enter the second point for y-coordinate c
Enter the first point for z-coordinate d
Enter the second point for z-coordinate e
'a' entered is not a number. please try again
PLEASE ENTER THE CONDON SEQUENCE FOR DETERMINING AMINO ACID
Enter a condon sequence of 3 characters(a, u, c, g) bcda
Length of condon sequence should be 3 characters
Enter 'c' to continue and 'q' or 'Q' to terminate? c
PLEASE ENTER THE COORDINATES FOR CALCULATING DISTANCE
Enter the first point for x-coordinate 1
Enter the second point for x-coorindate 2
Enter the first point for y-coordindate 3
Enter the second point for y-coordinate 4
Enter the first point for z-coordinate 5
Enter the second point for z-coordinate ab
'ab' entered is not a number. please try again
PLEASE ENTER THE CONDON SEQUENCE FOR DETERMINING AMINO ACID
Enter a condon sequence of 3 characters(a, u, c, g) bcd
Condon sequence should be of characters a, u, c, g
Enter 'c' to continue and 'q' or 'Q' to terminate? q
186590cb0725:Perl bonkv$
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.