in reply to Create the reverse complement DNA sequence without pattern matching and reverse built-in function?

Sure there is. You could even reimplement an entire regular expression engine using substr, though I wouldn't recommend it. However, you're not using a regular expression here, you're using transliteration: tr///.

my $seq="ACGGGAGGACGGGAAAATTACTACGGCATTAGC"; my %xref = ( A => 'T', C => 'G', G => 'C', T => 'A', a => 't', c => 'g', g => 'c', t => 'a', ); for(my $ix = 0; $ix < length $seq; ++$ix ) { substr( $seq, $ix, 1, $xref{ substr( $seq, $ix, 1 ) } ); } my $reverse = reverse($seq); print $reverse, "\n";

Proof you can write "almost C" in Perl.

I would expect this to be tremendously slower than using tr/// on large data sets.


Dave

  • Comment on Re: Create the reverse complement DNA sequence without pattern matching and reverse built-in function?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Create the reverse complement DNA sequence without pattern matching and reverse built-in function?
by atcroft (Abbot) on Feb 19, 2014 at 15:13 UTC

    Another similar approach, for illustration purposes:

    perl -Mstrict -Mwarnings -le 'my $seq=q{ACGGGAGGACGGGAAAATTACTACGGCATTAGC}; my $complement; my %rc = ( A => q{T}, T => q{A}, C => q{G}, G => q{C}, ); my @letters = split //, $seq; while ( @letters ) { my $l = uc pop @letters; $complement .= $rc{$l}; } print $seq; print $complement;'

    Hope that helps.