perlquestion
linseyr
Hi,
I have a file like this:
<code>
chr nr begin end c1 total_c1
chr10 1 10 20 15 2
</code>
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:
<code>
chr nr begin end c1 total_c1 c2 total_c2 c3 total_c3
chr1 2 30 50 10 9 8 9 7 2
</code>
Because it had two times a 9 as total, which is the highest total in the line.
My code looks like this now:
<p>
<readmore>
<code>
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");
}
}
</code>
</readmore>
</p>
Could somebody help me? :)