Created
September 21, 2013 23:10
-
-
Save Puriney/6655074 to your computer and use it in GitHub Desktop.
PERL: Union Gene Model
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/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