ensembl-hive  2.7.0
CoreInfo.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 package XrefMapper::CoreInfo;
21 use strict;
22 use warnings;
23 
24 use vars '@ISA';
25 @ISA = qw{ XrefMapper::BasicMapper };
26 
28 
29 use Cwd;
30 use DBI;
31 use File::Basename;
32 use IPC::Open3;
33 
34 # Get info from the core database.
35 
36 # Need to load tables:-
37 #
38 # gene_transcript_translation
39 # gene_stable_id
40 # transcript_stable_id
41 # translation_stable_id
42 
43 
44 sub new {
45  my($class, $mapper) = @_;
46 
47  my $self ={};
48  bless $self,$class;
49  $self->core($mapper->core);
50  $self->xref($mapper->xref);
51  $self->verbose($mapper->verbose);
52  return $self;
53 }
54 
55 
56 
57 sub get_core_data {
58  my $self = shift;
59 
60  # gene_transcript_translation
61  # gene_stable_id
62  # transcript_stable_id
63  # translation_stable_id
64 
65 
66  # load table gene_transcript_translation
67 
68  $self->load_gene_transcript_translation();
69 
70  # load table xxx_stable_id
71 
72  $self->load_stable_ids();
73 
74 
75  my $sth = $self->xref->dbc->prepare("insert into process_status (status, date) values('core_data_loaded',now())");
76  $sth->execute();
77  $sth->finish;
78 
79 
80  return;
81 }
82 
83 
84 sub load_gene_transcript_translation{
85  my ($self) = shift;
86 
87  my $ins_sth = $self->xref->dbc->prepare("insert ignore into gene_transcript_translation (gene_id, transcript_id, translation_id) values (?, ?, ?)");
88 
89  my $sql = "select tn.gene_id, tn.transcript_id, tl.translation_id from transcript tn left join translation tl on tl.transcript_id = tn.transcript_id";
90  my $sth = $self->core->dbc->prepare($sql);
91  $sth->execute();
92  my ($gene_id, $transcript_id, $translation_id);
93  $sth->bind_columns(\$gene_id, \$transcript_id, \$translation_id);
94  while($sth->fetch()){
95  $ins_sth->execute($gene_id, $transcript_id, $translation_id);
96  }
97  $ins_sth->finish;
98  $sth->finish;
99  return;
100 }
101 
102 sub load_stable_ids{
103  my ($self) = shift;
104 
105  my ($id, $stable_id, $biotype);
106  foreach my $table (qw(gene translation)){
107 
108  my $sth = $self->core->dbc->prepare("select ".$table."_id, stable_id from ".$table);
109  my $ins_sth = $self->xref->dbc->prepare("insert ignore into ".$table."_stable_id (internal_id, stable_id) values(?, ?)");
110  $sth->execute();
111  $sth->bind_columns(\$id, \$stable_id);
112  while($sth->fetch){
113  $ins_sth->execute($id, $stable_id);
114  }
115  $ins_sth->finish;
116  $sth->finish;
117  }
118 
119  #populate transcript_stable_id table incuding the biotype column
120  my $table = "transcript";
121  my $sth = $self->core->dbc->prepare("select ".$table."_id, stable_id, biotype from ".$table);
122  my $ins_sth = $self->xref->dbc->prepare("insert ignore into ".$table."_stable_id (internal_id, stable_id, biotype) values(?, ?, ?)");
123  $sth->execute();
124  $sth->bind_columns(\$id, \$stable_id, \$biotype);
125  while($sth->fetch){
126  $ins_sth->execute($id, $stable_id, $biotype);
127  }
128  $ins_sth->finish;
129  $sth->finish;
130 
131  return;
132 }
133 1;
XrefMapper::db::dbc
public dbc()
XrefMapper::BasicMapper
Definition: BasicMapper.pm:8
XrefMapper::BasicMapper::core
public XrefMapper::db core()