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

In reply to Statistics on Tab Delimited File by Paragod28

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.