3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
6 Licensed under the Apache License, Version 2.0 (the
"License");
7 you may not use
this file except in compliance with the License.
8 You may obtain a copy of the License at
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an
"AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License
for the specific language governing permissions and
16 limitations under the License.
20 Please email comments or questions to the
public Ensembl
21 developers list at <http:
23 Questions may also be sent to the Ensembl help desk at
32 A parser
class to parse UCSC data for human and mouse.
51 Only columns listed in
@required_columns are mandatory.
59 files => [
'UCSC_human/knownGene.txt.gz'],
64 package XrefParser::UCSCParser;
82 my ( $self, $ref_arg ) = @_;
84 my $source_id = $ref_arg->{source_id};
85 my $species_id = $ref_arg->{species_id};
86 my $files = $ref_arg->{files};
87 my $verbose = $ref_arg->{verbose}
88 my $dbi = $ref_arg->{dbi}
90 if ( (!defined $source_id) || (!defined $species_id) || (!defined $files) ) {
91 confess
'Need to pass source_id, species_id and files as pairs';
94 my $file = @{$files}[0];
98 my $file_io = $self->get_filehandle($file);
99 if ( !defined $file_io ) {
100 confess
"Can't open UCSC file $file\n";
103 my $input_file = Text::CSV->new({
107 }) || confess
"Cannot use file $file: " . Text::CSV->error_diag();
109 while ( my $data = $input_file->getline( $file_io ) ) {
110 my (undef, $chromosome, $strand, $tx_start, $tx_end, $cds_start, $cds_end,
111 undef, $exon_starts, $exon_ends, undef, $accession) = @{ $data };
113 # UCSC uses slightly different chromosome names, at least for
114 # human and mouse, so chop off the 'chr' in the beginning. We do
115 # not yet translate the names of the special chromosomes, e.g.
116 # "chr6_cox_hap1" (UCSC) into "c6_COX" (Ensembl).
117 $chromosome =~ s{ \A chr }{}msx;
119 # They also use '+' and '-' for the strand, instead of -1, 0, or 1.
120 if ( $strand eq q{+} ) {
123 elsif ( $strand eq q{-} ) {
130 # ... and non-coding transcripts have cds_start == cds_end. We would
131 # like these to be stored as NULLs.
132 if ( $cds_start == $cds_end ) {
137 # $exon_starts and $exon_ends usually (always?) have trailing commas,
139 $exon_starts =~ s{ , \z }{}msx;
140 $exon_ends =~ s{ , \z }{}msx;
142 # ... and they use the same kind of "inbetween" coordinates as e.g.
143 # exonerate, so increment all start coordinates by one.
145 if ( defined $cds_start ) {
148 # The string exon_starts is a comma-separated list of start coordinates
149 # for subsequent exons and we must increment each one. Split the string
150 # on commas, use map() to apply the "+1" transformation to every
151 # element of the resulting array, then join the result into a new
152 # comma-separated list.
154 join q{,},
map { $_ + 1 } split qr{ , }msx, $exon_starts;
156 $self->add_xref( $source_id, $species_id, {
158 chromosome => $chromosome,
160 txStart => $tx_start,
162 cdsStart => $cds_start,
164 exonStarts => $exon_starts,
165 exonEnds => $exon_ends,
173 $input_file->eof || confess
"Error parsing file $file: " . $input_file->error_diag();
177 print
"Loaded a total of $count UCSC xrefs\n";