# Exercise 5.4D

Exercise 5.4 in Beginning Perl for Bioinformatics

```#Ex 5-4

#Pseudocode:

#Write program to calculate the reverse complement of a string of DNA.

#First, get DNA sequence from user input.

#Second, calculate reverse complement using substr

#Print result

#my variables

my \$DNA = 0;

my \$reversecomplement = 0;

my \$base = 0;

my \$position = 0;

#Ask the user for a string of DNA (change it to upper)

print "Please input a string of DNA to get  its reverse complement:\n\n";

\$DNA = <STDIN>;

chomp \$DNA;

#Calculate reverse complement (refer to pg. 80 and what if it is not uppercase)

for (\$position = 0 ; \$position < length \$DNA ; ++\$position){

\$base = substr(\$dna, \$position, 1);

if ( \$base eq 'T' ) {

\$reversecomplement = \$reverse_dna.'A';

} elsif ( \$base eq 'A' ) {

\$reversecomplement = \$reverse_dna.'T';

} elsif ( \$base eq 'G' ) {

\$reversecomplement = \$reverse_dna.'C';

} elsif ( \$base eq 'C' ) {

\$reverse_dna = \$reverse_dna.'G';

}

}

#Strip \$reverse_dna of it's first character (why??????)

\$reverse_dna =~ s/^0*//;

#Print result

print "The corresponding reverse complement sequence is: \$reverse_dna.\n\n";

#The End

exit;
```