Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
file1 contig1 10037203 10038203 blah contig1 10037203 10038203 blah contig1 10037203 10038203 blah
i want to get my output as belowfile2 contig1 997329 938329 blab11 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 doingcontig1 10037203 10038203 blah contig1 10037203 10038203 blah contig1 10037203 10038203 blah contig1 10037329 10038329 blah11 contig1 10037329 10038329 blah11
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;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: output the overlapping regions to new file
by starX (Chaplain) on Jan 22, 2014 at 17:13 UTC | |
Re: output the overlapping regions to new file
by Laurent_R (Canon) on Jan 22, 2014 at 22:59 UTC | |
Re: output the overlapping regions to new file
by bioinformatics (Friar) on Jan 24, 2014 at 00:21 UTC |