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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |