Hi monks i have 2 files
file1 contig1 10037203 10038203 blah contig1 10037203 10038203 blah contig1 10037203 10038203 blah
file2 contig1 997329 938329 blab11 contig1 10037329 10038329 blah11 contig1 10037329 10038329 blah11
i want to get my output as below
contig1 10037203 10038203 blah contig1 10037203 10038203 blah contig1 10037203 10038203 blah contig1 10037329 10038329 blah11 contig1 10037329 10038329 blah11
i,e., if the overlap exists first output all the overlapping ones of file1 and then of file2 i was able to read each line by line and then compare but that is not what i want. here is what i was doing
open FILE1,"file1" or die "can't open file 1"; open FILE2,"file2" or die "can't open file 2"; open(w1,">output"); while ((my $line1 = <FILE1>) && (my $line2 = <FILE2>)) { chomp $line1; chomp $line2; my @cond1 = split("\t" , $line1); my @cond2 = split("\t" , $line2); if(($cond1[1] >= $cond2[1]) && ($cond1[2] <= $cond2[2])) { print w1 "$line1\t$line2\n"; } } close FILE1; close FILE2; close w1;

In reply to output the overlapping regions to new file by Anonymous Monk

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.