0
|
1 =head1 LICENSE
|
|
2
|
|
3 Copyright (c) 1999-2011 The European Bioinformatics Institute and
|
|
4 Genome Research Limited. All rights reserved.
|
|
5
|
|
6 This software is distributed under a modified Apache license.
|
|
7 For license details, please see
|
|
8
|
|
9 http://www.ensembl.org/info/about/code_licence.html
|
|
10
|
|
11 =head1 CONTACT
|
|
12
|
|
13 Please email comments or questions to the public Ensembl
|
|
14 developers list at <ensembl-dev@ebi.ac.uk>.
|
|
15
|
|
16 Questions may also be sent to the Ensembl help desk at
|
|
17 <helpdesk@ensembl.org>.
|
|
18
|
|
19 =cut
|
|
20
|
|
21 package Bio::EnsEMBL::Funcgen::Parsers::BaseExternalParser;
|
|
22
|
|
23 use strict;
|
|
24
|
|
25 use Bio::EnsEMBL::DBSQL::DBAdaptor;
|
|
26 use Bio::EnsEMBL::Utils::Argument qw( rearrange );
|
|
27 use Bio::EnsEMBL::Utils::Exception qw( throw );
|
|
28 use Bio::EnsEMBL::Funcgen::FeatureSet;
|
|
29 use Bio::EnsEMBL::Funcgen::FeatureType;
|
|
30 use Bio::EnsEMBL::Analysis;
|
|
31 #use Bio::EnsEMBL::Funcgen::Parsers::BaseImporter;
|
|
32 #use vars qw(@ISA)
|
|
33 #@ISA = ('Bio::EnsEMBL::Funcgen::Utils::Helper');
|
|
34
|
|
35 use base qw(Bio::EnsEMBL::Funcgen::Parsers::BaseImporter); #@ISA change to parent with perl 5.10
|
|
36
|
|
37
|
|
38
|
|
39 # Base functionality for external_feature parsers
|
|
40
|
|
41 #Make this inherit from Helper?
|
|
42 #Then change all the prints to logs
|
|
43
|
|
44 sub new {
|
|
45 my $caller = shift;
|
|
46 my $class = ref($caller) || $caller;
|
|
47 my $self = $class->SUPER::new(@_);
|
|
48
|
|
49 #validate and set type, analysis and feature_set here
|
|
50 my ($type, $db, $archive, $import_fsets) = rearrange(['TYPE', 'DB', 'ARCHIVE', 'IMPORT_SETS'], @_);
|
|
51
|
|
52 #What is ExternalParser specific here?
|
|
53 #archive?
|
|
54 #type? is this even used?
|
|
55
|
|
56
|
|
57 #throw('You must define a type of external_feature to import') if(! defined $type);
|
|
58
|
|
59 if (! ($db && ref($db) &&
|
|
60 $db->isa('Bio::EnsEMBL::Funcgen::DBSQL::DBAdaptor'))){
|
|
61 throw('You must provide a valid Bio::EnsEMBL::Funcgen::DBSQL::DBAdaptor');
|
|
62 }
|
|
63
|
|
64 throw('You can only specify either -clobber|rollback or -archive, but not both') if($self->rollback && $archive);
|
|
65
|
|
66 $self->{display_name_cache} = {};
|
|
67 $self->{'db'} = $db;
|
|
68 #$self->{type} = $type;
|
|
69 $self->{archive} = $archive if defined $archive;
|
|
70
|
|
71
|
|
72 #This is not fully implemented yet and need to be validated against the config feature_set
|
|
73 #pass something like set1,set2 and split and validate each.
|
|
74 #Or do this in the calling script?
|
|
75
|
|
76 throw('-import_sets not fully implemented yet') if defined $import_fsets;
|
|
77 $self->{'import_sets'} = (defined $import_fsets) ? @{$import_fsets} : undef;
|
|
78
|
|
79 $self->log("Parsing and loading $type ExternalFeatures");
|
|
80
|
|
81 return $self;
|
|
82
|
|
83 }
|
|
84
|
|
85
|
|
86 =head2 import_sets
|
|
87
|
|
88 Args : None
|
|
89 Example : foreach my $import_set_name(@{$self->import_sets}){ ... do the import ... }
|
|
90 Description: Getter for the list of import feature set names, defaults to all in parser config.
|
|
91 Returntype : Arrayref of import feature_set names
|
|
92 Exceptions : None
|
|
93 Caller : General
|
|
94 Status : Medium Risk
|
|
95
|
|
96 =cut
|
|
97
|
|
98 sub import_sets{
|
|
99 my $self = shift;
|
|
100
|
|
101 return $self->{'import_sets'} || [keys %{$self->{static_config}{feature_sets}}];
|
|
102 }
|
|
103
|
|
104
|
|
105 =head2 set_feature_sets
|
|
106
|
|
107 Args : None
|
|
108 Example : $self->set_feature_sets;
|
|
109 Description: Imports feature sets defined by import_sets.
|
|
110 Returntype : None
|
|
111 Exceptions : Throws if feature set already present and rollback or archive not set
|
|
112 Caller : General
|
|
113 Status : Medium Risk
|
|
114
|
|
115 =cut
|
|
116
|
|
117 #This is done after validate and store feature_types
|
|
118 #Updating this will require making all external parsers use 'static_config'
|
|
119
|
|
120 sub set_feature_sets{
|
|
121 my $self = shift;
|
|
122
|
|
123 throw('Must provide a set feature_set config hash') if ! defined $self->{static_config}{feature_sets};
|
|
124
|
|
125
|
|
126 my $fset_adaptor = $self->db->get_FeatureSetAdaptor;
|
|
127 my $analysis_adaptor = $self->db->get_AnalysisAdaptor;
|
|
128
|
|
129 foreach my $fset_name(@{$self->import_sets}){
|
|
130
|
|
131 $self->log("Defining FeatureSet:\t$fset_name");
|
|
132 my $fset = $fset_adaptor->fetch_by_name($fset_name);
|
|
133
|
|
134 #we don't need data sets for external_feature sets!
|
|
135 #Compare against config after we have merged with defined_anld_validate etc
|
|
136
|
|
137 if(defined $fset){
|
|
138 $self->log("Found previous FeatureSet $fset_name");
|
|
139
|
|
140 if($self->rollback){
|
|
141
|
|
142 $self->rollback_FeatureSet($fset);#Need to pass \@slices here?
|
|
143 }
|
|
144 elsif($self->{'archive'}){
|
|
145 my $archive_fset = $fset_adaptor->fetch_by_name($fset_name."_v".$self->{'archive'});
|
|
146
|
|
147 if(defined $archive_fset){
|
|
148 throw("You are trying to create an archive external feature_set which already exists:\t${fset_name}_v".$self->{archive});
|
|
149 }
|
|
150
|
|
151 my $sql = "UPDATE feature_set set name='$fset_name}_v".$self->{archive}."' where name='$fset_name'";
|
|
152 $self->db->dbc->do($sql);
|
|
153 undef $fset;
|
|
154 }else{
|
|
155 throw("You are trying to create an external feature_set which already exists:\t$fset_name\nMaybe to want to rollback or archive?");
|
|
156 }
|
|
157 }
|
|
158
|
|
159 #Assume using static config for now
|
|
160 #Will need to resolve this when it become generic
|
|
161 #Maybe we set outside of config!
|
|
162 #simply as analyses, feature_sets and feature_types?
|
|
163 my $fset_config = $self->{static_config}{feature_sets}{$fset_name}{feature_set};
|
|
164
|
|
165
|
|
166 if(! defined $fset){
|
|
167 my ($name, $analysis, $ftype, $display_label, $desc);
|
|
168 my $fset_analysis_key = (exists ${$fset_config}{-analysis}) ? '-analysis' : '-ANALYSIS';
|
|
169 my $fset_name_key = (exists ${$fset_config}{-name}) ? '-name' : '-NAME';
|
|
170 my $fset_ftype_key = (exists ${$fset_config}{-feature_type}) ? '-feature_type' : '-FEATURE_TYPE';
|
|
171 my $fset_dlabel_key = (exists ${$fset_config}{-display_label}) ? '-display_label' : '-DISPLAY_LABEL';
|
|
172 my $fset_desc_key = (exists ${$fset_config}{-description}) ? '-description' : '-DESCRIPTION';
|
|
173 my $display_name = (exists ${$fset_config}{$fset_dlabel_key}) ? $fset_config->{$fset_dlabel_key} : $fset_name;
|
|
174 #fset config name be different from key name
|
|
175 my $fs_name = (exists ${$fset_config}{$fset_name_key}) ? $fset_config->{$fset_name_key} : $fset_name;
|
|
176 #warn if they are different?
|
|
177
|
|
178
|
|
179 #Can't just deref config hash here as we need to deref the nested feature_type and analysis attrs
|
|
180
|
|
181 $fset = Bio::EnsEMBL::Funcgen::FeatureSet->new(
|
|
182 -name => $fs_name,
|
|
183 -feature_class=> 'external',
|
|
184 -analysis => ${$fset_config->{$fset_analysis_key}},
|
|
185 -feature_type => ${$fset_config->{$fset_ftype_key}},
|
|
186 -display_label => $display_name,
|
|
187 -description => $fset_config->{$fset_desc_key}
|
|
188 );
|
|
189
|
|
190 ($fset) = @{$self->db->get_FeatureSetAdaptor->store($fset)};
|
|
191 }
|
|
192
|
|
193 #Now replace config hash with object
|
|
194 #Will this reset in hash or just locally?
|
|
195 #$fset_config = $fset;
|
|
196 $self->{static_config}{feature_sets}{$fset_name}{feature_set} = $fset;
|
|
197 }
|
|
198
|
|
199 return;
|
|
200 }
|
|
201
|
|
202 #Can't use this anymore as we have to use static_config for all parsers which use set_feature_sets
|
|
203
|
|
204 #
|
|
205 #=head2 validate_and_store_feature_types
|
|
206 #
|
|
207 # Args : None
|
|
208 # Example : $self->validate_and_store_feature_types;
|
|
209 # Description: Imports feature types defined by import_sets.
|
|
210 # Returntype : None
|
|
211 # Exceptions : None
|
|
212 # Caller : General
|
|
213 # Status : High Risk - Now using BaseImporter::validate_and_store_config for vista
|
|
214 #
|
|
215 #=cut
|
|
216 #
|
|
217 ##Change all external parsers to use BaseImporter::validate_and_store_config
|
|
218 #
|
|
219 #sub validate_and_store_feature_types{
|
|
220 # my $self = shift;
|
|
221 #
|
|
222 # #This currently only stores ftype associated with the feature_sets
|
|
223 # #Havent't we done this already in the InputSet parser
|
|
224 # #Need to write BaseImporter and inherit from there.
|
|
225 #
|
|
226 # #InputSet does all loading, but depends on 'user_config'
|
|
227 # #Where as we are using hardcoded config here
|
|
228 # #Which are import_sets currently defaults to feature_sets keys
|
|
229 #
|
|
230 # #we could simply call this static_config and let user_config over-write static config with warnings?
|
|
231 # #on an key by key basis? (top level only?)
|
|
232 #
|
|
233 #
|
|
234 # my $ftype_adaptor = $self->db->get_FeatureTypeAdaptor;
|
|
235 #
|
|
236 # foreach my $import_set(@{$self->import_sets}){
|
|
237 #
|
|
238 # my $ftype_config = ${$self->{static_config}{feature_sets}{$import_set}{feature_type}};
|
|
239 # my $ftype = $ftype_adaptor->fetch_by_name($ftype_config->{'name'});
|
|
240 #
|
|
241 # $self->log("Validating $import_set FeatureType:\t".$ftype_config->{'name'});
|
|
242 #
|
|
243 # if(! defined $ftype){
|
|
244 # $self->log("FeatureType '".$ftype_config->{'name'}."' for external feature_set ".$self->{'type'}." not present");
|
|
245 # $self->log("Storing using type hash definitions");
|
|
246 #
|
|
247 # $ftype = Bio::EnsEMBL::Funcgen::FeatureType->new(
|
|
248 # -name => $ftype_config->{'name'},
|
|
249 # -class => $ftype_config->{'class'},
|
|
250 # -description => $ftype_config->{'description'},
|
|
251 # );
|
|
252 # ($ftype) = @{$ftype_adaptor->store($ftype)};
|
|
253 # }
|
|
254 #
|
|
255 # #Replace hash config with object
|
|
256 # $self->{static_config}{feature_types}{$ftype_config->{'name'}} = $ftype;
|
|
257 # }
|
|
258 #
|
|
259 # return;
|
|
260 #}
|
|
261 #
|
|
262
|
|
263
|
|
264
|
|
265
|
|
266
|
|
267
|
|
268
|
|
269 1;
|