I'm glad you haven't written this yourself because it is not in a good way. There are 2 problems with the layout which don't help with analysis:
We can fix the first by using perltidy. This gives the much more legible:
$file = shift; print "Window length\n"; $kmer = <STDIN>; chomp ($kmer); print "Minimum quality score cut-off\n"; $cut_off = <STDIN>; chomp ($cut_off); open (MYFILE, ">R.txt"); if (open (FASTQ, $file)) { while ($header1 = <FASTQ>) { $dna = <FASTQ>; $header2 = <FASTQ>; $qual = <FASTQ>; @dna = split ('', $dna); @qual = split ('', $qual); @num_value = (); @scores = (); foreach $qscore (@qual) { $num_value = ord ($qscore) - 33; push (@num_value, $num_value); } foreach $value (@num_value) { if ($value < $cut_off) { pop (@qual); } else { last; } } $sub1 = substr ($dna, -$#qual); $sub11 = substr ($qual, -$#qual); @qscopy = reverse @num_value; foreach $value (@qscopy) { if ($value < $cut_off) { pop (@qual); } else { last; } } $sub2 = substr ($sub1, 0, $#qual); $sub22 = substr ($sub11, 0, $#qual); for ($i = 0; $i <= $#qual - ($kmer - 1); $i++) { @scores = @num_value[$i .. $i + $kmer - 1]; $sum = 0; foreach $score (@scores) { $sum += $score; } if (($sum / $kmer) < $cut_off) { last; } } $sub3 = substr ($sub2, 0, ($i - 1)); $sub33 = substr ($sub22, 0, ($i - 1)); print MYFILE "$header1$sub3\n$header2$sub33\n\n"; } } else { print "Error!\n"; } close MYFILE;
See how much more structured that appears?. Now, here's what's wrong with the actual code:
As to why they have written it like this, I could not say. Without comments, documentation, sample inputs and so on it is a guessing game. If there's one point in particular which you don't understand then maybe highlight that?
In reply to Re: explanation of passages of a Perl script
by hippo
in thread explanation of passages of a Perl script
by uuuiii
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |