Question
Perl Programming. Do my answers look correct? My lecture has only covered the very basics of Perl and I don't know what I'm doing. 2.
Perl Programming. Do my answers look correct? My lecture has only covered the very basics of Perl and I don't know what I'm doing.
2. (7 points) The following questions refer to the Perl program, chap01a.pl, shown on page 18 in the textbook, for Case Study 1.1 Translation of a DNA sequence to an amino acid sequence using the standard genetic code. Read the Perl program, and try to understand what each statement in the program does. You may also search the Web for documentation about the unpack() function (e.g., type Perl unpack for a Google search). Then, answer the following questions.
The code:
#!/usr/bin/perl #translate.pl -- translate nucleic acid sequence to protein sequence # according to standard genetic code
# set up table of standard genetic code
%standardgeneticcode = ( "ttt"=> "Phe", "tct"=> "Ser", "tat"=> "Tyr", "tgt"=> "Cys", "ttc"=> "Phe", "tcc"=> "Ser", "tac"=> "Tyr", "tgc"=> "Cys", "tta"=> "Leu", "tca"=> "Ser", "taa"=> "TER", "tga"=> "TER", "ttg"=> "Leu", "tcg"=> "Ser", "tag"=> "TER", "tgg"=> "Trp", "ctt"=> "Leu", "cct"=> "Pro", "cat"=> "His", "cgt"=> "Arg", "ctc"=> "Leu", "ccc"=> "Pro", "cac"=> "His", "cgc"=> "Arg", "cta"=> "Leu", "cca"=> "Pro", "caa"=> "Gln", "cga"=> "Arg", "ctg"=> "Leu", "ccg"=> "Pro", "cag"=> "Gln", "cgg"=> "Arg", "att"=> "Ile", "act"=> "Thr", "aat"=> "Asn", "agt"=> "Ser", "atc"=> "Ile", "acc"=> "Thr", "aac"=> "Asn", "agc"=> "Ser", "ata"=> "Ile", "aca"=> "Thr", "aaa"=> "Lys", "aga"=> "Arg", "atg"=> "Met", "acg"=> "Thr", "aag"=> "Lys", "agg"=> "Arg", "gtt"=> "Val", "gct"=> "Ala", "gat"=> "Asp", "ggt"=> "Gly", "gtc"=> "Val", "gcc"=> "Ala", "gac"=> "Asp", "ggc"=> "Gly", "gta"=> "Val", "gca"=> "Ala", "gaa"=> "Glu", "gga"=> "Gly", "gtg"=> "Val", "gcg"=> "Ala", "gag"=> "Glu", "ggg"=> "Gly" );
# process input data
while ($line = ) { # read in line of input print "$line"; # transcribe to output chop(); # remove end-of-line character @triplets = unpack("a3" x (length($line)/3), $line); # pull out successive triplets foreach $codon (@triplets) { # loop over triplets print "$standardgeneticcode{$codon}"; # print out translation of each } # end loop on triplets print " "; # skip line on output } # end loop on input lines
# what follows is input data
__END__ atgcatccctttaat tctgtctga
2a (2 points) The current program takes an input nucleotide sequence in lowercase letters (e.g., atgcatccc). Describe how to modify the code so that it can also take an input nucleotide sequence in uppercase letters (e.g., ATGCATCCC).
My Answer: There are many different ways to modify programs. To modify the code so that it can also take input nucleotide sequence uppercase letters, the standard genetic code table could be altered by adding the codons in uppercase letters and their correlating signals. I.e., adding GTG => Val, GCG => Ala, GAG => Glu, and so on.
2b (2 points) The program uses the while loop to read all the lines of input data (appearing after __END__) through the predefined DATA stream. Explain the condition in which the while loop terminates. What is the value of $line when the while loop terminates?
My Answer: I have no clue. I can't seem to find a direct answer in any of my books. Any advice?
2c (1 point) The Perl program uses the function chop(), instead of chomp(), to remove a newline character that may be present at the end of the input line. In your opinion, is it a good programming practice to use chop() for this purpose? Why or why not?
My Answer: For this program, the use of chop() is good programming practice as it removes the line spaces that would be present in the code if it were not applied.
2d (2 points) A user-defined filehandle is often preferred over the predefined DATA stream for data input. Describe how to modify the Perl program so that it can input data from the file named input_file.txt and output results to the file named output_file.txt.
My Answer:
To open an input filehand, the user may enter:
open(INFILE, input_file.txt); #Filehandle, file, default for input. open (INFILE, open(INFILE, <, input_file.txt); #Filehandle, input mode; file
To open a new filehandle for output, the user would:
open(OUTFILE, >output_file.txt.); #Filehandle, output file open(OUTFILE, >, output_file.txt); #Filehandle, output, file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started