-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtripal_analysis_kegg.install
executable file
·281 lines (262 loc) · 9.39 KB
/
tripal_analysis_kegg.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<?php
/**
* Implementation of hook_install();
*/
function tripal_analysis_kegg_install() {
// Register this analysis module.
tripal_register_analysis_child('tripal_analysis_kegg');
// Add the cvterms needed for this module.
tripal_analysis_kegg_add_cvterms();
// Make sure the KEGG databases we will be using exist. The list of
// KEGG databases can be found here: http://www.genome.jp/kegg/kegg3.html
// we only use three: KEGG PATHWAY, KEGG BRITE AND KEGG ORTHOLOGY.
tripal_insert_db(array(
'name' => 'KEGG_PATHWAY',
'description' => 'KEGG PATHWAY is a collection of manually ' .
'drawn pathway maps representing our knowledge on the molecular interaction ' .
'and reaction networks.',
'url' => 'http://www.genome.jp/kegg/pathway.html',
'urlprefix' => 'http://www.genome.jp/dbget-bin/www_bget?ko+'
));
tripal_insert_db(array(
'name' => 'KEGG_BRITE',
'description' => 'KEGG BRITE is a collection of hierarchical ' .
'classifications from KEGG.',
'url' => 'http://www.genome.jp/kegg/brite.html',
'urlprefix' => 'http://www.genome.jp/kegg-bin/get_htext?'
));
tripal_insert_db(array(
'name' => 'KEGG_ORTHOLOGY',
'description' => 'The KEGG Orthology (KO) system ' .
'consists of manually defined ortholog groups that correspond to ' .
'pathways, BRITE hierarchys and modules',
'url' => 'http://www.genome.jp/kegg/ko.html',
'urlprefix' => 'http://www.genome.jp/dbget-bin/www_bget?ko:'
));
tripal_insert_db(array(
'name' => 'KEGG_MODULE',
'description' => 'KEGG MODULE is a collection of manually '.
'defined functional units, called KEGG modules and identified by the '.
'M numbers, used for annotation and biological interpretation of '.
'sequenced genomes',
'url' => 'http://www.genome.jp/kegg/module.html',
'urlprefix' => 'http://www.genome.jp/kegg-bin/show_module?',
));
// Add in the controlled vocabularies for the KEGG database.
tripal_insert_cv('KEGG_PATHWAY','Holds terms from the KEGG PATHWAY database.');
tripal_insert_cv('KEGG_BRITE', 'Holds terms from the KEGG BRITE database.');
tripal_insert_cv('KEGG_ORTHOLOGY', 'Holds terms from the KEGG ORTHOLOGY database.');
tripal_insert_cv('KEGG_MODULE', 'Holds terms from the KEGG MODULE database.');
// Add the materialized view
tripal_analysis_kegg_add_mview_kegg_by_organism();
}
/**
* Creates a view showing the kegg results for each organism.
*
* @ingroup tripal_analysis
*/
function tripal_analysis_kegg_add_mview_kegg_by_organism() {
$view_name = 'kegg_by_organism';
$comment = t('This view is for associating an organism to a KEGG analysis.');
// this is the SQL used to identify the organism to which an analsysis
// has been used. This is obtained though the analysisfeature -> feature -> organism
// joins
$sql = "
SELECT DISTINCT A.name,A.analysis_id,F.organism_id
FROM analysisprop AP
INNER JOIN analysis A on A.analysis_id = AP.analysis_id
INNER JOIN cvterm CVT on CVT.cvterm_id = AP.type_id
INNER JOIN analysisfeature AF on AF.analysis_id = A.analysis_id
INNER JOIN feature F on F.feature_id = AF.feature_id
WHERE CVT.name = 'analysis_kegg_settings'
";
// the schema array for describing this view
$schema = array(
'table' => $view_name,
'description' => $comment,
'fields' => array(
'analysis_name' => array(
'type' => 'varchar',
'length' => 255,
),
'analysis_id' => array(
'type' => 'int',
'not null' => TRUE,
),
'organism_id' => array(
'type' => 'int',
'not null' => TRUE,
),
),
'indexes' => array(
'kegg_by_organism_indx0' => array('analysis_id'),
'kegg_by_organism_indx1' => array('organism_id'),
),
'foreign keys' => array(
'analysis' => array(
'table' => 'analysis',
'columns' => array(
'analysis_id' => 'analysis_id',
),
),
'organism' => array(
'table' => 'organism',
'columns' => array(
'organism_id' => 'organism_id',
),
),
),
);
// add the view
tripal_add_mview($view_name, 'tripal_analysis_kegg', $schema, $sql, $comment);
}
/**
*
*/
function tripal_analysis_kegg_add_cvterms() {
tripal_insert_cvterm(array(
'name' => 'analysis_kegg_settings',
'def' => 'Settings of a KEGG analysis, Currently include only the heir.tar.gz file name & path.',
'cv_name' => 'tripal',
'db_name' => 'tripal',
));
tripal_insert_cvterm(array(
'name' => 'kegg_brite_data',
'def' => 'This term is intended for use in the analysisfeatureprop table to store the KAAS results data.',
'cv_name' => 'tripal',
'db_name' => 'tripal',
));
tripal_insert_cvterm(array(
'name' => 'analysis_kegg_query_re',
'def' => 'The regular expression for finding the feature name in the query definition line of the blast results',
'cv_name' => 'tripal',
'db_name' => 'tripal',
));
tripal_insert_cvterm(array(
'name' => 'analysis_kegg_query_type',
'def' => 'The feature type (e.g. mRNA, polypeptide) of the query input file. This type is used to identify the query feature when multiple features have the same name',
'cv_name' => 'tripal',
'db_name' => 'tripal',
));
tripal_insert_cvterm(array(
'name' => 'analysis_kegg_query_uniquename',
'def' => 'Indicates if the matched name in the query definition line of the blast results is feature uniquename',
'cv_name' => 'tripal',
'db_name' => 'tripal',
));
tripal_insert_cvterm(array(
'name' => 'analysis_kegg_output_keywords',
'def' => 'Selected keywords for kegg html output which are indexed for search.',
'cv_name' => 'tripal',
'db_name' => 'tripal',
));
tripal_insert_cvterm(array(
'name' => 'analysis_kegg_organism_id',
'def' => 'The organism ID of the organism to which KEGG analysis results belong.',
'cv_name' => 'tripal',
'db_name' => 'tripal',
));
}
/*******************************************************************************
* Implementation of hook_uninstall()
*/
function tripal_analysis_kegg_uninstall() {
tripal_unregister_analysis_child('tripal_analysis_kegg');
$mview_id = tripal_get_mview_id('kegg_by_organism');
if ($mview_id) {
tripal_delete_mview($mview_id);
}
}
/*******************************************************************************
* Implementation of hook_requirements(). Make sure 'Tripal Core' and 'Tripal
* Analysis' are enabled before installation
*/
function tripal_analysis_kegg_requirements($phase) {
$requirements = array();
if ($phase == 'install') {
// make sure chado is installed
if (!$GLOBALS["chado_is_installed"]) {
$requirements ['tripal_feature'] = array(
'title' => "t ripal_feature",
'value' => "ERROR: Chado must be installed before this module can be enabled",
'severity' => REQUIREMENT_ERROR,
);
}
}
return $requirements;
}
/**
* Fixes an error with the materialized view installation
*
*/
function tripal_analysis_kegg_update_7200() {
// there is a bug in the Tripal v2.0-alpha release that didn't add the
// materialized view schema to the mviews table.
// get the schema for the materialized view from the custom_tables table
// as there is a copy there, but only if the schema is missing from the
// materialized view table
try {
$view_name = 'kegg_by_organism';
$schema = db_select('tripal_mviews', 'tm')
->fields('tm', array('mv_schema'))
->condition('name', $view_name)
->execute()
->fetchField();
if (!$schema or $schema == 'Array') {
$schema = db_select('tripal_custom_tables', 'tct')
->fields('tct', array('schema'))
->condition('table_name', $view_name)
->execute()
->fetchField();
$schema_str = var_export(unserialize($schema), TRUE);
$schema_str = preg_replace('/=>\s+\n\s+array/', '=> array', $schema_str);
db_update('tripal_mviews')
->fields(array('mv_schema' => $schema_str))
->condition('name', $view_name)
->execute();
}
}
catch (\PDOException $e) {
$error = $e->getMessage();
throw new DrupalUpdateException('Failed to complete update' . $error);
}
}
/**
* Adds an organism_id property for KEGG Analysis results
*
*/
function tripal_analysis_kegg_update_7201() {
try {
tripal_insert_cvterm(array(
'name' => 'analysis_kegg_organism_id',
'definition' => 'The organism ID of the organism to which KEGG analysis results belong.',
'cv_name' => 'tripal',
'db_name' => 'tripal'
));
}
catch (\PDOException $e) {
$error = $e->getMessage();
throw new DrupalUpdateException('Failed to complete update: ' . $error);
}
}
/**
* Adds the KEGG Module database and vocabulary
*/
function tripal_analysis_kegg_update_7202() {
try {
tripal_insert_db(array(
'name' => 'KEGG_MODULE',
'description' => 'KEGG MODULE is a collection of manually '.
'defined functional units, called KEGG modules and identified by the '.
'M numbers, used for annotation and biological interpretation of '.
'sequenced genomes',
'url' => 'http://www.genome.jp/kegg/module.html',
'urlprefix' => 'http://www.genome.jp/kegg-bin/show_module?',
));
tripal_insert_cv('KEGG_MODULE', 'Holds terms from the KEGG MODULE database.');
}
catch (\PDOException $e) {
$error = $e->getMessage();
throw new DrupalUpdateException('Failed to complete update: ' . $error);
}
}