@@ -3,8 +3,10 @@ DROP VIEW IF EXISTS view_sample;
3
3
CREATE VIEW view_sample AS
4
4
SELECT
5
5
concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , sample .STABLE_ID ) as sample_unique_id,
6
+ TO_BASE64(concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , sample .STABLE_ID )) as sample_unique_id_base64,
6
7
sample .STABLE_ID as sample_stable_id,
7
8
concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , p .STABLE_ID ) as patient_unique_id,
9
+ TO_BASE64(concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , p .STABLE_ID )) as patient_unique_id_base64,
8
10
p .STABLE_ID as patient_stable_id,
9
11
cs .CANCER_STUDY_IDENTIFIER as cancer_study_identifier
10
12
FROM sample
@@ -25,70 +27,81 @@ FROM sample_list as sl
25
27
INNER JOIN cancer_study cs on sl .CANCER_STUDY_ID = cs .CANCER_STUDY_ID ;
26
28
27
29
# genomic_event
28
- DROP TABLE IF EXISTS view_genomic_event;
30
+ DROP VIEW IF EXISTS view_genomic_event;
31
+ DROP VIEW IF EXISTS view_genomic_event_mutation;
29
32
-- This view takes a long time to materialize. I store the data in a table to prevent repeated recalculations.
30
- # CREATE TABLE view_genomic_event AS
31
- # SELECT
32
- # concat(cs.CANCER_STUDY_IDENTIFIER, '_', sample.STABLE_ID) as sample_unique_id,
33
- # gene.HUGO_GENE_SYMBOL as hugo_gene_symbol,
34
- # me.PROTEIN_CHANGE as variant,
35
- # gp.STABLE_ID as gene_panel_stable_id,
36
- # cs.CANCER_STUDY_IDENTIFIER as cancer_study_identifier,
37
- # g.STABLE_ID as genetic_profile_stable_id
38
- # FROM mutation
39
- # LEFT JOIN mutation_event as me ON mutation.MUTATION_EVENT_ID = me.MUTATION_EVENT_ID
40
- # LEFT JOIN sample_profile sp on mutation.SAMPLE_ID = sp.SAMPLE_ID and mutation.GENETIC_PROFILE_ID = sp.GENETIC_PROFILE_ID
41
- # LEFT JOIN gene_panel gp on sp.PANEL_ID = gp.INTERNAL_ID
42
- # LEFT JOIN genetic_profile g on sp.GENETIC_PROFILE_ID = g.GENETIC_PROFILE_ID
43
- # LEFT JOIN cancer_study cs on g.CANCER_STUDY_ID = cs.CANCER_STUDY_ID
44
- # LEFT JOIN sample on mutation.SAMPLE_ID = sample.INTERNAL_ID
45
- # LEFT JOIN gene ON mutation.ENTREZ_GENE_ID = gene.ENTREZ_GENE_ID;
46
- # INSERT INTO view_genomic_event
47
- # SELECT
48
- # concat(cs.CANCER_STUDY_IDENTIFIER, '_', sample.STABLE_ID) as sample_unique_id,
49
- # gene.HUGO_GENE_SYMBOL as hugo_gene_symbol,
50
- # convert(ce.ALTERATION, char) as variant,
51
- # gene_panel.STABLE_ID as gene_panel_stable_id,
52
- # cs.CANCER_STUDY_IDENTIFIER as cancer_study_identifier,
53
- # gp.STABLE_ID as genetic_profile_stable_id
54
- # FROM sample_cna_event
55
- # LEFT JOIN cna_event ce on sample_cna_event.CNA_EVENT_ID = ce.CNA_EVENT_ID
56
- # LEFT JOIN gene on ce.ENTREZ_GENE_ID = gene.ENTREZ_GENE_ID
57
- # LEFT JOIN genetic_profile gp on sample_cna_event.GENETIC_PROFILE_ID = gp.GENETIC_PROFILE_ID
58
- # LEFT JOIN sample_profile sp on gp.GENETIC_PROFILE_ID = sp.GENETIC_PROFILE_ID
59
- # LEFT JOIN cancer_study cs on gp.CANCER_STUDY_ID = cs.CANCER_STUDY_ID
60
- # LEFT JOIN sample on sample_cna_event.SAMPLE_ID = sample.INTERNAL_ID
61
- # LEFT JOIN gene_panel ON sp.PANEL_ID = gene_panel.INTERNAL_ID;
62
- # INSERT INTO view_genomic_event
63
- # SELECT
64
- # concat(cs.CANCER_STUDY_IDENTIFIER, '_', s.STABLE_ID) as sample_unique_id,
65
- # hugo_gene_symbol,
66
- # Event_Info as variant,
67
- # g.STABLE_ID as gene_panel_stable_id,
68
- # cs.CANCER_STUDY_IDENTIFIER as cancer_study_identifier,
69
- # gp.STABLE_ID as genetic_profile_stable_id
70
- # FROM structural_variant as sv
71
- # LEFT JOIN (SELECT ENTREZ_GENE_ID, HUGO_GENE_SYMBOL as hugo_gene_symbol FROM gene) gene1 on gene1.ENTREZ_GENE_ID = sv.SITE1_ENTREZ_GENE_ID
72
- # LEFT OUTER JOIN genetic_profile gp on gp.GENETIC_PROFILE_ID = sv.GENETIC_PROFILE_ID
73
- # LEFT JOIN sample s on sv.SAMPLE_ID = s.INTERNAL_ID
74
- # LEFT JOIN cancer_study cs on gp.CANCER_STUDY_ID = cs.CANCER_STUDY_ID
75
- # LEFT JOIN sample_profile sp on gp.GENETIC_PROFILE_ID = sp.GENETIC_PROFILE_ID
76
- # LEFT JOIN gene_panel g on sp.PANEL_ID = g.INTERNAL_ID;
77
- # INSERT INTO view_genomic_event
78
- # SELECT
79
- # concat(cs.CANCER_STUDY_IDENTIFIER, '_', s.STABLE_ID) as sample_unique_id,
80
- # hugo_gene_symbol,
81
- # Event_Info as variant,
82
- # g.STABLE_ID as gene_panel_stable_id,
83
- # cs.CANCER_STUDY_IDENTIFIER as cancer_study_identifier,
84
- # gp.STABLE_ID as genetic_profile_stable_id
85
- # FROM structural_variant as sv
86
- # LEFT JOIN (SELECT ENTREZ_GENE_ID, HUGO_GENE_SYMBOL as hugo_gene_symbol FROM gene) gene2 on gene2.ENTREZ_GENE_ID = sv.SITE2_ENTREZ_GENE_ID
87
- # LEFT OUTER JOIN genetic_profile gp on gp.GENETIC_PROFILE_ID = sv.GENETIC_PROFILE_ID
88
- # LEFT JOIN sample s on sv.SAMPLE_ID = s.INTERNAL_ID
89
- # LEFT JOIN cancer_study cs on gp.CANCER_STUDY_ID = cs.CANCER_STUDY_ID
90
- # LEFT JOIN sample_profile sp on gp.GENETIC_PROFILE_ID = sp.GENETIC_PROFILE_ID
91
- # LEFT JOIN gene_panel g on sp.PANEL_ID = g.INTERNAL_ID;
33
+ CREATE VIEW view_genomic_event_mutation AS
34
+ SELECT
35
+ concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , sample .STABLE_ID ) as sample_unique_id,
36
+ gene .HUGO_GENE_SYMBOL as hugo_gene_symbol,
37
+ me .PROTEIN_CHANGE as variant,
38
+ ' mutation' ,
39
+ gp .STABLE_ID as gene_panel_stable_id,
40
+ cs .CANCER_STUDY_IDENTIFIER as cancer_study_identifier,
41
+ g .STABLE_ID as genetic_profile_stable_id
42
+ FROM mutation
43
+ LEFT JOIN mutation_event as me ON mutation .MUTATION_EVENT_ID = me .MUTATION_EVENT_ID
44
+ LEFT JOIN sample_profile sp on mutation .SAMPLE_ID = sp .SAMPLE_ID and mutation .GENETIC_PROFILE_ID = sp .GENETIC_PROFILE_ID
45
+ LEFT JOIN gene_panel gp on sp .PANEL_ID = gp .INTERNAL_ID
46
+ LEFT JOIN genetic_profile g on sp .GENETIC_PROFILE_ID = g .GENETIC_PROFILE_ID
47
+ LEFT JOIN cancer_study cs on g .CANCER_STUDY_ID = cs .CANCER_STUDY_ID
48
+ LEFT JOIN sample on mutation .SAMPLE_ID = sample .INTERNAL_ID
49
+ LEFT JOIN gene ON mutation .ENTREZ_GENE_ID = gene .ENTREZ_GENE_ID ;
50
+
51
+ DROP VIEW IF EXISTS view_genomic_event_cna;
52
+ CREATE VIEW view_genomic_event_cna AS
53
+ SELECT
54
+ concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , sample .STABLE_ID ) as sample_unique_id,
55
+ gene .HUGO_GENE_SYMBOL as hugo_gene_symbol,
56
+ convert (ce .ALTERATION , char ) as variant,
57
+ ' cna' ,
58
+ gene_panel .STABLE_ID as gene_panel_stable_id,
59
+ cs .CANCER_STUDY_IDENTIFIER as cancer_study_identifier,
60
+ gp .STABLE_ID as genetic_profile_stable_id
61
+ FROM sample_cna_event
62
+ INNER JOIN cna_event ce on sample_cna_event .CNA_EVENT_ID = ce .CNA_EVENT_ID
63
+ INNER JOIN gene on ce .ENTREZ_GENE_ID = gene .ENTREZ_GENE_ID
64
+ INNER JOIN genetic_profile gp on sample_cna_event .GENETIC_PROFILE_ID = gp .GENETIC_PROFILE_ID
65
+ INNER JOIN sample on sample_cna_event .SAMPLE_ID = sample .INTERNAL_ID
66
+ INNER JOIN sample_profile sp on gp .GENETIC_PROFILE_ID = sp .GENETIC_PROFILE_ID AND sp .SAMPLE_ID = sample .INTERNAL_ID
67
+ INNER JOIN cancer_study cs on gp .CANCER_STUDY_ID = cs .CANCER_STUDY_ID
68
+ INNER JOIN gene_panel ON sp .PANEL_ID = gene_panel .INTERNAL_ID ;
69
+
70
+ DROP VIEW IF EXISTS view_genomic_event_sv_gene1;
71
+ CREATE VIEW view_genomic_event_sv_gene1 AS
72
+ SELECT
73
+ concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , s .STABLE_ID ) as sample_unique_id,
74
+ hugo_gene_symbol,
75
+ Event_Info as variant,
76
+ ' sv' ,
77
+ g .STABLE_ID as gene_panel_stable_id,
78
+ cs .CANCER_STUDY_IDENTIFIER as cancer_study_identifier,
79
+ gp .STABLE_ID as genetic_profile_stable_id
80
+ FROM structural_variant as sv
81
+ INNER JOIN (SELECT ENTREZ_GENE_ID, HUGO_GENE_SYMBOL as hugo_gene_symbol FROM gene) gene1 on gene1 .ENTREZ_GENE_ID = sv .SITE1_ENTREZ_GENE_ID
82
+ INNER JOIN genetic_profile gp on gp .GENETIC_PROFILE_ID = sv .GENETIC_PROFILE_ID
83
+ INNER JOIN sample s on sv .SAMPLE_ID = s .INTERNAL_ID
84
+ INNER JOIN cancer_study cs on gp .CANCER_STUDY_ID = cs .CANCER_STUDY_ID
85
+ INNER JOIN sample_profile sp on sp .SAMPLE_ID = sv .SAMPLE_ID and sp .GENETIC_PROFILE_ID = sv .GENETIC_PROFILE_ID
86
+ INNER JOIN gene_panel g on sp .PANEL_ID = g .INTERNAL_ID ;
87
+
88
+ DROP VIEW IF EXISTS view_genomic_event_sv_gene2;
89
+ CREATE VIEW view_genomic_event_sv_gene2 AS
90
+ SELECT
91
+ concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , s .STABLE_ID ) as sample_unique_id,
92
+ hugo_gene_symbol,
93
+ Event_Info as variant,
94
+ ' sv' ,
95
+ g .STABLE_ID as gene_panel_stable_id,
96
+ cs .CANCER_STUDY_IDENTIFIER as cancer_study_identifier,
97
+ gp .STABLE_ID as genetic_profile_stable_id
98
+ FROM structural_variant as sv
99
+ INNER JOIN (SELECT ENTREZ_GENE_ID, HUGO_GENE_SYMBOL as hugo_gene_symbol FROM gene) gene2 on gene2 .ENTREZ_GENE_ID = sv .SITE2_ENTREZ_GENE_ID
100
+ INNER JOIN genetic_profile gp on gp .GENETIC_PROFILE_ID = sv .GENETIC_PROFILE_ID
101
+ INNER JOIN sample s on sv .SAMPLE_ID = s .INTERNAL_ID
102
+ INNER JOIN cancer_study cs on gp .CANCER_STUDY_ID = cs .CANCER_STUDY_ID
103
+ INNER JOIN sample_profile sp on sp .SAMPLE_ID = sv .SAMPLE_ID and sp .GENETIC_PROFILE_ID = sv .GENETIC_PROFILE_ID
104
+ INNER JOIN gene_panel g on sp .PANEL_ID = g .INTERNAL_ID ;
92
105
93
106
-- structural variant
94
107
DROP VIEW IF EXISTS view_structural_variant;
@@ -101,25 +114,25 @@ SELECT
101
114
cs .CANCER_STUDY_IDENTIFIER as cancer_study_identifier,
102
115
gp .STABLE_ID as genetic_profile_stable_id
103
116
FROM structural_variant as sv
104
- LEFT JOIN (SELECT ENTREZ_GENE_ID, HUGO_GENE_SYMBOL FROM gene) gene1 on gene1 .ENTREZ_GENE_ID = sv .SITE1_ENTREZ_GENE_ID
105
- LEFT JOIN (SELECT ENTREZ_GENE_ID, HUGO_GENE_SYMBOL FROM gene) gene2 on gene2 .ENTREZ_GENE_ID = sv .SITE2_ENTREZ_GENE_ID
106
- LEFT OUTER JOIN genetic_profile gp on gp .GENETIC_PROFILE_ID = sv .GENETIC_PROFILE_ID
107
- LEFT JOIN sample s on sv .SAMPLE_ID = s .INTERNAL_ID
108
- LEFT JOIN cancer_study cs on gp .CANCER_STUDY_ID = cs .CANCER_STUDY_ID
109
- LEFT JOIN sample_profile sp on gp .GENETIC_PROFILE_ID = sp .GENETIC_PROFILE_ID
110
- LEFT JOIN gene_panel g on sp .PANEL_ID = g .INTERNAL_ID ;
117
+ INNER JOIN (SELECT ENTREZ_GENE_ID, HUGO_GENE_SYMBOL FROM gene) gene1 on gene1 .ENTREZ_GENE_ID = sv .SITE1_ENTREZ_GENE_ID
118
+ INNER JOIN (SELECT ENTREZ_GENE_ID, HUGO_GENE_SYMBOL FROM gene) gene2 on gene2 .ENTREZ_GENE_ID = sv .SITE2_ENTREZ_GENE_ID
119
+ INNER JOIN genetic_profile gp on gp .GENETIC_PROFILE_ID = sv .GENETIC_PROFILE_ID
120
+ INNER JOIN sample s on sv .SAMPLE_ID = s .INTERNAL_ID
121
+ INNER JOIN cancer_study cs on gp .CANCER_STUDY_ID = cs .CANCER_STUDY_ID
122
+ INNER JOIN sample_profile sp on gp .GENETIC_PROFILE_ID = sp .GENETIC_PROFILE_ID AND sp . SAMPLE_ID = sv . SAMPLE_ID
123
+ INNER JOIN gene_panel g on sp .PANEL_ID = g .INTERNAL_ID ;
111
124
112
125
-- sample_clinical_attribute_numeric
113
126
DROP VIEW IF EXISTS view_sample_clinical_attribute_numeric;
114
127
CREATE VIEW view_sample_clinical_attribute_numeric AS
115
128
SELECT
116
- concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , s .STABLE_ID ) as sample_unique_id,
117
- concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , p .STABLE_ID ) as patient_unique_id,
129
+ concat(cancer_study .CANCER_STUDY_IDENTIFIER , ' _' , s .STABLE_ID ) as sample_unique_id,
130
+ concat(cancer_study .CANCER_STUDY_IDENTIFIER , ' _' , p .STABLE_ID ) as patient_unique_id,
118
131
ATTR_ID as attribute_name,
119
132
ATTR_VALUE as attribute_value,
120
- cs .CANCER_STUDY_IDENTIFIER as cancer_study_identifier
121
- FROM cancer_study cs
122
- INNER JOIN patient p on cs .CANCER_STUDY_ID = p .CANCER_STUDY_ID
133
+ cancer_study .CANCER_STUDY_IDENTIFIER as cancer_study_identifier
134
+ FROM cancer_study
135
+ INNER JOIN patient p on cancer_study .CANCER_STUDY_ID = p .CANCER_STUDY_ID
123
136
INNER JOIN sample s on p .INTERNAL_ID = s .PATIENT_ID
124
137
INNER JOIN clinical_sample cs on s .INTERNAL_ID = cs .INTERNAL_ID
125
138
WHERE ATTR_VALUE REGEXP ' ^[0-9.]+$' ;
@@ -128,13 +141,13 @@ WHERE ATTR_VALUE REGEXP '^[0-9.]+$';
128
141
DROP VIEW IF EXISTS view_sample_clinical_attribute_categorical;
129
142
CREATE VIEW view_sample_clinical_attribute_categorical AS
130
143
SELECT
131
- concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , s .STABLE_ID ) as sample_unique_id,
132
- concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , p .STABLE_ID ) as patient_unique_id,
144
+ concat(cancer_study .CANCER_STUDY_IDENTIFIER , ' _' , s .STABLE_ID ) as sample_unique_id,
145
+ concat(cancer_study .CANCER_STUDY_IDENTIFIER , ' _' , p .STABLE_ID ) as patient_unique_id,
133
146
ATTR_ID as attribute_name,
134
147
ATTR_VALUE as attribute_value,
135
- cs .CANCER_STUDY_IDENTIFIER as cancer_study_identifier
136
- FROM cancer_study cs
137
- INNER JOIN patient p on cs .CANCER_STUDY_ID = p .CANCER_STUDY_ID
148
+ cancer_study .CANCER_STUDY_IDENTIFIER as cancer_study_identifier
149
+ FROM cancer_study
150
+ INNER JOIN patient p on cancer_study .CANCER_STUDY_ID = p .CANCER_STUDY_ID
138
151
INNER JOIN sample s on p .INTERNAL_ID = s .PATIENT_ID
139
152
INNER JOIN clinical_sample cs on s .INTERNAL_ID = cs .INTERNAL_ID
140
153
WHERE ATTR_VALUE NOT REGEXP ' ^[0-9.]+$' ;
@@ -143,25 +156,25 @@ WHERE ATTR_VALUE NOT REGEXP '^[0-9.]+$';
143
156
DROP VIEW IF EXISTS view_patient_clinical_attribute_numeric;
144
157
CREATE VIEW view_patient_clinical_attribute_numeric AS
145
158
SELECT
146
- concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , p .STABLE_ID ) as patient_unique_id,
159
+ concat(cancer_study .CANCER_STUDY_IDENTIFIER , ' _' , p .STABLE_ID ) as patient_unique_id,
147
160
ATTR_ID as attribute_name,
148
161
ATTR_VALUE as attribute_value,
149
- cs .CANCER_STUDY_IDENTIFIER as cancer_study_identifier
150
- FROM cancer_study cs
151
- INNER JOIN patient p on cs .CANCER_STUDY_ID = p .CANCER_STUDY_ID
162
+ cancer_study .CANCER_STUDY_IDENTIFIER as cancer_study_identifier
163
+ FROM cancer_study
164
+ INNER JOIN patient p on cancer_study .CANCER_STUDY_ID = p .CANCER_STUDY_ID
152
165
INNER JOIN clinical_patient cp on p .INTERNAL_ID = cp .INTERNAL_ID
153
166
WHERE ATTR_VALUE REGEXP ' ^[0-9.]+$' ;
154
167
155
168
-- patient_clinical_attribute_categorical
156
169
DROP VIEW IF EXISTS view_patient_clinical_attribute_categorical;
157
170
CREATE VIEW view_patient_clinical_attribute_categorical AS
158
171
SELECT
159
- concat(cs .CANCER_STUDY_IDENTIFIER , ' _' , p .STABLE_ID ) as patient_unique_id,
172
+ concat(cancer_study .CANCER_STUDY_IDENTIFIER , ' _' , p .STABLE_ID ) as patient_unique_id,
160
173
ATTR_ID as attribute_name,
161
174
ATTR_VALUE as attribute_value,
162
- cs .CANCER_STUDY_IDENTIFIER as cancer_study_identifier
163
- FROM cancer_study cs
164
- INNER JOIN patient p on cs .CANCER_STUDY_ID = p .CANCER_STUDY_ID
175
+ cancer_study .CANCER_STUDY_IDENTIFIER as cancer_study_identifier
176
+ FROM cancer_study
177
+ INNER JOIN patient p on cancer_study .CANCER_STUDY_ID = p .CANCER_STUDY_ID
165
178
INNER JOIN clinical_patient cp on p .INTERNAL_ID = cp .INTERNAL_ID
166
179
WHERE ATTR_VALUE NOT REGEXP ' ^[0-9.]+$' ;
167
180
0 commit comments