Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: need help comparing DNA compliments

by dakkar (Hermit)
on Mar 17, 2003 at 17:26 UTC ( [id://243699]=note: print w/replies, xml ) Need Help??


in reply to need help comparing DNA compliments

First, you are not comparing strings, you are comparing arrays.

As this is not C, you don't need a for loop to get the length of an array: just say:

$counter=@dna;$counter2=@comp;
Assigning an array to a scalar assigns the length of the array to the scalar (OK, we're talking about context here, but I'm not going into a detailed discussion)

And your cycles are a bit out of whack... you are saying:

  1. if @dna is not empty (while (@dna))
  2. count how many bases I have in @dna
  3. count how many bases I have in @comp
  4. check if the one past last element of each list is a correct pairing
  5. etc

I'll not write here a "correct" solution, since many other people already have. I'll just write a (commented) snippet for the case of strings:

my $dna; # the sequence, as a string my $comp; # the complement, as a string my $c2; ($c2=$comp)=~tr[ATGC][TACG]; # copy $comp into $c2, then exchange each + base in $c2 with its complement (using the tr-ansliteration operator +) print "Match!\n" if $dna eq $c2; # since $c2 is $comp's complement, it + should be equal to $dna

-- 
        dakkar - Mobilis in mobile

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://243699]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2024-04-24 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found