Hi,

I have part of this code where I am calculating the average and coefficient variance from the values I generated from input data based on my code. And then the values will be output into a textfile.

. . . while(<CURINFILE>) { push @full_data , [split] while (<CURINFILE>); for $arr_ref1 (@full_data) { for $arr_ref2(@full_data) { $variable1 = ''; $variable2=''; for my $index1 (3..4) #first group { $ratio1 = ($$arr_ref2[$index1]/$$arr_ref1[$index1],"\t"); $variable1 .= $ratio1; #join column by column } for my $index2 (5..6) #second group { $ratio2 = ($$arr_ref2[$index2]/$$arr_ref1[$index2],"\t"); $variable2 .= $ratio2; #join column by column } #Calculate Average @arrayint1 = split (/\t/,$variable1); $avg1 = &average (\@arrayint1); @arrayint2 = split (/\t/,$variable2); $avg2 = &average (\@arrayint2); #Calculate SD @arrayint1 = split (/\t/,$variable1); $std1 = &stdev(\@arrayint1); @arrayint2 = split (/\t/,$variable2); $std2 = &stdev(\@arrayint2); #Calculate CV $cv1 = $std1/$avg1; $cv2 = $std2/$avg2; my $outputa = "$$arr_ref1[0]"; my $outputb = "$variable1\t$variable2\t"; my $outputc = "\t$avg1\t$avg2"; my $outputd = "\t$cv1\t$cv2"; ###### print everything out ##################### my $key = "$outputa"."$outputb". "$outputc"."outputd"; print OUT1 $key; print OUT1 "\n"; } } . (average and SD codes) .
so the output is:
_OUTPUT_ M446T27 1 1 1 1 1 1 0 0 M446T27 1.75 2.66 1.80 2.16 2.20 1.98 0.29 0.12 M446T27 1.00 1.64 0.99 1.09 1.32 1.04 0.34 0.06 . .

My question is, is it possible to actually filter the whole row ($key) based on the outputd(set condition for CV)(last two columns)? So that I do not want to print those rows that does not meet the criteria based on the CV of both groups.

EDIT: I'll rephrase my question..never good in words. Is there a need to put them into hashes or I can just do the if condition straightaway using variables and then assign back the outputa,b,c to the filtered outputd accordingly?


In reply to Filter rows according to certain criteria based on CV by hellohello1

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.