I am attempting to parse a text delimited file that contains sequence data and find the median on each column per organism. I posted a few days ago but I have still been working on an appropriate solution. Toolic helped me last time and I appreciate it but I still seem to be lost. Toolic did create a working solution but I still needed frequency and the proper format via organism. Thanks again for any help. http://www.perlmonks.org/?node_id=812285

Here is an example of my input data:

contig1 AC344 organism1 1e-1 122 45
contig1 AC344 organism1 1e-2 122 45
contig1 AC346 organism2 1e-102 122 46
contig1 Ac346 organism2 1e-100 122 46
contig1 Ac346 organism2 1e-114 122 46
contig1 Ac346 organism2 1e-111 122 46
contig2 NC333 organism3 1e-2 155 90
contig3 NC444 organism4 1 188 50
contig3 NC444 organism4 12 188 50

The first two columns are correct but it breaks apart when I try to get the medians. Here is an example of my output so far:

Organism Frequency Median_Eval Median_Contig_Length Median_Mapped_Length
organism3: 1 ARRAY(0x2838664) 0
organism1: 2 ARRAY(0x2cc2e4) 0
organism4: 2 ARRAY(0x28386b4) 0
organism2: 4 ARRAY(0x27d11ec) 0

Here is my code so far:

use strict; use warnings; use Acme::Tools; my (%count, %organisms, %med, %number); my $ref_filelist = $ARGV[0]; my ($contig, $accession, $organism, $eval, $con_length, $map_length); open(FILELIST, $ref_filelist ) or die "Could not open Reference filelist...($!)"; print "Organism\tFrequency\tMedian_Eval\tMedian_Contig_Length\tMedian +_Mapped_Length\n"; while (<FILELIST>){ ( $contig, $accession, $organism, $eval, $con_length, $map_length ) = +split ( '\t',); #my $median = $eval[($#eval / 2)]; my $med = median(@{$organisms{$organism}}); $med{$organism} = $med; #$organisms{$organism} = $eval; my $number = ++$count{$organism}; $number{$organism} = $number; } foreach $organism (sort {$number{$a} <=> $number{$b}} keys %organisms) +{ print "$organism:\t$number{$organism}\t$organisms{$organism}\t$med +{$organism}\n" ; }

In reply to Statistics via hash- NCBI BLAST 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.