I am attempting to find the statistical values on certain columns in a tab delimited file. Here is an example:
contig1 test1 1e-28 28 55
contig1 test2 1e-10 22 54
contig2 test1 1e-10 24 78
contig3 test2 10 78 57
contig4 test3 1e-5 200 55
contig4 test2 10 100 43
I wanted to parse the file with the main key being column2 and find the median for columns 3,4, and 5 that the matches each entry for column 2. So for column 2 I need to find all of the matches in the file and store their frequency, along with the median values for column 3,4,5. I have attempted to use hashes but that just confused me. Any help would be appreciated. Here is my code for frequency and median but I need to combine them with the rest of the data so I can output it back to a tab delimited file.
use strict;
use warnings;
use Cwd;
use List::Compare;
use List::AllUtils qw(:all);
my $ref_filelist = $ARGV[0];
my ($lable1, $line, $i, $contig, $accession, $organism, $eval, $con_le
+ngth, $map_length);
open(FILELIST, $ref_filelist )
or die "Could not open Reference filelist...($!)";
my %count;
while (<FILELIST>){
my @tab_list =( $contig, $accession, $organism, $eval, $con_length
+, $map_length ) = split ( '\t',);
++$count{$organism};
}
foreach (keys(%count)) {
print "$_: $count{$_}\n";
#####Sub not used in code yet#####
sub medianeval{
my $ref_filelist_1 = $ARGV[0];
my ($lable1, $line, $i, $contig, $accession, $organism, $eval, $con_le
+ngth, $map_length);
open(FILELIST1, $ref_filelist_1 )
or die "Could not open Reference filelist...($!)";
my %table;
while ($line = <FILELIST1>) {
chomp $line;
my @tab_list = ( $contig, $accession, $organism, $eval, $con_lengt
+h, $map_length ) = split ( '\t', $line );
$table{$organism} = [] unless exists $table{$organism};
push @{$table{$organism}}, $eval;
}
foreach $organism (sort keys %table) {
print "$organism: ";
my @eval = @{$table{$organism}};
my @eval_ref = sort {$a <=> $b } @eval;
my $median = $eval_ref[($#eval_ref / 2)];
print "$median\n";
}
}
I know this is a mess! I am still learning.
Thanks