Skip to content

Instantly share code, notes, and snippets.

@Puriney
Created September 21, 2013 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Puriney/6655074 to your computer and use it in GitHub Desktop.
Save Puriney/6655074 to your computer and use it in GitHub Desktop.
PERL: Union Gene Model
#!/usr/bin/perl -w
use strict;
# Notice:
# BED annotation should be sorted by the GeneID or GeneName ahead
# otherwise duplication in output
my $inBed = shift || die $!;
my $outUnion = shift || die $!;
open OUT, "> $outUnion";
open IN, $inBed;
my $lastID = "";
while (<IN>) {
chomp;
my $info = $_;
my @info = split /\t/, $info;
my $id = $info[3];
# AT1G01010.1 -> AT1G01010
$id =~ s/(\w+)\.(\d+)/$1/g ;
if ($id ne $lastID) {
# grep loci, mergeBed, awk to std BED6
# print $id . "\n";
print OUT `grep $id $inBed | mergeBed -i stdin -s -nms | awk '{print \$1,\$2,\$3,\$4,0,\$5}' OFS="\t" `;
$lastID = $id;
}
else {
next ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment