Hi Monks, I have three tab-delim files.
mainfile START STOP TYPE MEAN 1456 5385 p 98 6739 5468 n 87 6543 7275 n 54
file 1 NAME-WITH START STOP qqq 4202 8644 rrr 6399 3256 eee 6438 8456 …. … ttt 1456 5385 ggg 6543 7275
file 2 NAME-WITHOUT START STOP ddd 3467 3284 bbb 6739 5468

What I want is to input the first file and read in the following file 1 and file 2. So something like this should be happening, Checking the main file start and stop overlap with start and stop of first file 1 and second file 2.

Overlap of the starts and stops in each line of these files (file1 and file2) can be in following ways:

 start (file1/2)stop---- start(mainfile)stop----start(file1/2)stop


a. either the file1/2 stop is less than mainfile start ; then return 0
b. either the file1/2 start is less than mainfile stop; then return 0
or else if
a. the file1/2 stop is less than the mainfile start; then return 1 and say what name-without/with, start and stop (eg: qqq, 4202 8644)
b. the file1/2 start is less than mainfile stop; then return 1 and say what name-without/with, start and stop (eg: qqq, 4202 8644)
c. the file1/2 start and stop both is less than mainfile start stop; then return 1 and say what name-without/with, start and stop (eg: qqq, 4202 8644)
d. the file1/2 start and stop both is less than mainfile start stop; then return 1 and say what name-without/with, start and stop (eg: qqq, 4202 8644)

------------------------------

Is there any way to address this? I started working on the code but I am stuck as to how to proceed..Pardon if is difficult to understand what I am asking but I tried my best to describe the whole picture. Here is my code:

#!/usr/bin/perl #Open the mainfile with start, stop my $input_file = "/Users/myfolder/mainfile.txt"; die "Cannot open $input_file\n" unless (open(IN, $input_file)); my %start_stop_type; while (chomp($line = <IN>)) { my (@columns) = split /\s+/, $line; my $type = $columns[3]; my $start = $columns[1]; my $stop = $columns[2]; $type_and_start{$type} = $start; $type_and_stop{$type} = $stop; } close(IN); #Now open both the files i.e file1 and file2 with respective start and + stops open (MYFILE, "/Users/myfolder/file1.txt"); @file1 = <MYFILE>; close MYFILE; open (MYFILE2, "/Users/myfolder/file2.txt"); @file2 = <MYFILE2>; close MYFILE2; foreach $line (@file1,@file2){ ###NOT SURE?? if $file1/2_start<mainfile_start; return 0 ??? #Open output file and write the start stops of each name-with/without die "output.txt" unless(open(OUT,"> output.txt"));

In reply to comparing overlap? by perllearner007

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.