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
    Do you have to use STDIN in this case or do I have to store it a file? How did you get your outputs? I run the code and it did not allow any user input.

    please two sequences as arguments on the command line. Press any key to continue

    what am I missing and why cant I run the code?

    Stamp1982

      EDIT: (More of a complete 180, really): I somehow completely missed the fact you already asked the exact same question in Re^2: Reverse Complement and had a lengthy exchange with AnomylousMonk, who was very helpful.

      I actually used the exact same structure (and even used the exact same error messages!) that you provided in the original post. Did you write that code yourself? Anyway, I also gave a direct example of how to run the script. Assuming you saved the script as 1041523.pl (an odd name, to be sure—feel free to choose a better one), type the following:

      perl 1041523.pl GGGGaaaaaaaatttatatat atatataaattttttttcccc

      Of course, substitute any two sequences for the two shown here.