linseyr has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I have a file like this:
Could somebody help me? :)
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 chr10 1 10 20 15 2
Because it had two times a 9 as total, which is the highest total in the line. My code looks like this now:chr nr begin end c1 total_c1 c2 total_c2 + c3 total_c3 chr1 2 30 50 10 9 8 9 7 + 2
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"); } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Find highest value
by choroba (Cardinal) on Sep 19, 2012 at 14:07 UTC | |
by linseyr (Acolyte) on Sep 19, 2012 at 14:34 UTC | |
Re: Find highest value
by Tux (Canon) on Sep 19, 2012 at 14:33 UTC | |
Re: Find highest value
by nemesdani (Friar) on Sep 19, 2012 at 14:10 UTC |
Back to
Seekers of Perl Wisdom