ensembl-hive  2.8.1
VBasicConverter.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 SeqStoreConverter::vega::VBasicConverter;
21 
22 use strict;
23 use warnings;
25 use vars qw(@ISA);
27 
28 sub remove_supercontigs {
29  my $self = shift;
30 
31  my $target = $self->target();
32  my $dbh = $self->dbh();
33  $self->debug("Vega specific - removing supercontigs from $target");
34 
35  $dbh->do("DELETE FROM $target.meta ".
36  "WHERE meta_value like '%supercontig%'");
37 
38  $dbh->do("DELETE FROM $target.coord_system ".
39  "WHERE name like 'supercontig'");
40 
41  $dbh->do("DELETE $target.a ".
42  "FROM $target.assembly a, $target.seq_region sr ".
43  "WHERE sr.coord_system_id = 2 ".
44  "and a.asm_seq_region_id = sr.seq_region_id");
45 
46  $dbh->do("DELETE FROM $target.seq_region ".
47  "WHERE coord_system_id = 2");
48 }
49 
50 sub copy_other_vega_tables {
51  my $self = shift;
52  $self->copy_tables(
53  # vega tables
54  "gene_synonym",
55  "transcript_info",
56  "current_gene_info",
57  "current_transcript_info",
58  "author",
59  "gene_name",
60  "transcript_class",
61  "gene_remark",
62  "gene_info",
63  "evidence",
64  "transcript_remark",
65  "clone_remark",
66  "clone_info",
67  "clone_info_keyword",
68  "assembly_tag",
69  );
70  eval { $self->copy_current_clone_info; };
71  warn $@ if $@;
72 }
73 
74 sub copy_current_clone_info {
75  my $self=shift;
76  my $source = $self->source();
77  my $target = $self->target();
78  my $sth = $self->dbh()->prepare
79  ("INSERT INTO $target.current_clone_info(clone_id,clone_info_id) SELECT * FROM $source.current_clone_info");
80  $sth->execute();
81  $sth->finish();
82 }
83 
84 sub update_clone_info {
85  my $self = shift;
86  return;
87 }
88 
89 sub copy_internal_clone_names {
90  my $self = shift;
91  return;
92 }
93 
94 sub copy_assembly_exception {
95  my $self = shift;
96 
97  # copy assembly_exception table
98  $self->debug('Vega specific - copying assembly_exception table');
99  $self->copy_tables('assembly_exception');
100 
101  my $source = $self->source();
102  my $target = $self->target();
103  my $dbh = $self->dbh();
104 
105  # fix seq_region_id in assembly_exception
106  $self->debug('Vega specific - Updating seq_region_id in assembly_exception table');
107  $dbh->do(qq(
108  UPDATE $target.assembly_exception, $target.tmp_chr_map
109  SET assembly_exception.seq_region_id = tmp_chr_map.new_id
110  WHERE assembly_exception.seq_region_id = tmp_chr_map.old_id
111  ));
112  $dbh->do(qq(
113  UPDATE $target.assembly_exception, $target.tmp_chr_map
114  SET assembly_exception.exc_seq_region_id = tmp_chr_map.new_id
115  WHERE assembly_exception.exc_seq_region_id = tmp_chr_map.old_id
116  ));
117 
118  # fix seq_region.length if necessary (this is the case if you have an
119  # assembly_exception at the end of a chromosome)
120  my $sth1 = $dbh->prepare(qq(
121  UPDATE $target.seq_region SET length = ? WHERE seq_region_id = ?
122  ));
123  my $sth2 = $dbh->prepare(qq(
124  SELECT
125  sr.seq_region_id,
126  sr.length,
127  max(ae.seq_region_end)
128  FROM
129  $target.seq_region sr,
130  $target.assembly_exception ae
131  WHERE sr.seq_region_id = ae.seq_region_id
132  GROUP BY ae.seq_region_id
133  ));
134  $sth2->execute;
135  while (my ($sr_id, $sr_length, $max_ae_length) = $sth2->fetchrow_array) {
136  if ($max_ae_length > $sr_length) {
137  $self->debug(" Updating seq_region.length for $sr_id (old $sr_length, new $max_ae_length)");
138  $sth1->execute($max_ae_length, $sr_id);
139  }
140  }
141 }
142 
143 # reset gene, transcript, gene_description and external_db tables back to 30
144 sub back_patch_schema {
145  my $self = shift;
146  $self->debug ("Patching gene, transcript, gene_description and external_db tables back to sch-30");
147  my $target = $self->target;
148  my $dbh = $self->dbh;
149  $dbh->do("DROP TABLE $target.gene");
150  $dbh->do( qq(CREATE TABLE $target.gene (
151  `gene_id` int(10) unsigned NOT NULL auto_increment,
152  `type` varchar(40) NOT NULL default '',
153  `analysis_id` int(11) default NULL,
154  `seq_region_id` int(10) unsigned NOT NULL default '0',
155  `seq_region_start` int(10) unsigned NOT NULL default '0',
156  `seq_region_end` int(10) unsigned NOT NULL default '0',
157  `seq_region_strand` tinyint(2) NOT NULL default '0',
158  `display_xref_id` int(10) unsigned default NULL,
159  PRIMARY KEY (`gene_id`),
160  KEY `seq_region_idx` (`seq_region_id`,`seq_region_start`),
161  KEY `xref_id_index` (`display_xref_id`),
162  KEY `analysis_idx` (`analysis_id`)
163  ) ENGINE=MyISAM DEFAULT CHARSET=latin1
164  ));
165  $dbh->do("DROP TABLE $target.transcript");
166  $dbh->do( qq(CREATE TABLE $target.transcript (
167  `transcript_id` int(10) unsigned NOT NULL auto_increment,
168  `gene_id` int(10) unsigned NOT NULL default '0',
169  `seq_region_id` int(10) unsigned NOT NULL default '0',
170  `seq_region_start` int(10) unsigned NOT NULL default '0',
171  `seq_region_end` int(10) unsigned NOT NULL default '0',
172  `seq_region_strand` tinyint(2) NOT NULL default '0',
173  `display_xref_id` int(10) unsigned default NULL,
174  PRIMARY KEY (`transcript_id`),
175  KEY `seq_region_idx` (`seq_region_id`,`seq_region_start`),
176  KEY `gene_index` (`gene_id`),
177  KEY `xref_id_index` (`display_xref_id`)
178  ) ENGINE=MyISAM DEFAULT CHARSET=latin1
179  ));
180  $dbh->do( qq(CREATE TABLE $target.gene_description (
181  `gene_id` int(10) unsigned NOT NULL default '0',
182  `description` text,
183  PRIMARY KEY (`gene_id`)
184  ) ENGINE=MyISAM DEFAULT CHARSET=latin1
185  ));
186  $dbh->do("DROP TABLE $target.external_db");
187  $dbh->do( qq(CREATE TABLE $target.external_db (
188  `external_db_id` int(11) NOT NULL default '0',
189  `db_name` varchar(100) NOT NULL default '',
190  `release` varchar(40) NOT NULL default '',
191  `status` enum('KNOWNXREF','KNOWN','XREF','PRED','ORTH','PSEUDO') NOT NULL default 'KNOWNXREF',
192  PRIMARY KEY (`external_db_id`)
193  ) ENGINE=MyISAM DEFAULT CHARSET=latin1
194  ));
195 }
196 
197 
198 
199 
SeqStoreConverter::BasicConverter
Definition: BasicConverter.pm:3