-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtripal_rnaseq.install.php
executable file
·191 lines (178 loc) · 6.34 KB
/
tripal_rnaseq.install.php
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
<?php
/**
* @file
* Functions used to install the module
*/
/**
* Implements install_hook().
*
* Permforms actions when the module is first installed.
*
* @ingroup tripal_rnaseq
*/
function tripal_rnaseq_install() {
tripal_create_files_dir('tripal_rnaseq');
tripal_create_files_dir('tripal_rnaseq_exp');
tripal_rnaseq_add_custom_tables();
tripal_rnaseq_add_cvterms();
}
/**
* Create experiment table in chado
*/
function tripal_rnaseq_add_custom_tables() {
$schema = array(
'table' => 'feature_experiment',
'fields' => array(
'feature_experiment_id' => array('type' => 'serial', 'size' => 'big', 'not null' => TRUE),
'experiment_id' => array('type' => 'int', 'size' => 'big', 'not null' => TRUE),
'feature_id' => array('type' => 'int', 'size' => 'big', 'not null' => TRUE),
'pub_id' => array('type' => 'int', 'size' => 'big', 'not null' => TRUE),
),
'primary key' => array('feature_experiment_id'),
'indexes' => array(
'idx1' => array('experiment_id'),
'idx2' => array('feature_id'),
'idx3' => array('pub_id'),
),
'unique keys' => array(
'c1' => array('experiment_id', 'feature_id', 'pub_id'),
),
);
db_create_table('chado.feature_experiment', $schema);
// Drupal doesn't support FK's. Use SQL command to add them
$sql = "
ALTER TABLE ONLY chado.feature_experiment
ADD CONSTRAINT feature_experiment_experiment_id_fkey
FOREIGN KEY (experiment_id) REFERENCES chado.experiment(experiment_id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED";
db_query($sql);
$sql = "
ALTER TABLE ONLY chado.feature_experiment
ADD CONSTRAINT feature_experiment_feature_id_fkey
FOREIGN KEY (feature_id) REFERENCES chado.feature(feature_id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED";
db_query($sql);
$schema = array(
'table' => 'feature_experimentprop',
'fields' => array(
'feature_experimentprop_id' => array('type' => 'serial', 'size' => 'big', 'not null' => TRUE),
'feature_experiment_id' => array('type' => 'int', 'size' => 'big', 'not null' => TRUE),
'type_id' => array('type' => 'int', 'size' => 'big', 'not null' => TRUE),
'value' => array('type' => 'text', 'not null' => FALSE),
'rank' => array('type' => 'int', 'default' => 0, 'not null' => TRUE),
),
'primary key' => array('feature_experimentprop_id'),
'indexes' => array(
'idx1' => array('feature_experiment_id'),
'idx2' => array('type_id'),
),
'unique keys' => array(
'c1' => array('feature_experiment_id', 'type_id', 'rank'),
),
);
// Drupal doesn't support FK's. Use SQL command to add them
db_create_table('chado.feature_experimentprop', $schema);
$sql = "
ALTER TABLE ONLY chado.feature_experimentprop
ADD CONSTRAINT feature_experimentprop_feature_experiment_id_fkey
FOREIGN KEY (feature_experiment_id) REFERENCES chado.feature_experiment(feature_experiment_id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED";
db_query($sql);
$sql = "
ALTER TABLE ONLY chado.feature_experimentprop
ADD CONSTRAINT feature_experimentprop_type_id_fkey
FOREIGN KEY (type_id) REFERENCES chado.cvterm(cvterm_id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED";
db_query($sql);
}
/**
* add cvterms for expression value
*/
function tripal_rnaseq_add_cvterms() {
$expression_term = array(
'raw_count' => 'raw count number of reads',
'RPKM' => 'Reads Per Kilobase of transcript per Million',
'FPKM' => 'Fragments Per Kilobase of transcript per Million',
'RPM' => 'Reads per Million',
'SD_raw_count' => 'SD for error bar of raw count',
'SD_RPKM' => 'SD for error bar of RPKM',
'SD_FPKM' => 'SD for error bar of FPKM',
'SD_RPM' => 'SD for error bar of RPM'
);
tripal_insert_cv(
'tripal_rnaseq',
'Contains property terms for tripal rnaseq.'
);
foreach ($expression_term as $term => $description) {
tripal_insert_cvterm(array(
'name' => $term,
'definition' => $description,
'cv_name' => 'tripal_rnaseq',
'db_name' => 'tripal_sra',
));
}
}
/**
* Implements hook_schema()
*/
function tripal_rnaseq_schema() {
// table for store loaded expression file as node, which used for display in gene feature page
$schema['chado_rnaseq'] = array(
'description' => t('The table for RNASeq node'),
'fields' => array(
'nid' => array(
'description' => t('The primary identifier for a node.'),
'type' => 'serial', 'unsigned' => true, 'not null' => true,
),
'name' => array(
'description' => t('The human-readable name for experession file.'),
'type' => 'varchar', 'length' => 1023, 'not null' => true,
),
'path' => array(
'description' => t('The full path of the expression file.'),
'type' => 'varchar', 'length' => 1023, 'not null' => true,
),
'type_id' => array(
'description' => t('The type of the expression value.'),
'type' => 'int', 'size' => 'big', 'not null' => true,
),
'project_id' => array(
'description' => t('the project id.'),
'type' => 'int', 'size' => 'big', 'not null' => true,
),
'organism_id' => array(
'description' => t('the organism id.'),
'type' => 'int', 'size' => 'big', 'not null' => true,
),
),
'indexes' => array(
'name' => array('name'),
),
'primary key' => array('nid'),
'unique keys' => array(
'nid' => array('nid'),
'type_project_id' => array('type_id', 'project_id', 'organism_id'),
),
);
return $schema;
}
/**
* Implements hook_update(),
*
* update chado.feature_expression
* change the field name from expression_id to expreriment_id
* FOREIGN KEY (experiment_id) REFERENCES expression(expression_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
* FOREIGN KEY (experiment_id) REFERENCES experiment(experiment_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
*
* drop the constraint "feature_expression_pub_id_fkey" on "feature_expression"?
*
* can not do it, already did it manually
*/
function tripal_rnaseq_update_1000() {
// Changing the length of the type field to allow it to be more readable.
//db_change_field('chado.feature_expression', 'expression_id', 'experiment_id',
// array(
// 'description' => t('link it to experiment table of tripal_sra module.'),
// )
//);
}