http://www.perlmonks.org?node_id=1024136


in reply to Creating 2D array / Matrix

This post finds overlapping .bed files, if that helps.

The link above will find overlapping ranges. If you just want to list both .bed files in sorted order, then the following will do it.

#!/usr/bin/perl use strict; use warnings; use 5.014; @ARGV = qw/ 148N.txt 162N.txt 174N.txt 175N.txt /; my @data = map {[split]} map {$_->[0]} sort {$a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] || $a->[3] +<=> $b->[3]} map {[ $_, /\d+/g]} <>; say "@$_" for @data;
Ouput from the 4 files (in sorted order):
C:\Old_Data\perlp>perl t6.pl chr1 10 50 chr1 12 40 chr1 20 45 chr1 25 30 chr1 25 50 chr1 41 45 chr1 48 80 chr1 60 80 chr1 100 500 chr10 10 20

Update: changed the sort and made simpler and still correct. .bed file definition from here.