in reply to Reverse Complement
Here are some suggestions. The actual transformation is extremely simple; most of the program is input validation and output. Throughout, I have used die for fatal errors, which will use STDERR for output, and exit with a non-zero exit code. That's normally a good thing, but if that is not what you want, you can go back to using print and exit.
There is no need to concatenate both strings and split it later, going over character by character. reverse will reverse a string for you.
Providing sample input and output would have been really helpful. Fortunately, I was able to look up what a reverse complement was fairly easily.
I've kept the same basic structure and order as your code, so I suggest you compare the two and if anything is unclear, let us know.
#!/usr/bin/env perl use warnings; use strict; die "Please enter two sequences as arguments on the command line\n" unless @ARGV == 2; my ($orig, $comp) = map { uc } @ARGV; die "Please enter only ATCG sequences\n" if grep { /[^ATCG]/ } $orig, +$comp; die "Sorry, the two sequences you have just entered are of different l +engths." . "\nPlease try again on the command line.\n" if length $orig != length $comp; # $comp will transform back to $orig iff it is the reverse complement $comp =~ y/ATCG/TAGC/; if ($orig eq reverse $comp) { print "Yes, the two sequences are reverse-complement of each other +.\n"; exit; } else { die "Unfortunately, the two sequences are not reverse-complement.\ +n"; }
Output:
$ perl 1041523.pl GGGGaaaaaaaatttatatat atatataaattttttttcccc Yes, the two sequences are reverse-complement of each other. $ perl 1041523.pl GGGGaaaaaaaatttatatat atatataaattttatttcccc Unfortunately, the two sequences are not reverse-complement.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Reverse Complement
by stamp1982 (Novice) on Jun 30, 2013 at 20:51 UTC | |
by rjt (Curate) on Jun 30, 2013 at 23:53 UTC |