use strict; use warnings; #### # Read BED file into an array #### my $BED_FILE = <) { my ($chrom, $chrBeg, $chrEnd, $name, $score, $strand, $thickBeg, $thickEnd, $RGB, $blkCnt, $blkSzs, $blkBegs) = split /\s+/, $line; push @ABED, [ $chrBeg, $chrEnd, $name ]; } #### # Compare each coordinate in my list of things to check # against the items we stored in the BED element array #### my $COORDS_FILE = <) { my ($item, $beg, $end) = split /\s+/, $line; print "Checking item $item [$beg, $end] against BED file\n"; for my $rBED (@ABED) { if (overlaps([$beg, $end], $rBED)) { print "Item $item overlaps $rBED->[2]\n"; } } print "\n"; } sub overlaps { my ($lBeg, $lEnd) = @{$_[0]}; my ($rBeg, $rEnd) = @{$_[1]}; return 1 if $rBeg>$lBeg and $rBeg<$lEnd; return 1 if $rEnd>$lBeg and $rEnd<$lEnd; return 1 if $lBeg>$rBeg and $lBeg<$rEnd; return 1 if $lEnd>$rBeg and $lEnd<$rEnd; return 0; }