forked from wtsi-hgi/IYG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iyg.sql
256 lines (207 loc) · 8.38 KB
/
iyg.sql
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
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
CREATE SCHEMA IF NOT EXISTS `iyg` ;
USE `iyg` ;
-- -----------------------------------------------------
-- Table `iyg`.`profiles`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iyg`.`profiles` ;
CREATE TABLE IF NOT EXISTS `iyg`.`profiles` (
`profile_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`barcode` VARCHAR(15) NOT NULL ,
`consent_flag` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
`public_id` VARCHAR(40) NOT NULL ,
`quality_flagged` TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (`profile_id`) )
ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARACTER SET = latin1;
CREATE UNIQUE INDEX `barcode_idx` ON `iyg`.`profiles` (`barcode` ASC) ;
CREATE UNIQUE INDEX `public_id_idx` ON `iyg`.`profiles` (`public_id` ASC) ;
-- -----------------------------------------------------
-- Table `iyg`.`snps`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iyg`.`snps` ;
CREATE TABLE IF NOT EXISTS `iyg`.`snps` (
`snp_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`rs_id` VARCHAR(40) NOT NULL ,
`name` VARCHAR(255) NOT NULL DEFAULT '',
`description` TEXT ,
`ploidy` DECIMAL NOT NULL DEFAULT 0,
PRIMARY KEY (`snp_id`) )
ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARACTER SET = latin1;
CREATE INDEX `rs_id_idx` ON `iyg`.`snps` (`rs_id` ASC) ;
CREATE INDEX `snp_id_idx` ON `iyg`.`snps` (`snp_id` ASC) ;
-- -----------------------------------------------------
-- Table `iyg`.`variants`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iyg`.`variants` ;
CREATE TABLE IF NOT EXISTS `iyg`.`variants` (
`variant_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`snp_id` INT(10) UNSIGNED NOT NULL ,
`genotype` VARCHAR(5) NOT NULL ,
`popfreq` DECIMAL(10,4) NOT NULL DEFAULT 0,
PRIMARY KEY (`variant_id`) ,
CONSTRAINT `snp_id`
FOREIGN KEY (`snp_id` )
REFERENCES `iyg`.`snps` (`snp_id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARACTER SET = latin1;
CREATE UNIQUE INDEX `snp_genotype_composite` ON `iyg`.`variants` (`snp_id` ASC, `genotype` ASC) ;
CREATE INDEX `snp_id_idx` ON `iyg`.`variants` (`snp_id` ASC) ;
-- -----------------------------------------------------
-- Table `iyg`.`results`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iyg`.`results` ;
CREATE TABLE IF NOT EXISTS `iyg`.`results` (
`result_id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`profile_id` INT(11) UNSIGNED NOT NULL ,
`variant_id` INT(11) UNSIGNED NOT NULL ,
`confidence` DECIMAL(5,2) NOT NULL DEFAULT 100,
PRIMARY KEY (`result_id`) ,
CONSTRAINT `profile_id`
FOREIGN KEY (`profile_id` )
REFERENCES `iyg`.`profiles` (`profile_id` )
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `result_variant_id`
FOREIGN KEY (`variant_id` )
REFERENCES `iyg`.`variants` (`variant_id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARACTER SET = latin1;
CREATE INDEX `profile_variant_composite` ON `iyg`.`results` (`profile_id` ASC, `variant_id` ASC) ;
CREATE INDEX `profile_id_idx` ON `iyg`.`results` (`profile_id` ASC) ;
CREATE INDEX `variant_id_idx` ON `iyg`.`results` (`variant_id` ASC) ;
-- -----------------------------------------------------
-- Table `iyg`.`traits`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iyg`.`traits` ;
CREATE TABLE IF NOT EXISTS `iyg`.`traits` (
`trait_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(255) NOT NULL ,
`description` TEXT ,
`predictability` INT(1) NOT NULL ,
`active_flag` TINYINT(1) UNSIGNED NOT NULL ,
`handler` VARCHAR(50) NOT NULL ,
`short_name` VARCHAR(50) NOT NULL ,
`units` VARCHAR(50) ,
`mean` DECIMAL(10,4) ,
`sd` DECIMAL(10,4) ,
PRIMARY KEY (`trait_id`) )
ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARACTER SET = latin1;
-- -----------------------------------------------------
-- Table `iyg`.`variants_traits`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iyg`.`variants_traits` ;
CREATE TABLE IF NOT EXISTS `iyg`.`variants_traits` (
`variant_trait_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`variant_id` INT(10) UNSIGNED NOT NULL ,
`trait_id` INT(10) UNSIGNED NOT NULL ,
`value` VARCHAR(255) NOT NULL DEFAULT '',
`description` MEDIUMTEXT ,
PRIMARY KEY (`variant_trait_id`) ,
CONSTRAINT `trait_id`
FOREIGN KEY (`trait_id` )
REFERENCES `iyg`.`traits` (`trait_id` )
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `variant_id`
FOREIGN KEY (`variant_id` )
REFERENCES `iyg`.`variants` (`variant_id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARACTER SET = latin1;
CREATE UNIQUE INDEX `variant_trait_composite` ON `iyg`.`variants_traits` (`variant_id` ASC, `trait_id` ASC) ;
CREATE INDEX `variant_id_idx` ON `iyg`.`variants_traits` (`variant_id` ASC) ;
CREATE INDEX `trait_id_idx` ON `iyg`.`variants_traits` (`trait_id` ASC) ;
-- -----------------------------------------------------
-- Table `iyg`.`snps_traits`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iyg`.`snps_traits` ;
CREATE TABLE IF NOT EXISTS `iyg`.`snps_traits` (
`snp_trait_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`snp_id` INT(10) UNSIGNED NOT NULL ,
`trait_id` INT(10) UNSIGNED NOT NULL ,
`description` MEDIUMTEXT ,
PRIMARY KEY (`snp_trait_id`) ,
CONSTRAINT `snps_traits_trait_id`
FOREIGN KEY (`trait_id` )
REFERENCES `iyg`.`traits` (`trait_id` )
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `snps_traits_snp_id`
FOREIGN KEY (`snp_id` )
REFERENCES `iyg`.`snps` (`snp_id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARACTER SET = latin1;
CREATE UNIQUE INDEX `snp_trait_composite` ON `iyg`.`snps_traits` (`snp_id` ASC, `trait_id` ASC) ;
CREATE INDEX `snp_id_idx` ON `iyg`.`snps_traits` (`snp_id` ASC) ;
CREATE INDEX `trait_id_idx` ON `iyg`.`snps_traits` (`trait_id` ASC) ;
-- -----------------------------------------------------
-- Table `iyg`.`profiles_traits`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iyg`.`profiles_traits` ;
CREATE TABLE IF NOT EXISTS `iyg`.`profiles_traits` (
`profile_trait_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`profile_id` INT(10) UNSIGNED NOT NULL ,
`trait_id` INT(10) UNSIGNED NOT NULL ,
`name` VARCHAR(500) ,
`data` MEDIUMTEXT ,
PRIMARY KEY (`profile_trait_id`) ,
CONSTRAINT `profiles_traits_trait_id`
FOREIGN KEY (`trait_id` )
REFERENCES `iyg`.`traits` (`trait_id` )
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `profiles_traits_profile_id`
FOREIGN KEY (`profile_id` )
REFERENCES `iyg`.`profiles` (`profile_id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARACTER SET = latin1;
CREATE UNIQUE INDEX `profile_trait_composite` ON `iyg`.`profiles_traits` (`profile_id` ASC, `trait_id` ASC, `name` ASC) ;
CREATE INDEX `profile_id_idx` ON `iyg`.`profiles_traits` (`profile_id` ASC) ;
CREATE INDEX `trait_id_idx` ON `iyg`.`profiles_traits` (`trait_id` ASC) ;
CREATE INDEX `name_idx` ON `iyg`.`profiles_traits` (`name` ASC) ;
-- -----------------------------------------------------
-- Table `iyg`.`traits_additional`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `iyg`.`traits_additional` ;
CREATE TABLE IF NOT EXISTS `iyg`.`traits_additional` (
`trait_additional_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT ,
`trait_id` INT(10) UNSIGNED NOT NULL ,
`name` VARCHAR(500) ,
`data` MEDIUMTEXT ,
PRIMARY KEY (`trait_additional_id`) ,
CONSTRAINT `traits_additional_trait_id`
FOREIGN KEY (`trait_id` )
REFERENCES `iyg`.`traits` (`trait_id` )
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 1
DEFAULT CHARACTER SET = latin1;
CREATE UNIQUE INDEX `traits_additional_composite` ON `iyg`.`traits_additional` (`trait_id` ASC, `name` ASC) ;
CREATE INDEX `trait_id_idx` ON `iyg`.`traits_additional` (`trait_id` ASC) ;
CREATE INDEX `name_idx` ON `iyg`.`traits_additional` (`name` ASC) ;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;