/usr/bin/bed2gff3 is in gbrowse 2.56+dfsg-3build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | #!/usr/bin/perl
# convert UCSC gene files into GFF3 data
use strict;
use File::Basename 'basename';
use Getopt::Long;
my $executable = basename($0);
my ($SRC,$ORIGIN);
GetOptions('src:s' => \$SRC,
'origin:i' => \$ORIGIN,
) or die <<USAGE;
Usage: $0 [options] ucsc_file1 ucsc_file2...
Convert UCSC Genome Browser BED-format gene files into GFF3 version files.
Only the gene IDs and their locations come through. You have to get
the comments and aliases some other way.
Options:
-src <string> Choose a source for the gene, default "UCSC"
-origin <integer> Choose a relative position to number from, default is "1"
The resulting file is in GFF3 format and should be loaded into a
Bio::DB::GFF database using the following command:
bp_bulk_load_gff.pl -c -d db1 --maxfeature 1000000000 --gff3_munge file.gff
USAGE
$SRC ||= 'UCSC';
$ORIGIN ||= 1;
print "##gff-version 3\n";
# automatically uncompress varous compression formats
foreach (@ARGV) {
$_ = "gunzip -c $_ |" if /\.gz$/;
$_ = "uncompress -c $_ |" if /\.Z$/;
$_ = "bunzip2 -c $_ |" if /\.bz2$/;
}
while (<>) {
chomp;
next if /^\#/;;
next if /random/; ## added line
my ($chrom,$txStart,$txEnd,$id,$score,$strand,$cdsStart,$cdsEnd,
$itemRGB,$exonCount,$exonSizes,$exonStarts) = split /\t/;
my ($utr5_start,$utr5_end,$utr3_start,$utr3_end);
# adjust for Jim's 0-based coordinates
$txStart++;
$cdsStart++;
$txStart -= $ORIGIN;
$txEnd -= $ORIGIN;
$cdsStart -= $ORIGIN;
$cdsEnd -= $ORIGIN;
# print the transcript
print join("\t",$chrom,$SRC,'mRNA',$txStart,$txEnd,'.',$strand,'.',"ID=$id;Name=$id"),"\n";
# now handle the CDS entries -- the tricky part is the need to keep
# track of phase
my $phase = 0;
my @exon_starts = map {$_-$ORIGIN+$txStart} split ',',$exonStarts;
my @exon_sizes = map {$_-$ORIGIN} split ',',$exonSizes;
my @exon_ends = map {$exon_starts[$_]+$exon_sizes[$_]+1} (0..@exon_sizes);
if ($strand eq '+') {
for (my $i=0;$i<@exon_starts;$i++) { # for each exon start
my $exon_start = $exon_starts[$i] + 1;
my $exon_end = $exon_ends[$i];
my (@utr_start,@utr_end,$cds_start,$cds_end);
if ($exon_start < $cdsStart) { # in a 5' UTR
push (@utr_start, $exon_start);
} elsif ($exon_start > $cdsEnd) {
push (@utr_start, $exon_start);
} else {
$cds_start = $exon_start;
}
if ($exon_end < $cdsStart) {
push (@utr_end, $exon_end);
} elsif ($exon_end > $cdsEnd) {
push (@utr_end, $exon_end);
} else {
$cds_end = $exon_end;
}
if ($utr_start[0] && !$utr_end[0]) { # half in half out on 5' end
$utr_end[0]= $cdsStart - 1;
$cds_start = $cdsStart;
$cds_end = $exon_end;
}
if ($utr_end[0] && !$utr_start[0]) { # half in half out on 3' end
$utr_start[0]= $cdsEnd + 1;
$cds_end = $cdsEnd;
$cds_start = $exon_start;
}
# If the CDS is within the exon
if (defined $utr_start[0] == defined $utr_end[0] &&
$utr_start[0] < $cdsStart && $utr_end[0] > $cdsEnd) {
$utr_end[0]= $cdsStart - 1;
$cds_start = $cdsStart;
$cds_end = $cdsEnd;
push (@utr_start, $cdsEnd + 1);
push (@utr_end, $exon_end);
}
die "programmer error, not an even number of utr_starts and
utr_ends"
unless $#utr_start == $#utr_end;
die "programmer error, cds_start and no cds_end"
unless defined $cds_start == defined $cds_end;
for (my $i=0;$i<@utr_start;$i++) { # for each utr start
if (defined $utr_start[$i] && $utr_start[$i] <= $utr_end[$i] &&
$utr_start[$i] < $cdsStart) {
print join
("\t",$chrom,$SRC,"five_prime_UTR",$utr_start[$i],$utr_end[$i],'.',$strand,'.',"Parent=$id"),"\n"
} # end of if
} # end of foreach
if (defined $cds_start && $cds_start <= $cds_end) {
print join
("\t",$chrom,$SRC,'CDS',$cds_start,$cds_end,'.',$strand,$phase,"Parent=$id"),"\n";
$phase = (($cds_end-$cds_start+1-$phase)) % 3;
}
for (my $i=0;$i<@utr_start;$i++) { # for each utr start
if (defined $utr_start[$i] && $utr_start[$i] <= $utr_end[$i] &&
$utr_start[$i] > $cdsEnd) {
print join ("\t",$chrom,$SRC,"three_prime_UTR",,$utr_start[$i],
$utr_end[$i],'.',$strand,'.',"Parent=$id"),"\n"
}
}
} # end of for each exon
} # matches if strand = +
if ($strand eq '-') {
my @lines;
for (my $i=@exon_starts-1; $i>=0; $i--) { # count backwards
my $exon_start = $exon_starts[$i] + 1;
my $exon_end = $exon_ends[$i];
my (@utr_start,@utr_end,$cds_start,$cds_end);
if ($exon_end > $cdsEnd) { # in a 5' UTR
push (@utr_end, $exon_end);
} elsif ($exon_end < $cdsStart) {
push (@utr_end, $exon_end);
} else {
$cds_end = $exon_end;
}
if ($exon_start > $cdsEnd) {
push (@utr_start, $exon_start);
} elsif ($exon_start < $cdsStart) {
push (@utr_start, $exon_start);
} else {
$cds_start = $exon_start;
}
if ($utr_start[0] && !$utr_end[0]) { # half in half out on 3' end
$utr_end[0] = $cdsStart - 1;
$cds_start = $cdsStart;
$cds_end = $exon_end;
}
if ($utr_end[0] && !$utr_start[0]) { # half in half out on 5' end
$utr_start[0] = $cdsEnd + 1;
$cds_end = $cdsEnd;
$cds_start = $exon_start;
}
# If the CDS is within the exon
if (defined $utr_start[0] == defined $utr_end[0] &&
$utr_start[0] < $cdsStart && $utr_end[0] > $cdsEnd) {
$utr_end[0]= $cdsStart - 1;
$cds_start = $cdsStart;
$cds_end = $cdsEnd;
push (@utr_start, $cdsEnd + 1);
push (@utr_end, $exon_end);
}
die "programmer error, not an even number of utr_starts and
utr_ends"
unless $#utr_start == $#utr_end;
die "programmer error, cds_start and no cds_end" unless defined
$cds_start == defined $cds_end;
for (my $i=0;$i<@utr_start;$i++) { # for each utr start
if (defined $utr_start[$i] && $utr_start[$i] <= $utr_end[$i] &&
$utr_start[$i] > $cdsEnd) {
unshift @lines,join
("\t",$chrom,$SRC,"five_prime_UTR",,$utr_start[$i],$utr_end[$i],'.',$strand,'.',"Parent=$id"),"\n"
}
} # end of for
if (defined $cds_start && $cds_start <= $cds_end) {
unshift @lines,join
("\t",$chrom,$SRC,'CDS',$cds_start,$cds_end,'.',$strand,$phase,"Parent=$id"),"\n";
$phase = (($cds_end-$cds_start+1-$phase)) % 3;
}
for (my $i=0;$i<@utr_start;$i++) { # for each utr start
if (defined $utr_start[$i] && $utr_start[$i] <= $utr_end[$i] &&
$utr_end[$i] < $cdsStart) {
unshift @lines,join
("\t",$chrom,$SRC,"three_prime_UTR",$utr_start[$i],$utr_end[$i],'.',$strand,'.',"Parent=$id"),"\n"
}
} # end for
}
print @lines;
}
} # end while <>
__END__
=head1 NAME
ucsc_genes2gff.pl - Convert UCSC Genome Browser-format gene files into GFF
files suitable for loading into gbrowse
=head1 SYNOPSIS
% uscsc_genes2gff.pl [options] ucsc_file1 ucsc_file2...
Options:
-src <string> Choose a source for the gene, default "UCSC"
-origin <integer> Choose a relative position to number from, default
is "1"
=head1 DESCRIPTION
This script massages the gene files available from the "tables" link
of the UCSC genome browser (genome.ucsc.edu) into a form suitable for
loading of gbrowse. Warning: it only works with the gene tables.
Other tables, such as EST alignments, contours and repeats, have their
own formats which will require other scripts to parse.
To use this script, get one or more UCSC tables, either from the
"Tables" link on the browser, or from the UCSC Genome Browser FTP
site. Give the table file as the argument to this script. You may
want to provide an alternative "source" field. Otherwise this script
defaults to "UCSC".
% pucsc_genes2gff.pl -src RefSeq refseq_data.ucsc > refseq.gff
The resulting GFF file can then be loaded into a Bio::DB::GFF database
using the following command:
% bulk_load_gff.pl -d <databasename> refseq.gff
=head1 SEE ALSO
L<Bio::DB::GFF>, L<bulk_load_gff.pl>, L<load_gff.pl>
=head1 AUTHOR
Lincoln Stein <lstein@cshl.org>.
Copyright (c) 2003 Cold Spring Harbor Laboratory
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself. See DISCLAIMER.txt for
disclaimers of warranty.
=cut
|