Write a perl program that has functions defined for the follow:1. function compl
ID: 3629627 • Letter: W
Question
Write a perl program that has functions defined for the follow:1. function complement_and_reverse: Takes a string that consists of any combination of A, G, C, or T and produces the watson-crick complement. A->C, G->T, and vice versa. The string is then reversed and that value is returned invalid strings should throw an error (return to menu with error printed).2. function create_windows: Takes a string, an integer that defines the window size, and an integer value that defines a sliding amount. The function will return a list of strings such that, the initial string is broken into windows defined by the window size, that shift by the sliding amount. ex: "ACGCGTGTTA", 4, 2 would return ["ACGC", "GCGT", "GTGT", "GTTA", "TA"] invalid strings should throw an error (return to menu with error printed).3. function get_reads: Takes a string that is a path to a file containing one string per line. The function will return a list of valid strings contained in the file (a valid string only contains A, G, C, or T) invalid file (doesnt exist, no permission) should throw error and return. 4. function write_windows: Takes a string that is a path to a file and a list of strings (windows). The function will open a file and write all windows to the file. invalid file (doesnt exist, no permission) should throw error and return.5. Finally make a menu that is user driver. it will have an option for each ofthese commands.ex: if the user selected option 1, they would be prompted for an input stringto complement. the result would be printed.
Explanation / Answer
#!/usr/bin/perl -w
# Calculating the reverse complement of a strand of DNA
# The DNA
$DNA = 'ACGGGAGGACGGGAAAATTACTACGGCATTAGC';
print "Here is the starting DNA: $DNA ";
# Calculate the reverse complement
# XXX Warning: this attempt will fail! XXX
#
# First, copy the DNA into new variable $revcom
# (short for REVerse COMplement)
# Notice that variable names can use lowercase letters like
# "revcom" as well as uppercase like "DNA".
# In fact, lowercase is more common.
#
# It doesn't matter if we first reverse the string and then
# do the complementation; or if we first do the complementation
# and then reverse the string. Same result each time.
# So when we make the copy we'll do the reverse in the same statement.
$revcom = reverse $DNA;
# Next substitute all bases by their complements,
# A->T, T->A, G->C, C->G
$revcom =~ s/A/T/g;
$revcom =~ s/T/A/g;
$revcom =~ s/G/C/g;
$revcom =~ s/C/G/g;
2)a)
# Make a new copy of the DNA (see why we saved the original?)
$revcom = reverse $DNA;
# The Perl translate/transliterate command is just what we need:
$revcom =~ tr/ACGTacgt/TGCAtgca/;
print "Here is the reverse complement DNA: $revcom ";
exit;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.