in reply to Re: string complement question
in thread string complement question

thanks B10m, but this is still just getting the exact match! oh well...

Replies are listed 'Best First'.
Re: string complement question
by b10m (Vicar) on Nov 21, 2003 at 13:23 UTC
    Mmmm, my bad. I wasn't paying much attention (apparantly). I was still checking and printing the same stuff, which didn't really make sense. This should do the trick (still slow, and I'm looking forward to faster ways :)
    my $i; my $j; my $dna; my $temp_dna; for ($i=0; $i < @array1; $i++) { $dna = $array1[$i]; $temp_dna = $dna; $dna = reverse $dna; $dna =~ tr/actg/tgac/; for ($j=0; $j < @array1; $j++) { if ($dna eq $array1[$j]) { print "FOUND $temp_dna\t$array[$j]\n"; } } }
    Please note that I made a lot of steps to get to this. This could be shortened, but this is more readable (for me at least ;)
    --
    B10m
      Well, if it's just finding matches inside the same array, it's just a variation on finding uniques in an array. Here's one way of solving it:
      #!/usr/bin/perl use strict; use warnings; my @array = qw /TATG GTTC GAAC AATA/; # DNA's tend to be loooooooooooooooong, so we create a lookup # table to calculate the reversed inverse. my %table; my @chars = qw /A C G T/; foreach my $c1 (@chars) { foreach my $c2 (@chars) { foreach my $c3 (@chars) { foreach my $c4 (@chars) { my $val = reverse my $key = "$c1$c2$c3$c4"; $val =~ y/ACGT/TGCA/; $table {$key} = $val; } } } } my %tmp; @tmp {@array} = (); my @matches = grep {exists $tmp {$table {$_}}} @array; print "@matches\n"; __END__

      Abigail