Skip to content

Commit 865a27d

Browse files
authored
Merge pull request #210 from bimberlabinternal/25.11_fb_sbtperf
Use query parameters in alignment_summary queries
1 parent 8c5ba3c commit 865a27d

File tree

8 files changed

+77
-41
lines changed

8 files changed

+77
-41
lines changed

GenotypeAssays/resources/views/bulkHaplotype.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script type="text/javascript" nonce="<%=scriptNonce%>">
22

33
Ext4.onReady(function () {
4-
var analysisIds = LABKEY.ActionURL.getParameter('analysisIds');
4+
var analysisId = LABKEY.ActionURL.getParameter('analysisId');
55

6-
if (!analysisIds) {
7-
alert('Must Provide At Least One Analysis Id');
6+
if (!analysisId) {
7+
alert('Must Provide An Analysis Id');
88
return;
99
}
1010

@@ -15,7 +15,7 @@
1515
title: 'Haplotype Matches',
1616
items: [{
1717
xtype: 'genotypeassays-haplotypepanel',
18-
analysisIds: analysisIds.split(';'),
18+
analysisIds: analysisId,
1919
showCheckBoxes: true
2020
}]
2121
}).render(webpart.wrapperDivId);

GenotypeAssays/resources/views/sbtReview.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,15 @@
155155
allowHeaderLock: false,
156156
schemaName: 'sequenceanalysis',
157157
queryName: 'alignment_summary_grouped',
158-
//viewName: 'With Haplotype Matches',
158+
viewName: 'With Haplotype Matches',
159159
//sort: '-percent',
160160
containerPath: Laboratory.Utils.getQueryContainerPath(),
161-
filterArray: [LABKEY.Filter.create('analysis_id', analysisId, LABKEY.Filter.Types.EQUAL)],
162161
removeableFilters: [
163162
LABKEY.Filter.create('percent_from_locus', 0.25, LABKEY.Filter.Types.GTE)
164163
],
164+
parameters: {
165+
AnalysisId: analysisId
166+
},
165167
scope: this,
166168
success: this.onDataRegionLoad
167169
})
@@ -173,15 +175,17 @@
173175
allowHeaderLock: false,
174176
schemaName: 'sequenceanalysis',
175177
queryName: 'alignment_summary_by_lineage',
176-
//viewName: 'With Haplotype Matches',
178+
viewName: 'With Haplotype Matches',
177179
sort: '-percent',
178180
containerPath: Laboratory.Utils.getQueryContainerPath(),
179-
filterArray: [LABKEY.Filter.create('analysis_id', analysisId, LABKEY.Filter.Types.EQUAL)],
180181
removeableFilters: [
181182
LABKEY.Filter.create('percent_from_locus', 0.25, LABKEY.Filter.Types.GTE),
182183
LABKEY.Filter.create('total_reads', 5, LABKEY.Filter.Types.GT),
183184
LABKEY.Filter.create('totalLineages', 1, LABKEY.Filter.Types.EQUAL)
184185
],
186+
parameters: {
187+
AnalysisId: analysisId
188+
},
185189
scope: this,
186190
success: this.onDataRegionLoad
187191
})
@@ -191,7 +195,7 @@
191195
title: 'Haplotype Matches',
192196
items: [{
193197
xtype: 'genotypeassays-haplotypepanel',
194-
analysisIds: [analysisId]
198+
analysisId: [analysisId]
195199
}]
196200
},{
197201
xtype: 'ldk-querypanel',

GenotypeAssays/resources/web/genotypeassays/buttons.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ GenotypeAssays.buttons = new function(){
2121
return;
2222
}
2323

24+
if (checked.length !== 1) {
25+
alert('Only one row at a time can be selected');
26+
return;
27+
}
28+
2429
var newForm = Ext4.DomHelper.append(document.getElementsByTagName('body')[0],
2530
'<form method="POST" action="' + LABKEY.ActionURL.buildURL("genotypeassays", "bulkHaplotype", null) + '">' +
26-
'<input type="hidden" name="analysisIds" value="' + Ext4.htmlEncode(checked.join(';')) + '" />' +
31+
'<input type="hidden" name="analysisId" value="' + Ext4.htmlEncode(checked[0]) + '" />' +
2732
'</form>');
2833
newForm.submit();
2934
}

