-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSQL-SRA-to-Graph.txt
284 lines (243 loc) · 7.11 KB
/
SQL-SRA-to-Graph.txt
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
282
283
284
-- By Jamie Al-Nasir, 01/12/2013
-- Dept. of Computer Science, Royal Holloway university
--
--
-- A script of SQL Queries for SQLite that convert the SRA
-- a into directed acyclic graph for 2D-visualisation
-- Some tricks are required in order to tie the graph together...
--
-- i) a psudo-node is created to represent each table in the SRA
-- i.e. study, experiment, sample, run, submission etc...
-- ii) pseudo-edges are created to join each table record to one
-- of these pseudo-nodes so as to create hubs in the graph.
--
-- It is possible to weight the edges so the pseudo-edges have
-- an edge weight of 0.5 and normal edges have an edge weight of 1.
--
-- It is probably a good idea to take a smaller proportion of this
-- data as it contains approximately 4,049,658 edges and 1,706,119 nodes!!
--
-- Top level studies, create tree table
create table tree
as select rowid as id,
study_accession as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
submission_accession as sub_access,
'study' as type
from study;
-- study table object
insert into tree
select (select max(id) from tree)+1 as id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
'' as sub_access,
'tblstudy' as type
from metaInfo where rowid = 1;
-- study table items
insert into tree
select id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
'' as sub_access,
'tblstudy-item' as type
from tree where tree.type = 'study';
-- "Central"/top-like level submissions
insert into tree
select rowid+(select max(id) from tree) as id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
submission_accession as sub_access,
'submission' as type
from submission;
-- submissions table object
insert into tree
select (select max(id) from tree)+1 as id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
'' as sub_access,
'tblsubmission' as type
from metaInfo where rowid = 1;
-- submissions table items
insert into tree
select id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
'' as sub_access,
'tblsubmission-item' as type
from tree where tree.type = 'submission';
-- experiments
insert into tree
select rowid+(select max(id) from tree) as id,
study_accession as stu_access,
experiment_accession as exp_access,
'' as run_access,
sample_accession as sam_access,
submission_accession as sub_access,
'experiment' as type
from experiment;
-- experiment table object
insert into tree
select (select max(id) from tree)+1 as id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
'' as sub_access,
'tblexperiment' as type
from metaInfo where rowid = 1;
-- experiment table items
insert into tree
select id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
'' as sub_access,
'tblexperiment-item' as type
from tree where tree.type = 'experiment';
-- samples
insert into tree
select rowid+(select max(id) from tree) as id,
'' as stu_access,
'' as exp_access,
'' as run_access,
sample_accession as sam_access,
submission_accession as sub_access,
'sample' as type
from sample;
-- samples table object
insert into tree
select (select max(id) from tree)+1 as id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
'' as sub_access,
'tblsample' as type
from metaInfo where rowid = 1;
-- samples table items
insert into tree
select id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
'' as sub_access,
'tblsample-item' as type
from tree where tree.type = 'sample';
-- runs
insert into tree
select rowid+(select max(id) from tree) as id,
'' as stu_access,
experiment_accession as exp_access,
run_accession as run_access,
'' as sam_access,
submission_accession as sub_access,
'run' as type
from run;
-- run table object
insert into tree
select (select max(id) from tree)+1 as id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
'' as sub_access,
'tblrun' as type
from metaInfo where rowid = 1;
-- run table items
insert into tree
select id,
'' as stu_access,
'' as exp_access,
'' as run_access,
'' as sam_access,
'' as sub_access,
'tblrun-item' as type
from tree where tree.type = 'run';
-- experiment-study, create normalised src/dest edges tree (tree_n)
create table tree_n as
select a.id as dest, b.id as src, 'study-experiment' as type from tree a
inner join tree as b on a.stu_access = b.stu_access
where a.type = 'study'
and b.type = 'experiment';
-- with weights
select a.id as dest, b.id as src, 'study-experiment' as type, weight from tree a
inner join tree as b on a.stu_access = b.stu_access,
id_exp_w as w on b.id = w.id
where a.type = 'study'
and b.type = 'experiment';
-- study table
insert into tree_n
select id as dest, (select id from tree where type = 'tblstudy') as src, 'tblstudy-item' as type from tree
where
tree.type = 'tblstudy-item';
-- sample-experiment
insert into tree_n
select a.id as dest, b.id as src, 'experiment-sample' as type from tree a
inner join tree as b on a.sam_access = b.sam_access
where a.type = 'experiment'
and b.type = 'sample';
-- experiment table
insert into tree_n
select id as dest, (select id from tree where type = 'tblexperiment') as src, 'tblexperiment-item' as type from tree
where
tree.type = 'tblexperiment-item';
-- sample-run
insert into tree_n
select a.id as dest, b.id as src, 'sample-run' as type from tree a
inner join tree as b on a.sam_access = b.sam_access
where a.type = 'sample'
and b.type = 'run';
-- sample table
insert into tree_n
select id as dest, (select id from tree where type = 'tblsample') as src, 'tblsample-item' as type from tree
where
tree.type = 'tblsample-item';
-- run table
insert into tree_n
select id as dest, (select id from tree where type = 'tblrun') as src, 'tblrun-item' as type from tree
where
tree.type = 'tblrun-item';
-- Submission edges
-- study-submission
insert into tree_n
select a.id as dest, b.id as src, 'study-submission' as type from tree a
inner join tree as b on a.sub_access = b.sub_access
where a.type = 'study'
and b.type = 'submission';
-- exp-submission
insert into tree_n
select a.id as dest, b.id as src, 'experiment-submission' as type from tree a
inner join tree as b on a.sub_access = b.sub_access
where a.type = 'experiment'
and b.type = 'submission';
-- sample-submission
insert into tree_n
select a.id as dest, b.id as src, 'sample-submission' as type from tree a
inner join tree as b on a.sub_access = b.sub_access
where a.type = 'sample'
and b.type = 'submission';
-- run-submission
insert into tree_n
select a.id as dest, b.id as src, 'run-submission' as type from tree a
inner join tree as b on a.sub_access = b.sub_access
where a.type = 'run'
and b.type = 'submission';
-- submission table
insert into tree_n
select id as dest, (select id from tree where type = 'tblsubmission') as src, 'tblsubmission-item' as type from tree
where
tree.type = 'tblsubmission-item';