Homework #1: Reverse Complements

Due Thursday, January 24.

This is taken from Exercise 5.6 in Tisdall's Beginning Perl: Write a program that checks if two strings input by the user are reverse complements of each other. Use the Perl built-in functions split, pop, shift, and eq (eq is actually an operator, not a function, but you get the idea.) Your program should prompt the user to enter two strings. If the strings contain letters other than those in the set {TCGAtcga}, the program should print a message indicating that that letter does not represent a valid nucleotide.

You may see a way to solve the problem not using split, pop and shift, but try to do so--think of it as a puzzle. If you are still stumped, feel free to solve it however you may.

Here is a sample session:

$ perl -w hw1.pl
Enter a strand of DNA: cgat
Enter another strand: atcg
The strands are reverse complements of each other.  Congratulations!
$ perl -w hw1.pl
Enter a strand of DNA: cgat
Enter another strand: cxtt
At least one of the characters in that string is not a nucleotide!
$ perl -w hw1.pl
Enter a strand of DNA: cgat
Enter another strand: cgatc
The two strands are of differing lengths, and so cannot be reverse complements!
$ perl -w hw1.pl
Enter a strand of DNA: cgat
Enter another strand: cgat
The strands are not reverse complements of each other.
$

What to Submit:

Submit both your code and a transcript (such as the one above) demonstrating the use of your program.

Hints:

To simplify handling mixed case strings, you should probably use a transliteration operator to convert TCGA to lowercase before doing much of anything else. Also, remember to use the chomp operator when getting data from the keyboard.

There are plenty of solutions to this problem to be found on the web. Resist the temptation to look them up. Try to solve this problem on your own, from scratch. It is not a difficult problem, and the readings should have readily prepared you for the assignment.