Created
June 14, 2012 10:30
-
-
Save ray1729/2929488 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings FATAL => 'all'; | |
use List::Util qw(max min); | |
my @COLS = qw( label _ chr strand start end ); | |
my @KEY_COLS = qw( label chr strand ); | |
my %refSeq; | |
while (<>) { | |
chomp; | |
my %h; | |
@h{@COLS} = split "\t"; | |
my $key = join ':', @h{@KEY_COLS}; | |
if ( $refSeq{$key} ) { | |
$refSeq{$key}{start} = min( $refSeq{$key}{start}, $h{start} ); | |
$refSeq{$key}{end} = max( $refSeq{$key}{end}, $h{end} ); | |
} | |
else { | |
$refSeq{$key} = \%h; | |
} | |
} | |
for ( sort { $a->{chr} cmp $b->{chr} || $a->{start} <=> $b->{start} || $a->{end} <=> $b->{end} } values %refSeq ) { | |
print join( "\t", @{$_}{@COLS} ) . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment