Hi all; I am fairly new to Perl. I'm trying to write a simple code that will parse 4 DNA sequences that have been aligned with gaps. I want the program to count up at nucleotide substitutions and ignore dashes '-' that denote gaps. I've come up with the following code, but the damn thing just runs forever, and doesn't seem to enter the if loops. Input file is fasta format. Any ideas?

@input = <INPUT>; $query1_name = $input[0]; $query1 = $input[1]; $query2_name = $input[2]; $query2 = $input[3]; $query3_name = $input[4]; $query3 = $input[5]; $query4_name = $input[6]; $query4 = $input[7]; @query1 = split ('', $query1); @query2 = split ('', $query2); @query3 = split ('', $query3); @query4 = split ('', $query4); $length1 = scalar @query1; $length2 = scalar @query2; $length3 = scalar @query3; $length4 = scalar @query4; while ($counter <= $length1) { $query1nt = $query1[$counter]; $query2nt = $query2[$counter]; $query3nt = $query3[$counter]; $query4nt = $query4[$counter]; if ($query1nt ne $query2nt) { if ($query1nt ne '-' && $query2nt ne '-') { ++$count_sub; } } elsif ($query1nt ne $query3nt) { if ($query1nt ne "-" && $query3nt ne "-") { ++$count_sub; } } elsif ($query1nt ne $query4nt) { if ($query1nt ne "-" && $query4nt ne "-") { ++$count_sub; } } else { ++$count_same; print "else, hello\n"; } } $totallength = $count_sub + $count_same; print "The number of subs is $count_sub. The number of matches is $cou +nt_same.\n\n"; print "To check, $totallength should equal the length of the alignment +.\n\n"; exit;

In reply to Parsing Multiple Alignment -- using Perl for DNA by le_albatross

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.