tags:

views:

819

answers:

4

I am using Perl for a script that takes in input as two short strings of DNA. As an output, I concatenate the two strings strings then print the second string lined up over its copy at the end of the concatenated string. For example: if input string are AAAA and TTTTT then print:

AAAAATTTTT
     TTTTT

I know there are other ways to do this but I am curious to know why my use of tr/// isn't working.

The code for the program is:

use strict;
use warnings;
print "enter a DNA sequence \n";
$DNA1=<>; #<> shorthand for STDIN
$DNA1=~ s/\r?\n?$//;
print $DNA1 "\n\n";
print "enter second DNA sequence \n";
$DNA2=<>;
$DNA2=~ s/\r?\n?$//;
print $DNA2 "\n\n";
$DNA= join("",($DNA1,$DNA2));
print "Both DNA sequences are \"$DNA\" \n\n";
$DNA3=$DNA1;
$DNA3=~ tr/ATCGatcg//;
print $DNA3 "\n\n";
$DNA4= join("",($DNA3,$DNA2));
print $DNA4 "\n\n";
exit;
+1  A: 

You need to put a space in the second half of the tr command.

Alternatively, it seems that what you're trying to do is create a variable containing as many spaces as there were characters in the first string:

my $spaces = ' ' x length($DNA1);
Alnitak
rofl, it took me forever just to find the "tr" command...
Bobby Cannon
+1  A: 

Your tr changes any of ACTGatcg and removes them. I think you want

$DNA3 =~ tr/atcgATCG/ /;
Paul Tomblin
actually without the space the tr command does nothing
Alnitak
not nothing, it counts them (but the returned count is unused here)
ysth
+1  A: 

It might just be a simple syntax error. Try:

$DNA3 =~ tr/ATCGatcg/ /;

where the second slash separates your two translation entities, and you have a space character between the second and third slashes.

Good luck!

Edit: my mistake - misunderstood what you wanted to do. Answer adjusted accordingly :)

Mike
A: 

Is this the program that you want?

#!perl

my $s1 = 'AAAAAAAAA';
my $s2 = 'TCGAGCTA';

print 
    $s1, $s2, "\n", 
    ' ' x length( $s1 ), $s2, "\n";
brian d foy