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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |