Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: compare values while value on other column remains the same

by Anonymous Monk
on Sep 21, 2012 at 21:11 UTC ( #994992=note: print w/ replies, xml ) Need Help??


in reply to compare values while value on other column remains the same

Something like this?

use strict; use warnings; use List::Util qw(sum); my %table; while (defined(my $line = <DATA>)) { my @values = split(/\s+/, $line); push @{$table{$values[3]}}, \@values; } foreach my $key (sort keys %table) { my $avg_diff = sum(map { ($_->[5] / 1000) - ($_->[4] / 1000) } @{$ +table{$key}}) / @{$table{$key}}; foreach my $array_ref (@{$table{$key}}) { if ($avg_diff >= 0.02) { print join("\t", @{$array_ref}), "\n"; } } } __DATA__ chr1 15865 15915 cg13869341 908 913 chr1 18827 18877 cg14008030 688 776 chr1 29407 29457 cg12045430 43 70 chr1 29407 29457 cg12045430 43 88 chr1 29407 29457 cg12045430 43 16 chr1 29425 29475 cg20826792 57 70 chr1 29425 29475 cg20826792 57 88 chr1 29425 29475 cg20826792 57 16 chr1 29435 29485 cg00381604 33 70 chr1 29435 29485 cg00381604 33 88 chr1 29435 29485 cg00381604 33 16 chr1 68849 68899 cg20253340 560 593 chr1 69591 69641 cg21870274 791 809 chr1 91550 91600 cg03130891 55 84


Comment on Re: compare values while value on other column remains the same
Download Code
Re^2: compare values while value on other column remains the same
by linseyr (Acolyte) on Sep 26, 2012 at 20:23 UTC
    Hi, Thank you for your answer. I want to do something slightly different now, and Im trying to do it with the code you provided, but since Im all new with this, the hashes and maps are a bit difficult to me.. I want to do it at a different order, because I want to do something else with it. I already combined multiple data files into one which now looks like this:
    cg12045430 43 16 6 44 23 63 24 77 cg12045430 43 16 6 44 23 63 24 80 cg12045430 43 16 6 44 23 63 24 45 cg12045430 43 16 6 44 23 115 24 77 cg12045430 43 16 6 44 23 115 24 80 cg12045430 43 16 6 44 23 115 24 45 cg12045430 43 16 6 44 23 29 24 77 cg12045430 43 16 6 44 23 29 24 80 cg12045430 43 16 6 44 23 29 24 45
    So I have again the same id's on multiple lines and different values on columns 2-9. I want for one ID get the average of columns 2-9. So for that input file that would be:
    cg12045430 43 16 6 44 23 69 24 67
    And afterwards I want to calculate the difference between column 2,3 and 4,5 and 6,7 and 8,9 like before. I tried to do it using your code and for every key calculate the average of the map, but it didn't work. Could you give me some advise? Thanks!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://994992]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2014-07-13 01:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (244 votes), past polls