Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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

by CountZero (Bishop)
on Sep 22, 2012 at 12:16 UTC ( #995094=note: print w/replies, xml ) Need Help??

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

I turned your data into a tab-separated CSV file and added a line of headers (fieldnames). Then I could use DBI to attack your problem with SQL.
use Modern::Perl; use DBI; my $dbh = DBI->connect( "dbi:CSV:", "", "", { f_dir => './DB', csv_sep_char => "\t", } ) or die "Cannot connect: $DBI::errstr"; my $sql = 'SELECT id, count(*) AS number, sum(tumor) AS tumorscore, sum(normal) +AS normalscore, sum(tumor - normal) AS difference, avg(tumor - normal +) AS averagedifference FROM methyl WHERE (tumor - normal) <=20 or (tu +mor - normal) >=20 GROUP BY id ORDER BY id'; my $sth = $dbh->prepare($sql); $sth->execute; while ( my $row = $sth->fetchrow_hashref ) { say "id: $row->{'id'}, Count: $row->{'number'}, Score tumor: $row->{'tumor +score'}, Score normal: $row->{'normalscore'}, Difference: $row->{'dif +ference'}, Average Difference: $row->{'averagedifference'}"; }
id: cg00381604, Count: 3, Score tumor: 99, Score normal: 174, Differen +ce: -75, Average Difference: -25 id: cg03130891, Count: 1, Score tumor: 55, Score normal: 84, Differenc +e: -29, Average Difference: -29 id: cg12045430, Count: 3, Score tumor: 129, Score normal: 174, Differe +nce: -45, Average Difference: -15 id: cg13869341, Count: 1, Score tumor: 908, Score normal: 913, Differe +nce: -5, Average Difference: -5 id: cg14008030, Count: 1, Score tumor: 688, Score normal: 776, Differe +nce: -88, Average Difference: -88 id: cg20253340, Count: 1, Score tumor: 560, Score normal: 593, Differe +nce: -33, Average Difference: -33 id: cg20826792, Count: 3, Score tumor: 171, Score normal: 174, Differe +nce: -3, Average Difference: -1 id: cg21870274, Count: 1, Score tumor: 791, Score normal: 809, Differe +nce: -18, Average Difference: -18
To exclude as much as possible any rounding-of errors I did not divide the figures by 1000.


A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

My blog: Imperial Deltronics

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995094]
[Corion]: DST does that to everybody...
Corion attempts to find who to address to better target his drive-by patches
[Corion]: This time it's for the Duktape embedded Javascript engine, which would be nice to have IMO, but doesn't compile on Windows currently
[Corion]: I imagine it would be fun to have WWW::Mechanize:: Duktape, but I haven't seen a web browser written in Javascript yet, except the ones distributed with PhantomJs

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2017-03-27 11:07 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (319 votes). Check out past polls.