Skip to content

Commit ec71a72

Browse files
committed
Use query parameters in alignment_summary queries
1 parent 96d6882 commit ec71a72

File tree

9 files changed

+20
-651
lines changed

9 files changed

+20
-651
lines changed

SequenceAnalysis/resources/queries/sequenceanalysis/alignment_summary_by_lineage.sql

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
1-
/*
2-
* Copyright (c) 2012 LabKey Corporation
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
PARAMETERS(AnalysisId INTEGER)
2+
163
select
17-
(CAST(a.analysis_id as varchar) || '<>' || a.lineages) as key,
4+
(CAST(AnalysisId as varchar) || '<>' || a.lineages) as key,
185
a.analysis_id,
196
a.lineages,
207
max(a.totalLineages) as totalLineages,
@@ -25,13 +12,13 @@ select
2512
round(100 * (cast(sum(a.total) as float) / cast(max(a.total_reads) as float)), 2) as percent,
2613
group_concat(distinct a.haplotypesWithAllele) as haplotypesWithAllele,
2714

28-
CAST((select sum(s.total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = a.analysis_id AND s.rowid IN (
29-
SELECT distinct asj.alignment_id from sequenceanalysis.alignment_summary_junction asj WHERE asj.ref_nt_id.locus = a.loci and asj.status = true
15+
CAST((select sum(s.total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = AnalysisId AND s.rowid IN (
16+
SELECT distinct asj.alignment_id from sequenceanalysis.alignment_summary_junction asj WHERE asj.analysis_id = AnalysisId AND asj.ref_nt_id.locus = a.loci and asj.status = true
3017
)
3118
) as integer) as total_reads_from_locus,
3219

33-
round(100 * (cast(sum(a.total) as float) / cast((select sum(s.total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = a.analysis_id AND s.rowid IN (
34-
SELECT distinct asj.alignment_id from sequenceanalysis.alignment_summary_junction asj WHERE asj.ref_nt_id.locus = a.loci and asj.status = true
20+
round(100 * (cast(sum(a.total) as float) / cast((select sum(s.total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = AnalysisId AND s.rowid IN (
21+
SELECT distinct asj.alignment_id from sequenceanalysis.alignment_summary_junction asj WHERE asj.analysis_id = AnalysisId AND asj.ref_nt_id.locus = a.loci and asj.status = true
3522
)
3623
) as float)), 2) as percent_from_locus,
3724
group_concat(distinct a.rowid, ',') as rowids
@@ -47,15 +34,16 @@ FROM (
4734
group_concat(distinct coalesce(j.ref_nt_id.locus, j.ref_nt_id.name), chr(10)) as loci,
4835

4936
total,
50-
cast((select sum(total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = a.analysis_id) as integer) as total_reads,
37+
cast((select sum(total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = AnalysisId) as integer) as total_reads,
5138
group_concat(distinct hs.haplotype, chr(10)) as haplotypesWithAllele
5239

5340
from sequenceanalysis.alignment_summary a
54-
join sequenceanalysis.alignment_summary_junction j ON (j.alignment_id = a.rowid and j.status = true)
41+
join sequenceanalysis.alignment_summary_junction j ON (j.analysis_id = AnalysisId AND j.alignment_id = a.rowid and j.status = true)
5542
left join sequenceanalysis.haplotype_sequences hs ON ((
5643
(hs.name = j.ref_nt_id.lineage AND hs.type = 'Lineage') OR
5744
(hs.name = j.ref_nt_id.name AND hs.type = 'Allele')
5845
) AND hs.haplotype.datedisabled IS NULL)
46+
WHERE a.analysis_id = AnalysisId
5947
group by a.analysis_id, a.rowid, a.total
6048

6149
) a

SequenceAnalysis/resources/queries/sequenceanalysis/alignment_summary_by_lineage_pivoted.query.xml

Lines changed: 0 additions & 9 deletions
This file was deleted.

SequenceAnalysis/resources/queries/sequenceanalysis/alignment_summary_by_lineage_pivoted.sql

Lines changed: 0 additions & 9 deletions
This file was deleted.

SequenceAnalysis/resources/queries/sequenceanalysis/alignment_summary_grouped.sql

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
1-
/*
2-
* Copyright (c) 2012 LabKey Corporation
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
1+
PARAMETERS(AnalysisId INTEGER)
2+
163
select
174
a.analysis_id,
185
a.alleles,
@@ -36,13 +23,13 @@ select
3623
group_concat(a.rowid, ',') as rowids,
3724
group_concat(distinct a.haplotypesWithAllele) as haplotypesWithAllele,
3825

39-
CAST((select sum(s.total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = a.analysis_id AND s.rowid IN (
40-
SELECT distinct asj.alignment_id from sequenceanalysis.alignment_summary_junction asj WHERE asj.ref_nt_id.locus = a.loci and asj.status = true
26+
CAST((select sum(s.total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = AnalysisId AND s.rowid IN (
27+
SELECT distinct asj.alignment_id from sequenceanalysis.alignment_summary_junction asj WHERE asj.analysis_id = AnalysisId AND asj.ref_nt_id.locus = a.loci and asj.status = true
4128
)
4229
) as INTEGER) as total_reads_from_locus,
4330

44-
round(100 * (cast(sum(a.total) as float) / CASE WHEN count(a.lineages) = 0 THEN max(a.total_reads) ELSE cast((select sum(s.total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = a.analysis_id AND s.rowid IN (
45-
SELECT distinct asj.alignment_id from sequenceanalysis.alignment_summary_junction asj WHERE asj.ref_nt_id.locus = a.loci and asj.status = true
31+
round(100 * (cast(sum(a.total) as float) / CASE WHEN count(a.lineages) = 0 THEN max(a.total_reads) ELSE cast((select sum(s.total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = AnalysisId AND s.rowid IN (
32+
SELECT distinct asj.alignment_id from sequenceanalysis.alignment_summary_junction asj WHERE asj.analysis_id = AnalysisId AND asj.ref_nt_id.locus = a.loci and asj.status = true
4633
)
4734
) as float) END), 2) as percent_from_locus,
4835
max(lastModified) as lastModified,
@@ -67,14 +54,15 @@ FROM (
6754
total_forward,
6855
total_reverse,
6956
valid_pairs,
70-
(select sum(total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = a.analysis_id) as total_reads,
57+
(select sum(total) as total FROM sequenceanalysis.alignment_summary s WHERE s.analysis_id = AnalysisId) as total_reads,
7158
max(j.modified) as lastModified
7259
from sequenceanalysis.alignment_summary a
73-
left join sequenceanalysis.alignment_summary_junction j ON (j.alignment_id = a.rowid and j.status = true)
60+
left join sequenceanalysis.alignment_summary_junction j ON (j.analysis_id = AnalysisId AND j.alignment_id = a.rowid and j.status = true)
7461
left join sequenceanalysis.haplotype_sequences hs ON ((
7562
(hs.name = j.ref_nt_id.lineage AND hs.type = 'Lineage') OR
7663
(hs.name = j.ref_nt_id.name AND hs.type = 'Allele')
7764
) AND hs.haplotype.datedisabled IS NULL)
65+
WHERE a.analysis_id = AnalysisId
7866
group by a.analysis_id, a.rowid, a.total, total_forward, total_reverse, valid_pairs
7967

8068
) a

SequenceAnalysis/resources/schemas/sequenceanalysis.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -523,15 +523,7 @@
523523
<onClick>SequenceAnalysis.window.RunExportWindow.downloadFilesForAnalysis(dataRegionName);</onClick>
524524
</item>
525525
<item text="Alignment Reports">
526-
<item text="Alignment Summary">
527-
<onClick>SequenceAnalysis.Buttons.viewQuery(dataRegionName, {queryName: 'alignment_summary_grouped'})</onClick>
528-
</item>
529-
<item text="Alignment Summary, By Lineage">
530-
<onClick>SequenceAnalysis.Buttons.viewQuery(dataRegionName, {queryName: 'alignment_summary_by_lineage'})</onClick>
531-
</item>
532-
<item text="Alignment Summary, Pivoted By Lineage">
533-
<onClick>SequenceAnalysis.Buttons.viewAlignmentsPivoted(dataRegionName)</onClick>
534-
</item>
526+
<!-- TODO: use analysisId-->
535527
<item text="Matching Haplotypes">
536528
<onClick>SequenceAnalysis.Buttons.viewQuery(dataRegionName, {queryName: 'haplotypeMatches'})</onClick>
537529
</item>

0 commit comments

Comments
 (0)