Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hi monks, I'm feeling a bit stuck. I basically am writing a sub-routine that compares two strings of dna, and prints out any mismatches that occur ( where good base-pairs are defined in the sub). My problem is that if the mismatch occurs on the first or last base of the string it messes up. e.g. for a sequence:
ATCG AAGG
Mismatches are present on first and last positions e.g. A/A and G/G. I want the program to also print the bases either side of the mismatches e.g. AT/AA and CG/GG. But if the mismatch is on the first position it prints GA/GA and if it is on the last position it prints G/G. How can I get it to not print [$i -1] if the mismatch has occured on the first position, and to not print [$i+1] if the mismatch is on the last position. Thanks for your help. ;-)
sub get_mismatches { my ($segment, $comp_segment) = @_; my @seg_mismatches; my @seg_mis; my $i; my %good_pairs = ( 'A' => 'T', 'C' => 'G', 'G' => 'C', 'T' => 'A', ); foreach (my $i =0; $i < @$segment; $i++) { if ($segment->[$i] ne $good_pairs {$comp_segment->[$i]}) { push @seg_mismatches,"$segment->[$i-1]$segment->[$i]/$com +p_segment->[$i-1]$comp_segment->[$i]\n"; push @seg_mismatches, "$segment->[$i]$segment->[$i+1]/$co +mp_segment->[$i]$comp_segment->[$i+1]\n"; push @seg_mis, "$segment->[$i-1]$segment->[$i] $segment-> +[$i]$segment->[$i+1]\n"; } } return (\@seg_mismatches, \@seg_mis); }

update (broquaint): escaped square brackets + title change (was strings)


In reply to Finding DNA string mismatches 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? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2023-02-08 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (40 votes). Check out past polls.

    Notices?