Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.