in reply to Find overlap
Here is one way to do it:
#!/usr/bin/perl use warnings; use strict; @ARGV = ( '148Nsorted.bed', '162Nsorted.bed', '174Nsorted.bed', '175Ns +orted.bed' ); my %data; while ( <> ) { /^\s*(\S+)\s+(\d+)\s+(\d+)\s*$/ or next; $data{ $1 } |= '0' x ( $2 - 1 ) . '1' x ( $3 - ( $2 - 1 ) ); } keys( %data ) == 1 or die "Error: too many keys.\n"; my ( $name, $string ) = each %data; $string =~ /10+1/ and die "Error: no overlap.\n"; $string =~ /^0*1/ and my $start = $+[ 0 ]; $string =~ /.*1/ and my $end = $+[ 0 ]; print "$name\t$start\t$end\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Find overlap
by Anonymous Monk on Oct 14, 2012 at 16:32 UTC | |
Re^2: Find overlap
by linseyr (Acolyte) on Oct 14, 2012 at 16:46 UTC | |
by jwkrahn (Abbot) on Oct 16, 2012 at 04:51 UTC |
In Section
Seekers of Perl Wisdom