mgamar:

Now that erix provided a pointer to some information about your problem, here's a little sketch you might be able to pull some ideas out of:

use strict; use warnings; #### # Read BED file into an array #### my $BED_FILE = <<EOBED; chr7 127471196 127472363 Pos1 0 + 127471196 127472363 255,0, +0 chr7 127472363 127473530 Pos2 0 + 127472363 127473530 255,0, +0 chr7 127473530 127474697 Pos3 0 + 127473530 127474697 255,0, +0 chr7 127474697 127475864 Pos4 0 + 127474697 127475864 255,0, +0 chr7 127475864 127477031 Neg1 0 - 127475864 127477031 0,0,25 +5 chr7 127477031 127478198 Neg2 0 - 127477031 127478198 0,0,25 +5 chr7 127478198 127479365 Neg3 0 - 127478198 127479365 0,0,25 +5 chr7 127479365 127480532 Pos5 0 + 127479365 127480532 255,0, +0 chr7 127480532 127481699 Neg4 0 - 127480532 127481699 0,0,25 +5 EOBED my @ABED; open my $BFH, '<', \$BED_FILE; while (my $line = <$BFH>) { 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 = <<EOCOORDS; joe 123456789 123456900 Doesn't touch any of 'em bill 127473500 127474000 Intersects Pos2 and Pos3 judy 127480550 127480560 Inside Neg4 EOCOORDS open my $CFH, '<', \$COORDS_FILE; while (my $line = <$CFH>) { 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; }

When I run it, I get:

Checking item joe [123456789, 123456900] against BED file Checking item bill [127473500, 127474000] against BED file Item bill overlaps Pos2 Item bill overlaps Pos3 Checking item judy [127480550, 127480560] against BED file Item judy overlaps Neg4

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: extract sequences of DNA from coordinates by roboticus
in thread extract sequences of DNA from coordinates by mgamar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.