GenotypeAssays/resources/web/genotypeassays/panel/HaplotypePanel.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Ext4.define('GenotypeAssays.panel.HaplotypePanel', {
22
extend: 'Ext.panel.Panel',
33
alias: 'widget.genotypeassays-haplotypepanel',
4-
analysisIds: null,
4+
analysisId: null,
55
showCheckBoxes: false,
66

77
initComponent: function(){
@@ -266,10 +266,11 @@ Ext4.define('GenotypeAssays.panel.HaplotypePanel', {
266266
}
267267
}, this);
268268

269-
Ext4.Msg.confirm('Publish Selected?', 'You have chosen to published the following haplotypes:<br><br>' + (haplotypeNames.length > 8 ? 'Too many to display' : haplotypeNames.join('<br>')) + '<br><br>Continue?', function (val) {
269+
Ext4.Msg.confirm('Publish Selected?', 'You have chosen to publish the following haplotypes:<br><br>' + (haplotypeNames.length > 8 ? 'Too many to display' : haplotypeNames.join('<br>')) + '<br><br>Continue?', function (val) {
270270
if (val == 'yes') {
271271
Ext4.create('GenotypeAssays.window.PublishResultsWindow', {
272272
actionName: 'cacheHaplotypes',
273+
analysisId: this.analysisId,
273274
json: json
274275
}).show();
275276
}
@@ -460,10 +461,12 @@ Ext4.define('GenotypeAssays.panel.HaplotypePanel', {
460461
schemaName: 'sequenceanalysis',
461462
queryName: 'alignment_summary_by_lineage',
462463
columns: 'analysis_id,analysis_id/readset,analysis_id/readset/subjectId,lineages,loci,total,total_reads,percent,total_reads_from_locus,percent_from_locus',
464+
parameters: {
465+
AnalysisId: this.analysisId
466+
},
463467
apiVersion: 13.2,
464468
scope: this,
465469
filterArray: [
466-
LABKEY.Filter.create('analysis_id', this.analysisIds.join(';'), LABKEY.Filter.Types.IN),
467470
LABKEY.Filter.create('percent_from_locus', minPct || 0, LABKEY.Filter.Types.GTE)
468471
],
469472
failure: LDK.Utils.getErrorCallback(),
@@ -502,9 +505,9 @@ Ext4.define('GenotypeAssays.panel.HaplotypePanel', {
502505
sort: 'analysis_id',
503506
apiVersion: 13.2,
504507
scope: this,
505-
filterArray: [
506-
LABKEY.Filter.create('analysis_id', this.analysisIds.join(';'), LABKEY.Filter.Types.IN)
507-
],
508+
parameters: {
509+
AnalysisId: this.analysisId
510+
},
508511
failure: LDK.Utils.getErrorCallback(),
509512
success: function(results){
510513
this.lineageToAlleleMap = {};

GenotypeAssays/resources/web/genotypeassays/window/PublishResultsWindow.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,20 @@ Ext4.define('GenotypeAssays.window.PublishResultsWindow', {
1111
return;
1212
}
1313

14+
const analysisId = dr.getParameters()?.AnalysisId;
15+
if (!analysisId) {
16+
Ext4.Msg.alert('Error', 'Error: unable to find analysisId. This should not occur.');
17+
LDK.Assert.assertNotEmpty('Unable to find AnalysisId parameter from the DataRegion in PublishResultsWindow');
18+
19+
return;
20+
}
21+
1422
Ext4.create('GenotypeAssays.window.PublishResultsWindow', {
1523
dataRegionName: dataRegionName,
24+
analysisId: analysisId,
1625
actionName: 'cacheAnalyses'
1726
}).show();
1827
}
19-
20-
// haplotypeButtonHandler: function(dataRegionName){
21-
// var dr = LABKEY.DataRegions[dataRegionName];
22-
// LDK.Assert.assertNotEmpty('Unable to find dataregion in PublishResultsWindow', dr);
23-
//
24-
// if (!dr.getChecked().length) {
25-
// Ext4.Msg.alert('Error', 'No rows selected');
26-
// return;
27-
// }
28-
//
29-
// Ext4.create('GenotypeAssays.window.PublishResultsWindow', {
30-
// dataRegionName: dataRegionName,
31-
// actionName: 'cacheHaplotypes'
32-
// }).show();
33-
// }
3428
},
3529

3630
initComponent: function(){
@@ -122,6 +116,7 @@ Ext4.define('GenotypeAssays.window.PublishResultsWindow', {
122116
scope: this,
123117
jsonData: {
124118
alleleNames: alleleNames,
119+
analysisId: this.analysisId,
125120
json: Ext4.encode(this.json),
126121
protocolId: protocol
127122
},

GenotypeAssays/src/org/labkey/genotypeassays/GenotypeAssaysController.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public ApiResponse execute(CacheAnalysesForm form, BindException errors)
133133
}
134134

135135
String[] alleleNames = Arrays.stream(form.getAlleleNames()).map(StringEscapeUtils::unescapeHtml4).toArray(String[]::new);
136-
Pair<List<Long>, List<Long>> ret = GenotypeAssaysManager.get().cacheAnalyses(getViewContext(), protocol, alleleNames);
136+
Pair<List<Long>, List<Long>> ret = GenotypeAssaysManager.get().cacheAnalyses(getViewContext(), form.getAnalysisId(), protocol, alleleNames);
137137
resultProperties.put("runsCreated", ret.first);
138138
resultProperties.put("runsDeleted", ret.second);
139139
}
@@ -159,6 +159,7 @@ public static class CacheAnalysesForm
159159
{
160160
private String[] _alleleNames;
161161
private String _json;
162+
private int _analysisId;
162163
private int _protocolId;
163164

164165
public String[] getAlleleNames()
@@ -190,6 +191,16 @@ public void setJson(String json)
190191
{
191192
_json = json;
192193
}
194+
195+
public int getAnalysisId()
196+
{
197+
return _analysisId;
198+
}
199+
200+
public void setAnalysisId(int analysisId)
201+
{
202+
_analysisId = analysisId;
203+
}
193204
}
194205

195206
@RequiresPermission(UpdatePermission.class)

GenotypeAssays/src/org/labkey/genotypeassays/GenotypeAssaysManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ public static GenotypeAssaysManager get()
9090
return _instance;
9191
}
9292

93-
94-
public Pair<List<Long>, List<Long>> cacheAnalyses(final ViewContext ctx, final ExpProtocol protocol, String[] pks) throws IllegalArgumentException
93+
public Pair<List<Long>, List<Long>> cacheAnalyses(final ViewContext ctx, final int analysisId, final ExpProtocol protocol, String[] pks) throws IllegalArgumentException
9594
{
9695
final User u = ctx.getUser();
9796
final List<Long> runsCreated = new ArrayList<>();
@@ -126,6 +125,8 @@ public Pair<List<Long>, List<Long>> cacheAnalyses(final ViewContext ctx, final E
126125

127126
AtomicInteger records = new AtomicInteger();
128127
TableSelector tsAlignments = new TableSelector(tableAlignments, cols.values(), new SimpleFilter(FieldKey.fromString("key"), Arrays.asList(pks), CompareType.IN), null);
128+
tsAlignments.setNamedParameters(Map.of("AnalysisId", analysisId));
129+
129130
tsAlignments.forEach(new Selector.ForEachBlock<ResultSet>()
130131
{
131132
@Override

primeseq/src/org/labkey/primeseq/pipeline/MhcCleanupPipelineJob.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,11 @@ private void processAnalysis(int analysisId)
283283
final Map<String, Double> existingData = new HashMap<>();
284284
SimpleFilter dataFilter = new SimpleFilter(FieldKey.fromString("analysis_id"), analysisId, CompareType.EQUAL);
285285
dataFilter.addCondition(FieldKey.fromString("percent_from_locus"), getPipelineJob().getLineageThreshold(), CompareType.GT);
286-
new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_by_lineage"), PageFlowUtil.set("lineages", "percent_from_locus"), dataFilter, null).forEachResults(rs -> {
286+
287+
TableSelector ts = new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_by_lineage"), PageFlowUtil.set("lineages", "percent_from_locus"), dataFilter, null);
288+
ts.setNamedParameters(Map.of("AnalysisId", analysisId));
289+
290+
ts.forEachResults(rs -> {
287291
existingData.put(rs.getString(FieldKey.fromString("lineages")), rs.getDouble(FieldKey.fromString("percent_from_locus")));
288292
});
289293

@@ -311,7 +315,10 @@ private void processAnalysis(int analysisId)
311315
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("analysis_id"), analysisId, CompareType.EQUAL);
312316
filter.addCondition(FieldKey.fromString("percent_from_locus"), getPipelineJob().getLineageThreshold(), CompareType.LT);
313317

314-
List<String> lowFreqRowIdList = new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_by_lineage"), PageFlowUtil.set("rowids"), filter, null).getArrayList(String.class);
318+
ts = new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_by_lineage"), PageFlowUtil.set("rowids"), filter, null);
319+
ts.setNamedParameters(Map.of("AnalysisId", analysisId));
320+
321+
List<String> lowFreqRowIdList = ts.getArrayList(String.class);
315322
if (!lowFreqRowIdList.isEmpty())
316323
{
317324
getJob().getLogger().info("Analysis: " + analysisId + ", low freq lineages: " + lowFreqRowIdList.size());
@@ -329,7 +336,9 @@ private void processAnalysis(int analysisId)
329336
SimpleFilter filter = new SimpleFilter(FieldKey.fromString("analysis_id"), analysisId, CompareType.EQUAL);
330337
filter.addCondition(FieldKey.fromString("percent_from_locus"), getPipelineJob().getAlleleGroupThreshold(), CompareType.LT);
331338

332-
List<String> lowFreqRowIdList = new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_grouped"), PageFlowUtil.set("rowids"), filter, null).getArrayList(String.class);
339+
ts = new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_grouped"), PageFlowUtil.set("rowids"), filter, null);
340+
ts.setNamedParameters(Map.of("AnalysisId", analysisId));
341+
List<String> lowFreqRowIdList = ts.getArrayList(String.class);
333342
if (!lowFreqRowIdList.isEmpty())
334343
{
335344
getJob().getLogger().info("Analysis: " + analysisId + ", low freq allele groups: " + lowFreqRowIdList.size());
@@ -363,7 +372,9 @@ private void processAnalysis(int analysisId)
363372
filter.addCondition(FieldKey.fromString("totalLineages"), 1, CompareType.GT);
364373
filter.addCondition(FieldKey.fromString("loci"), "MHC", CompareType.CONTAINS);
365374

366-
List<String> rowIdList = new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_grouped"), PageFlowUtil.set("rowids"), filter, null).getArrayList(String.class);
375+
ts = new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_grouped"), PageFlowUtil.set("rowids"), filter, null);
376+
ts.setNamedParameters(Map.of("AnalysisId", analysisId));
377+
List<String> rowIdList = ts.getArrayList(String.class);
367378
if (!rowIdList.isEmpty())
368379
{
369380
getJob().getLogger().info("Analysis: " + analysisId + ", multi-lineage records: " + rowIdList.size());
@@ -380,7 +391,9 @@ private void processAnalysis(int analysisId)
380391
{
381392
SimpleFilter nAlignmentFilter = new SimpleFilter(FieldKey.fromString("analysis_id"), analysisId, CompareType.EQUAL);
382393
nAlignmentFilter.addCondition(FieldKey.fromString("nAlignments"), 1, CompareType.GT);
383-
List<String> redundantAlignmentSets = new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_grouped"), PageFlowUtil.set("rowids"), nAlignmentFilter, null).getArrayList(String.class);
394+
ts = new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_grouped"), PageFlowUtil.set("rowids"), nAlignmentFilter, null);
395+
ts.setNamedParameters(Map.of("AnalysisId", analysisId));
396+
List<String> redundantAlignmentSets = ts.getArrayList(String.class);
384397
if (!redundantAlignmentSets.isEmpty())
385398
{
386399
getJob().getLogger().info("Analysis: " + analysisId + ", redundant alignment sets: " + redundantAlignmentSets.size());
@@ -446,7 +459,9 @@ private void processAnalysis(int analysisId)
446459

447460
// verify ending data:
448461
final Map<String, Double> endingData = new HashMap<>();
449-
new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_by_lineage"), PageFlowUtil.set("lineages", "percent_from_locus"), dataFilter, null).forEachResults(rs -> {
462+
ts = new TableSelector(QueryService.get().getUserSchema(getJob().getUser(), getJob().getContainer(), "sequenceanalysis").getTable("alignment_summary_by_lineage"), PageFlowUtil.set("lineages", "percent_from_locus"), dataFilter, null);
463+
ts.setNamedParameters(Map.of("AnalysisId", analysisId));
464+
ts.forEachResults(rs -> {
450465
endingData.put(rs.getString(FieldKey.fromString("lineages")), rs.getDouble(FieldKey.fromString("percent_from_locus")));
451466
});
452467

@@ -515,7 +530,9 @@ public AlignmentGroupCompare(final int analysisId, Container c, User u)
515530
{
516531
this.analysisId = analysisId;
517532

518-
new TableSelector(QueryService.get().getUserSchema(u, c, "sequenceanalysis").getTable("alignment_summary_grouped"), PageFlowUtil.set("analysis_id", "alleles", "lineages", "totalLineages", "total_reads", "total_forward", "total_reverse", "valid_pairs", "rowids"), new SimpleFilter(FieldKey.fromString("analysis_id"), analysisId), null).forEachResults(rs -> {
533+
TableSelector ts = new TableSelector(QueryService.get().getUserSchema(u, c, "sequenceanalysis").getTable("alignment_summary_grouped"), PageFlowUtil.set("analysis_id", "alleles", "lineages", "totalLineages", "total_reads", "total_forward", "total_reverse", "valid_pairs", "rowids"), new SimpleFilter(FieldKey.fromString("analysis_id"), analysisId), null);
534+
ts.setNamedParameters(Map.of("AnalysisId", analysisId));
535+
ts.forEachResults(rs -> {
519536
if (rs.getString(FieldKey.fromString("alleles")) == null)
520537
{
521538
return;

0 commit comments

Comments
 (0)