in reply to Re^2: find which ranges share at least one common value
in thread find which ranges share at least one common value

Your getting this cos I'm bored waiting for a long running process to complete. In future, show some effort.

#! perl -slw use strict; <> for 1 .. 2; ## discard headers ## Read ranges stdin my @ranges = map { [ (split)[3,5] ] } <>; print "$_ : [ @{ $ranges[ $_ ]} ]" for 0 .. $#ranges; my @overlaps; for my $i1 ( 0 .. $#ranges ) { for my $i2 ( $i1+1 .. $#ranges ) { unless( $ranges[ $i1 ][ 0 ] > $ranges[ $i2 ][ 1 ] or $ranges[ $i1 ][ 1 ] < $ranges[ $i2 ][ 0 ] ) { push @{ $overlaps[ $i1 ] }, $i2; } } } defined $overlaps[ $_ ] and print "$_ overlaps with @{ $overlaps[ $_ ] }" for 0 .. $#overlaps;

Use as parttable | script.pl. You should see output something like:

0 : [ 8392560 41950559 ] 1 : [ 0 8392559 ] 2 : [ 0 78156479 ] 3 : [ 41950560 48245999 ] 4 : [ 48246000 56638559 ] 5 : [ 56638560 65031119 ] 6 : [ 65031120 73423679 ] 7 : [ 73423680 73529759 ] 0 overlaps with 2 1 overlaps with 2 2 overlaps with 3 4 5 6 7

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: find which ranges share at least one common value
by Anonymous Monk on Feb 08, 2011 at 15:11 UTC
    Thanks a lot. I shall take some time to understand how this works.