odegbon has asked for the wisdom of the Perl Monks concerning the following question:
I have a file which is tab delimited(a hit from a DB). I would like to first store say the first and tenth item on each(row) as well as the entire row in a hash. And then build an array of hashes from 2nd,3rd,...... rows respectively. I would then sort each of the rows by score and ID(which are the first and 10th elements of each row) and print the row with the best score.
I have tried this out and it seems I was just able to pick only one row:
my program seem to be processing only the first row. I need hints/snippets!my @CHIMP = <CBLAT>;#CBLAT hold the file to be processed</p> my %hITS; my $score; my @bestHITS; if(!@CHIMP){</p> my $nm = "no_match"; next} my $cblast = shift @CHIMP;#process blat output lines(r +ows)</p> my @row = split(/\t/,$cblast);</p> unshift @{$hITS{$score}},{MATCH=>$row[0],qID=>$row[9], +cLINE=>$cblast};#keep score,query id and whole lines in hash</p> @{$hITS{$score}} = sort {$b->{MATCH} <=> $a->{MATCH} | +| $a->{qID} cmp $b->{qID}} </p>@{$hITS{$score}};#sort by match score/ +query ID</p> foreach my $key (@{$hITS{$score}}){ my $hits = $key->{cLINE}; push @bestHITS, $hits;#keep sorted lines in ar +ray last;}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Building an array of hashes, and then sorting keys with each hash
by ikegami (Patriarch) on Dec 30, 2009 at 01:42 UTC | |
by odegbon (Initiate) on Dec 30, 2009 at 07:05 UTC | |
by ikegami (Patriarch) on Dec 30, 2009 at 12:41 UTC | |
by odegbon (Initiate) on Dec 31, 2009 at 05:41 UTC | |
by ikegami (Patriarch) on Jan 02, 2010 at 00:40 UTC | |
| |
by odegbon (Initiate) on Dec 31, 2009 at 07:46 UTC |