Skip to content

Instantly share code, notes, and snippets.

@ray1729
Created June 14, 2012 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ray1729/2929488 to your computer and use it in GitHub Desktop.
Save ray1729/2929488 to your computer and use it in GitHub Desktop.
#!/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