Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
more useful options
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Hi, I have a file like this:
chr nr begin end c1 total_c1 chr10 1 10 20 15 2
where the first column describes the chromosome nr, second column nr of peak, third column begin position, fourth column end position, and in total there are 20 columns for (10x class, total_class) so in total 10 classes. I want to find out which class had the highest total, and write a file with "$chr $begin $end $class". There are some classes for which the highest total equals the total of an other class. This line will be "undefined". I wrote a script to find the highest column (probably not the easiest way to do it), but how can I find the undefined lines? So for example this line would be undefined:
chr nr begin end c1 total_c1 c2 total_c2 + c3 total_c3 chr1 2 30 50 10 9 8 9 7 + 2
Because it had two times a 9 as total, which is the highest total in the line. My code looks like this now:

open(classFile,'<',"Results/Classification/classesNormal.txt") or die +$!; my @classes = <classFile>; close(classFile); for my $line(@classes){ my($chr,$nr,$begin,$end,$c1,$total_c1,$c2,$total_c2,$c3,$total_c3, +$c4,$total_c4,$c5,$total_c5,$c6,$total_c6,$c7,$total_c7,$c8,$total_c8 +,$c9,$total_c9,$c10,$total_c10) = split("\t",$line); if ($total_c1 > $total_c2 && $total_c1 > $total_c3 && $total_c1 > +$total_c4 && $total_c1 > $total_c5 && $total_c1 > $total_c6 && $total +_c1 > $total_c7 && $total_c1 > $total_c8 && $total_c1 > $total_c9 && +$total_c1 > $total_c10){ print ($chr,"\t",$begin,"\t",$end,"\t",$c1,"\n"); } if ($total_c2 > $total_c1 && $total_c2 > $total_c3 && $total_c2 > +$total_c4 && $total_c2 > $total_c5 && $total_c2 > $total_c6 && $total +_c2 > $total_c7 && $total_c2 > $total_c8 && $total_c2 > $total_c9 && +$total_c2 > $total_c10){ print ($chr,"\t",$begin,"\t",$end,"\t",$c2,"\n"); } if ($total_c3 > $total_c1 && $total_c3 > $total_c2 && $total_c3 > +$total_c4 && $total_c3 > $total_c5 && $total_c3 > $total_c6 && $total +_c3 > $total_c7 && $total_c3 > $total_c8 && $total_c3 > $total_c9 && +$total_c3 > $total_c10){ print ($chr,"\t",$begin,"\t",$end,"\t",$c3,"\n"); } if ($total_c4 > $total_c1 && $total_c4 > $total_c2 && $total_c4 > +$total_c3 && $total_c4 > $total_c5 && $total_c4 > $total_c6 && $total +_c4 > $total_c7 && $total_c4 > $total_c8 && $total_c4 > $total_c9 && +$total_c4 > $total_c10){ print ($chr,"\t",$begin,"\t",$end,"\t",$c4,"\n"); } if ($total_c5 > $total_c1 && $total_c5 > $total_c2 && $total_c5 > +$total_c3 && $total_c5 > $total_c4 && $total_c5 > $total_c6 && $total +_c5 > $total_c7 && $total_c5 > $total_c8 && $total_c5 > $total_c9 && +$total_c5 > $total_c10){ print ($chr,"\t",$begin,"\t",$end,"\t",$c5,"\n"); } if ($total_c6 > $total_c1 && $total_c6 > $total_c2 && $total_c6 > +$total_c3 && $total_c6 > $total_c4 && $total_c6 > $total_c5 && $total +_c6 > $total_c7 && $total_c6 > $total_c8 && $total_c6 > $total_c9 && +$total_c6 > $total_c10){ print ($chr,"\t",$begin,"\t",$end,"\t",$c3,"\n"); } if ($total_c7 > $total_c1 && $total_c7 > $total_c2 && $total_c7 > +$total_c3 && $total_c7 > $total_c4 && $total_c7 > $total_c5 && $total +_c7 > $total_c6 && $total_c7 > $total_c8 && $total_c7 > $total_c9 && +$total_c7 > $total_c10){ print ($chr,"\t",$begin,"\t",$end,"\t",$c7,"\n"); } if ($total_c8 > $total_c1 && $total_c8 > $total_c2 && $total_c8 > +$total_c3 && $total_c8 > $total_c4 && $total_c8 > $total_c5 && $total +_c8 > $total_c6 && $total_c8 > $total_c7 && $total_c8 > $total_c9 && +$total_c8 > $total_c10){ print ($chr,"\t",$begin,"\t",$end,"\t",$c8,"\n"); } if ($total_c9 > $total_c1 && $total_c9 > $total_c2 && $total_c9 > +$total_c3 && $total_c9 > $total_c4 && $total_c9 > $total_c5 && $total +_c9 > $total_c6 && $total_c9 > $total_c7 && $total_c9 > $total_c8 && +$total_c9 > $total_c10){ print ($chr,"\t",$begin,"\t",$end,"\t",$c9,"\n"); } }

Could somebody help me? :)

In reply to Find highest value by linseyr

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others meditating upon the Monastery: (6)
    As of 2014-04-16 04:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (413 votes), past polls