Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

If you only needed to know if the complement string was (or was not) a true complement of the original, perhaps the simplest way would be to re-complement the complement and check for equality. The re-complementation can be acheived very easily using Perl's tr/// operator. eg.

my $dna = 'ACGTACGT'; my $cmp = 'TGCATGCA'; (my $recmp = $cmp) =~ tr[ACGT][TGCA]; print 'Matched' if $recmp eq $dna;

However, as you want to know what the failures were, you can still use the technique to simplify the process of finding them by creating the re-complemented string and then detecting the differences. You could do this with substr

#! perl -slw use strict; while( !eof DATA ) { my $dna = <DATA>; my $cmp = <DATA>; (my $temp = $cmp) =~ tr[ACGT][TGCA]; if ($dna eq $temp) { print "$cmp is an accurate compliment of \n$dna"; } elsif (length $dna != length $cmp) { print "$cmp is a different length to \n$dna"; } else { for my $pos(0 .. length $dna) { my $c1 = substr($dna, $pos, 1); my $c2 = substr($cmp, $pos, 1); print "$c1-$c2 (pos:$pos) is a mismatch" unless $c1 eq (substr($temp, $pos, 1)); } } } __DATA__ ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC TGACCATGTATCGATCGATATCGTATGCTATATCTGCAGACGATCAGCAGCAAACGGATTTCGGATCTAG +CATCGATCAG ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC TGACCATGTATCGATCGATATCGTATGCTATATCTGCAGACGATCAGCAGCAAACGGATTTCGGATCTAG +CATCGATCA ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC TGACCATGTATCGATCGATATCCTAGGCTATATCTGCAGACGATCAGCAGCAAACGGATATCGGATCTAG +GATCGATCAG

Output

C:\test>243661 TGACCATGTATCGATCGATATCGTATGCTATATCTGCAGACGATCAGCAGCAAACGGATTTCGGATCTAG +CATCGATCAG is an accurate compliment of ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC TGACCATGTATCGATCGATATCGTATGCTATATCTGCAGACGATCAGCAGCAAACGGATTTCGGATCTAG +CATCGATCA is a different length to ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC C-C (pos:22) is a mismatch A-G (pos:25) is a mismatch A-A (pos:59) is a mismatch G-G (pos:70) is a mismatch C:\test>

Or you could go one stage further and use Perl's bit-wise string manipulations to find the differences and use the resultant string to indicate those differences in a simple manner.

#! perl -sw use strict; while( !eof DATA ) { my $dna = <DATA>; my $cmp = <DATA>; (my $temp = $cmp) =~ tr[ACGT][TGCA]; if ($dna eq $temp) { print "\nNo mismatches found\n"; print $dna; print $cmp; } else { ($temp ^= $dna) =~s[[^\0]][*]g; print "\nAsterists (*) indicate mismatches\n"; print $dna; print $temp, $/; print $cmp; } } __DATA__ ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC TGACCATGTATCGATCGATATCGTATGCTATATCTGCAGACGATCAGCAGCAAACGGATTTCGGATCTAG +CATCGATCAG ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC TGACCATGTATCGATCGATATCGTATGCTATATCTGCAGACGATCAGCAGCAAACGGATTTCGGATCTAG +CATCGATCA ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC TGACCATGTATCGATCGATATCCTAGGCTATATCTGCAGACGATCAGCAGCAAACGGATATCGGATCTAG +GATCGATCAG

Output

C:\test>243661-2 No mismatches found ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC TGACCATGTATCGATCGATATCGTATGCTATATCTGCAGACGATCAGCAGCAAACGGATTTCGGATCTAG +CATCGATCAG Asterists (*) indicate mismatches ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC + ** TGACCATGTATCGATCGATATCGTATGCTATATCTGCAGACGATCAGCAGCAAACGGATTTCGGATCTAG +CATCGATCA Asterists (*) indicate mismatches ACTGGTACATAGCTAGCTATAGCATACGATATAGACGTCTGCTAGTCGTCGTTTGCCTAAAGCCTAGATC +GTAGCTAGTC * * * +* TGACCATGTATCGATCGATATCCTAGGCTATATCTGCAGACGATCAGCAGCAAACGGATATCGGATCTAG +GATCGATCAG C:\test>

Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

In reply to Re: need help comparing DNA compliments by BrowserUk
in thread need help comparing DNA compliments by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (1)
As of 2024-04-24 13:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found