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
|
-- $Id: genetic.sql,v 1.31 2008-08-25 19:53:14 scottcain Exp $
-- ==========================================
-- Chado genetics module
--
-- changes 2011-05-31
-- added type_id to genotype (can be null for backward compatibility)
-- added genotypeprop table
-- 2006-04-11
-- split out phenotype tables into phenotype module
--
-- redesigned 2003-10-28
--
-- changes 2003-11-10:
-- incorporating suggestions to make everything a gcontext; use
-- gcontext_relationship to make some gcontexts derivable from others. we
-- would incorporate environment this way - just add the environment
-- descriptors as properties of the child gcontext
--
-- changes 2004-06 (Documented by DE: 10-MAR-2005):
-- Many, including rename of gcontext to genotype, split
-- phenstatement into phenstatement & phenotype, created environment
--
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ============
-- DEPENDENCIES
-- ============
-- :import feature from sequence
-- :import phenotype from phenotype
-- :import cvterm from cv
-- :import pub from pub
-- :import dbxref from general
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ================================================
-- TABLE: genotype
-- ================================================
create table genotype (
genotype_id serial not null,
primary key (genotype_id),
name text,
uniquename text not null,
description varchar(255),
type_id INT NOT NULL,
FOREIGN KEY (type_id) REFERENCES cvterm (cvterm_id) ON DELETE CASCADE,
constraint genotype_c1 unique (uniquename)
);
create index genotype_idx1 on genotype(uniquename);
create index genotype_idx2 on genotype(name);
COMMENT ON TABLE genotype IS 'Genetic context. A genotype is defined by a collection of features, mutations, balancers, deficiencies, haplotype blocks, or engineered constructs.';
COMMENT ON COLUMN genotype.uniquename IS 'The unique name for a genotype;
typically derived from the features making up the genotype.';
COMMENT ON COLUMN genotype.name IS 'Optional alternative name for a genotype,
for display purposes.';
-- ===============================================
-- TABLE: feature_genotype
-- ================================================
create table feature_genotype (
feature_genotype_id serial not null,
primary key (feature_genotype_id),
feature_id int not null,
foreign key (feature_id) references feature (feature_id) on delete cascade,
genotype_id int not null,
foreign key (genotype_id) references genotype (genotype_id) on delete cascade,
chromosome_id int,
foreign key (chromosome_id) references feature (feature_id) on delete set null,
rank int not null,
cgroup int not null,
cvterm_id int not null,
foreign key (cvterm_id) references cvterm (cvterm_id) on delete cascade,
constraint feature_genotype_c1 unique (feature_id, genotype_id, cvterm_id, chromosome_id, rank, cgroup)
);
create index feature_genotype_idx1 on feature_genotype (feature_id);
create index feature_genotype_idx2 on feature_genotype (genotype_id);
COMMENT ON TABLE feature_genotype IS NULL;
COMMENT ON COLUMN feature_genotype.rank IS 'rank can be used for
n-ploid organisms or to preserve order.';
COMMENT ON COLUMN feature_genotype.cgroup IS 'Spatially distinguishable
group. group can be used for distinguishing the chromosomal groups,
for example (RNAi products and so on can be treated as different
groups, as they do not fall on a particular chromosome).';
COMMENT ON COLUMN feature_genotype.chromosome_id IS 'A feature of SO type "chromosome".';
-- ================================================
-- TABLE: environment
-- ================================================
create table environment (
environment_id serial not NULL,
primary key (environment_id),
uniquename text not null,
description text,
constraint environment_c1 unique (uniquename)
);
create index environment_idx1 on environment(uniquename);
COMMENT ON TABLE environment IS 'The environmental component of a phenotype description.';
-- ================================================
-- TABLE: environment_cvterm
-- ================================================
create table environment_cvterm (
environment_cvterm_id serial not null,
primary key (environment_cvterm_id),
environment_id int not null,
foreign key (environment_id) references environment (environment_id) on delete cascade,
cvterm_id int not null,
foreign key (cvterm_id) references cvterm (cvterm_id) on delete cascade,
constraint environment_cvterm_c1 unique (environment_id, cvterm_id)
);
create index environment_cvterm_idx1 on environment_cvterm (environment_id);
create index environment_cvterm_idx2 on environment_cvterm (cvterm_id);
COMMENT ON TABLE environment_cvterm IS NULL;
-- ================================================
-- TABLE: phenstatement
-- ================================================
CREATE TABLE phenstatement (
phenstatement_id SERIAL NOT NULL,
primary key (phenstatement_id),
genotype_id INT NOT NULL,
FOREIGN KEY (genotype_id) REFERENCES genotype (genotype_id) ON DELETE CASCADE,
environment_id INT NOT NULL,
FOREIGN KEY (environment_id) REFERENCES environment (environment_id) ON DELETE CASCADE,
phenotype_id INT NOT NULL,
FOREIGN KEY (phenotype_id) REFERENCES phenotype (phenotype_id) ON DELETE CASCADE,
type_id INT NOT NULL,
FOREIGN KEY (type_id) REFERENCES cvterm (cvterm_id) ON DELETE CASCADE,
pub_id INT NOT NULL,
FOREIGN KEY (pub_id) REFERENCES pub (pub_id) ON DELETE CASCADE,
CONSTRAINT phenstatement_c1 UNIQUE (genotype_id,phenotype_id,environment_id,type_id,pub_id)
);
CREATE INDEX phenstatement_idx1 ON phenstatement (genotype_id);
CREATE INDEX phenstatement_idx2 ON phenstatement (phenotype_id);
COMMENT ON TABLE phenstatement IS 'Phenotypes are things like "larval lethal". Phenstatements are things like "dpp-1 is recessive larval lethal". So essentially phenstatement is a linking table expressing the relationship between genotype, environment, and phenotype.';
-- ================================================
-- TABLE: phendesc
-- ================================================
CREATE TABLE phendesc (
phendesc_id SERIAL NOT NULL,
primary key (phendesc_id),
genotype_id INT NOT NULL,
FOREIGN KEY (genotype_id) REFERENCES genotype (genotype_id) ON DELETE CASCADE,
environment_id INT NOT NULL,
FOREIGN KEY (environment_id) REFERENCES environment ( environment_id) ON DELETE CASCADE,
description TEXT NOT NULL,
type_id INT NOT NULL,
FOREIGN KEY (type_id) REFERENCES cvterm (cvterm_id) ON DELETE CASCADE,
pub_id INT NOT NULL,
FOREIGN KEY (pub_id) REFERENCES pub (pub_id) ON DELETE CASCADE,
CONSTRAINT phendesc_c1 UNIQUE (genotype_id,environment_id,type_id,pub_id)
);
CREATE INDEX phendesc_idx1 ON phendesc (genotype_id);
CREATE INDEX phendesc_idx2 ON phendesc (environment_id);
CREATE INDEX phendesc_idx3 ON phendesc (pub_id);
COMMENT ON TABLE phendesc IS 'A summary of a _set_ of phenotypic statements for any one gcontext made in any one publication.';
-- ================================================
-- TABLE: phenotype_comparison
-- ================================================
CREATE TABLE phenotype_comparison (
phenotype_comparison_id SERIAL NOT NULL,
primary key (phenotype_comparison_id),
genotype1_id INT NOT NULL,
FOREIGN KEY (genotype1_id) REFERENCES genotype (genotype_id) ON DELETE CASCADE,
environment1_id INT NOT NULL,
FOREIGN KEY (environment1_id) REFERENCES environment (environment_id) ON DELETE CASCADE,
genotype2_id INT NOT NULL,
FOREIGN KEY (genotype2_id) REFERENCES genotype (genotype_id) ON DELETE CASCADE,
environment2_id INT NOT NULL,
FOREIGN KEY (environment2_id) REFERENCES environment (environment_id) ON DELETE CASCADE,
phenotype1_id INT NOT NULL,
FOREIGN KEY (phenotype1_id) REFERENCES phenotype (phenotype_id) ON DELETE CASCADE,
phenotype2_id INT,
FOREIGN KEY (phenotype2_id) REFERENCES phenotype (phenotype_id) ON DELETE CASCADE,
pub_id INT NOT NULL,
FOREIGN KEY (pub_id) REFERENCES pub (pub_id) ON DELETE CASCADE,
organism_id INT NOT NULL,
FOREIGN KEY (organism_id) REFERENCES organism (organism_id) ON DELETE CASCADE,
CONSTRAINT phenotype_comparison_c1 UNIQUE (genotype1_id,environment1_id,genotype2_id,environment2_id,phenotype1_id,pub_id)
);
CREATE INDEX phenotype_comparison_idx1 on phenotype_comparison (genotype1_id);
CREATE INDEX phenotype_comparison_idx2 on phenotype_comparison (genotype2_id);
CREATE INDEX phenotype_comparison_idx4 on phenotype_comparison (pub_id);
COMMENT ON TABLE phenotype_comparison IS 'Comparison of phenotypes e.g., genotype1/environment1/phenotype1 "non-suppressible" with respect to genotype2/environment2/phenotype2.';
-- ================================================
-- TABLE: phenotype_comparison_cvterm
-- ================================================
CREATE TABLE phenotype_comparison_cvterm (
phenotype_comparison_cvterm_id serial not null,
primary key (phenotype_comparison_cvterm_id),
phenotype_comparison_id int not null,
FOREIGN KEY (phenotype_comparison_id) references phenotype_comparison (phenotype_comparison_id) on delete cascade,
cvterm_id int not null,
FOREIGN KEY (cvterm_id) references cvterm (cvterm_id) on delete cascade,
pub_id INT not null,
FOREIGN KEY (pub_id) references pub (pub_id) on delete cascade,
rank int not null default 0,
CONSTRAINT phenotype_comparison_cvterm_c1 unique (phenotype_comparison_id, cvterm_id)
);
CREATE INDEX phenotype_comparison_cvterm_idx1 on phenotype_comparison_cvterm (phenotype_comparison_id);
CREATE INDEX phenotype_comparison_cvterm_idx2 on phenotype_comparison_cvterm (cvterm_id);
-- ================================================
-- TABLE: genotypeprop
-- ================================================
create table genotypeprop (
genotypeprop_id serial not null,
primary key (genotypeprop_id),
genotype_id int not null,
foreign key (genotype_id) references genotype (genotype_id) on delete cascade INITIALLY DEFERRED,
type_id int not null,
foreign key (type_id) references cvterm (cvterm_id) on delete cascade INITIALLY DEFERRED,
value text null,
rank int not null default 0,
constraint genotypeprop_c1 unique (genotype_id,type_id,rank)
);
create index genotypeprop_idx1 on genotypeprop (genotype_id);
create index genotypeprop_idx2 on genotypeprop (type_id);
|