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:

  1. Inconsistent indenting and padding
  2. No comments or documentation whatsoever

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:

  1. No strict
  2. No warnings
  3. No sanitising of arguments or inputs
  4. No declarations of variables
  5. Use of multiple variables ($sub1, $sub2, $sub3) where arrays would be better
  6. Use of C-ish rather than perlish "for" loops
  7. 2-argument form of open where 3-argument would be better
  8. Bareword instead of lexical filehandles (this might be because it's very old code but it's an easy one to update)

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

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.