|
|
| Think about Loose Coupling | |
| PerlMonks |
Re^5: Find overlapby Cristoforo (Chaplain) |
| on Oct 17, 2012 at 15:42 UTC ( #999564=note: print w/ replies, xml ) | Need Help?? |
|
Here is a solution that won't include non-overlapping regions. It uses the Sort::Naturally and List::Util modules. It also prints out the number of overlapping records, (merged 3 says 3 records overlapped this range). You can change the print statement to not print this if you (probably) want. For each chromosome, the records are sorted in order from the smallest beginning position to the largest beginning position. This simplifies the logic and makes a solution possible. The code that does this is: my ($first, @in_order) = sort {$a->[0] <=> $b->[0]} @{ $data{$chr} }; And, this is the program. Update: Just a note - you don't need the 'nsort' function from the Sort::Naturally module for the program to process correctly. This would merely order your chromosomes in your output. And, if you can't use List::Util for the max function, you could easily define it yourself. I used the module just to save some additional code.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||