ensembl-hive  2.8.1
CoordinateParser.pm
Go to the documentation of this file.
1 =head1 LICENSE
2 
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5 
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
9 
10  http://www.apache.org/licenses/LICENSE-2.0
11 
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.
17 
18 =cut
19 
20 # $Id$
21 
22 # This sub-class of XrefParser::BaseParser serves as the parent class
23 # for parsers of Xref source data that we use coordinate overlap to
24 # determine the Xrefs to.
25 
26 package XrefParser::CoordinateParser;
27 
28 use strict;
29 use warnings;
30 
31 use Carp;
32 use DBI qw( :sql_types );
33 
34 use base qw( XrefParser::BaseParser );
35 
36 our $add_xref_sth;
37 our $add_xref_sql = q(
38  INSERT INTO coordinate_xref
39  ( source_id, species_id,
40  accession,
41  chromosome, strand,
42  txStart, txEnd,
43  cdsStart, cdsEnd,
44  exonStarts, exonEnds )
45  VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
46 );
47 
48 sub add_xref {
49  my $self = shift;
50  my ( $source_id, $species_id, $xref ) = @_;
51 
52  if ( !defined($add_xref_sth) ) {
53  my $dbh = $self->dbi();
54  $add_xref_sth = $dbh->prepare_cached($add_xref_sql);
55  if ( !defined($add_xref_sth) ) {
56  croak( $dbh->errstr() );
57  }
58  }
59 
60  for my $required_key ( 'accession', 'chromosome',
61  'strand', 'txStart',
62  'txEnd', 'exonStarts',
63  'exonEnds' )
64  {
65  if ( !defined( $xref->{$required_key} ) ) {
66  croak(
67  sprintf( "Missing required key '%s' for Xref", $required_key )
68  );
69  }
70  }
71 
72  $add_xref_sth->bind_param( 1, $source_id, SQL_INTEGER );
73  $add_xref_sth->bind_param( 2, $species_id, SQL_INTEGER );
74  $add_xref_sth->bind_param( 3, $xref->{'accession'}, SQL_VARCHAR );
75  $add_xref_sth->bind_param( 4, $xref->{'chromosome'}, SQL_VARCHAR );
76  $add_xref_sth->bind_param( 5, $xref->{'strand'}, SQL_INTEGER );
77  $add_xref_sth->bind_param( 6, $xref->{'txStart'}, SQL_INTEGER );
78  $add_xref_sth->bind_param( 7, $xref->{'txEnd'}, SQL_INTEGER );
79  $add_xref_sth->bind_param( 8, $xref->{'cdsStart'}, SQL_INTEGER );
80  $add_xref_sth->bind_param( 9, $xref->{'cdsEnd'}, SQL_INTEGER );
81  $add_xref_sth->bind_param( 10, $xref->{'exonStarts'}, SQL_VARCHAR );
82  $add_xref_sth->bind_param( 11, $xref->{'exonEnds'}, SQL_VARCHAR );
83 
84  $add_xref_sth->execute() or croak( $add_xref_sth->errstr() );
85 } ## end sub add_xref
86 
87 1;
accession
public accession()
XrefParser::BaseParser
Definition: BaseParser.pm:8