Skip to content

Commit 5ae52eb

Browse files
committed
wc: fix initializing query and filters in interpreter browser rd #TASK-8076
1 parent efa81f5 commit 5ae52eb

File tree

1 file changed

+43
-49
lines changed

1 file changed

+43
-49
lines changed

src/webcomponents/variant/interpretation/variant-interpreter-browser-rd.js

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -92,83 +92,76 @@ class VariantInterpreterBrowserRd extends LitElement {
9292
}
9393

9494
clinicalAnalysisObserver() {
95-
if (this.query) {
96-
this._query = {
97-
...this.query,
98-
};
99-
return;
100-
}
101-
10295
// Configuration is using the clinicalAnalysis
10396
this._config = this.getDefaultConfig();
10497

98+
let query = {};
99+
let activeFilterFilters;
100+
let files = [];
101+
105102
// Init the active filters with every new Case opened. Then we add the default filters for the given sample.
106-
let _activeFilterFilters;
107103
if (this.settings?.menu?.examples?.length > 0) {
108104
// Load custom filters if configured
109105
// We need to clone to make sure we reset active fields
110-
_activeFilterFilters = UtilsNew.objectClone(this.settings.menu.examples);
106+
activeFilterFilters = UtilsNew.objectClone(this.settings.menu.examples);
111107
} else {
112108
// Load default filters if not custom defined
113-
_activeFilterFilters = this._config?.filter?.examples ? [...this._config.filter.examples] : [];
109+
activeFilterFilters = this._config?.filter?.examples ? [...this._config.filter.examples] : [];
114110
}
115111

116112
// Check for adding the examples filters section
117-
if (_activeFilterFilters?.length > 0) {
118-
_activeFilterFilters.unshift({
113+
if (activeFilterFilters?.length > 0) {
114+
activeFilterFilters.unshift({
119115
category: true,
120116
name: "Example Filters",
121117
});
122118
}
123119

124-
this.sample = this.clinicalAnalysis.proband?.samples?.find(sample => !sample.somatic);
125-
if (this.sample) {
126-
// Init query object if needed
127-
if (!this._query) {
128-
this._query = {};
129-
}
120+
// get the germline sample
121+
const sample = this.clinicalAnalysis.proband?.samples?.find(sample => !sample.somatic);
130122

123+
if (sample) {
131124
// 1. 'sample' query param: if sample is not defined then we must set the sample and genotype
132-
if (!this._query?.sample) {
133-
this._sampleQuery = null;
125+
if (!query?.sample) {
126+
let sampleQuery = null;
134127
switch (this.clinicalAnalysis.type.toUpperCase()) {
135128
case "SINGLE":
136129
case "CANCER":
137130
// Nacho (29-7-24): we have found too many exceptions in the genotypes, we should NOT add the genotypes here
138131
// this._sampleQuery = this.sample.id + ":" + ["0/1", "1/1", "1", "1/2"].join(",");
139-
this._sampleQuery = this.sample.id;
132+
sampleQuery = sample.id;
140133
break;
141134
case "FAMILY":
142135
// Add proband genotypes
143-
const sampleIds = [this.sample.id + ":" + ["0/1", "1/1", "1", "1/2"].join(",")];
136+
const sampleIds = [sample.id + ":" + ["0/1", "1/1", "1", "1/2"].join(",")];
144137
for (const member of this.clinicalAnalysis.family?.members) {
145138
// Proband is already in the array in the first position, we add other family members
146139
if (member.id !== this.clinicalAnalysis.proband?.id && member.samples?.length > 0) {
147140
sampleIds.push(member.samples[0].id + ":" + ["0/0", "0/1", "1/1", "1", "1/2"].join(","));
148141
}
149142
}
150-
this._sampleQuery = sampleIds.join(";");
143+
sampleQuery = sampleIds.join(";");
151144
break;
152145
}
153146

154147
// Set query object
155-
if (this._sampleQuery) {
156-
this._query.sample = this._sampleQuery;
148+
if (sampleQuery) {
149+
query.sample = sampleQuery;
157150
}
158151
}
159152

160153
// 2. 'panel' query param: add case panels to query object
161154
if (this.clinicalAnalysis.interpretation?.panels?.length > 0) {
162-
this._query.panel = this.clinicalAnalysis.interpretation.panels.map(panel => panel.id).join(",");
155+
query.panel = this.clinicalAnalysis.interpretation.panels.map(panel => panel.id).join(",");
163156
} else {
164157
if (this.clinicalAnalysis.panels?.length > 0) {
165-
this._query.panel = this.clinicalAnalysis.panels.map(panel => panel.id).join(",");
158+
query.panel = this.clinicalAnalysis.panels.map(panel => panel.id).join(",");
166159
}
167160
}
168161

169162
// 3. panelIntersection param: if panel lock is enabled, this param should be also enabled
170163
if (this.clinicalAnalysis.panelLocked) {
171-
this._query.panelIntersection = true;
164+
query.panelIntersection = true;
172165
}
173166

174167
// 4. 'fileData' query param: fetch non SV files and set init query
@@ -182,12 +175,12 @@ class VariantInterpreterBrowserRd extends LitElement {
182175
.filter(vc => vc.dataFilters.findIndex(filter => !filter.source || filter.source === "FILE") !== -1);
183176

184177
// Files matching the selected Variant Callers
185-
this.files = (this.clinicalAnalysis.files || [])
178+
files = (this.clinicalAnalysis.files || [])
186179
.filter(file => file.format.toUpperCase() === "VCF")
187180
.filter(file =>
188181
nonSvGermlineVariantCallers.findIndex(vc => vc.id.toUpperCase() === file.software?.name?.toUpperCase()) !== -1);
189182

190-
if (this.files?.length > 0) {
183+
if (files?.length > 0) {
191184
const fileDataFilters = [];
192185
nonSvGermlineVariantCallers
193186
.forEach(vc => {
@@ -202,7 +195,7 @@ class VariantInterpreterBrowserRd extends LitElement {
202195
// Only add this file to the filter if we have at least one default value
203196
if (filtersWithDefaultValues.length > 0) {
204197
// We need to find the file for that caller, file MUST be indexed
205-
const fileId = this.files
198+
const fileId = files
206199
.filter(file => file.internal?.variant?.index?.status?.id === "READY")
207200
.find(file => file.software.name === vc.id)?.name;
208201
if (fileId) {
@@ -212,18 +205,18 @@ class VariantInterpreterBrowserRd extends LitElement {
212205
});
213206

214207
// Update query with default 'fileData' parameters
215-
this._query.fileData = fileDataFilters.join(",");
208+
query.fileData = fileDataFilters.join(",");
216209
} else {
217-
this.files = this.clinicalAnalysis.files?.filter(file => file.format.toUpperCase() === "VCF") || [];
210+
files = this.clinicalAnalysis.files?.filter(file => file.format.toUpperCase() === "VCF") || [];
218211
}
219212
} else {
220-
this.files = this.clinicalAnalysis.files?.filter(file => file.format.toUpperCase() === "VCF") || [];
213+
files = this.clinicalAnalysis.files?.filter(file => file.format.toUpperCase() === "VCF") || [];
221214
}
222215

223216
// 5. Read defaultFilter from browser settings
224217
if (this.settings?.menu?.defaultFilter) {
225-
this._query = {
226-
...this._query,
218+
query = {
219+
...query,
227220
...this.settings.menu.defaultFilter,
228221
};
229222
}
@@ -233,13 +226,13 @@ class VariantInterpreterBrowserRd extends LitElement {
233226

234227
// Add filter to Active Filter's menu
235228
// 1. Add variant stats saved queries to the Active Filters menu
236-
if (this.sample.qualityControl?.variant?.variantStats?.length > 0) {
237-
_activeFilterFilters.push({
229+
if (sample.qualityControl?.variant?.variantStats?.length > 0) {
230+
activeFilterFilters.push({
238231
category: true,
239232
name: "Variant Stats Filters",
240233
});
241-
_activeFilterFilters.push(
242-
...this.sample.qualityControl.variant.variantStats.map(variantStat => ({
234+
activeFilterFilters.push(
235+
...sample.qualityControl.variant.variantStats.map(variantStat => ({
243236
id: variantStat.id,
244237
active: false,
245238
query: variantStat.query,
@@ -248,21 +241,21 @@ class VariantInterpreterBrowserRd extends LitElement {
248241
}
249242

250243
// 2. Add default initial query the active filter menu
251-
_activeFilterFilters.unshift({
244+
activeFilterFilters.unshift({
252245
id: "Default Filter",
253246
active: false,
254-
query: this._query,
247+
query: query,
255248
});
256249

257250
// Add 'file' filter if 'fileData' exists
258-
if (this.files) {
259-
const fileNames = this.files
251+
if (files) {
252+
const fileNames = files
260253
.filter(file => file.internal?.variant?.index?.status?.id === "READY")
261254
.map(f => f.name);
262255
// Only filter by file if there are more than 1 file indexed
263256
if (fileNames.length > 0) {
264257
const joinedFileNames = fileNames.join(",");
265-
for (const filter of _activeFilterFilters) {
258+
for (const filter of activeFilterFilters) {
266259
if (filter.query?.fileData && !filter.query?.file) {
267260
filter.query.file = joinedFileNames;
268261
}
@@ -271,11 +264,11 @@ class VariantInterpreterBrowserRd extends LitElement {
271264
}
272265

273266
// Set active filters
274-
this._config.filter.activeFilters.filters = _activeFilterFilters;
267+
this._config.filter.activeFilters.filters = activeFilterFilters;
275268
const activeFilter = this._config.filter.activeFilters.filters.find(filter => filter.active);
276269
if (activeFilter?.query) {
277-
this._query = {
278-
...this._query,
270+
query = {
271+
...query,
279272
...activeFilter.query,
280273
};
281274
}
@@ -285,7 +278,8 @@ class VariantInterpreterBrowserRd extends LitElement {
285278
this._config.filter.activeFilters.filters = [];
286279
}
287280

288-
this._query = {...this._query};
281+
// set the initial query: use the query from the property (to restore the previous query) or the default query
282+
this._query = this.query ? UtilsNew.objectClone(this.query) : query;
289283
}
290284

291285
onQueryChange(event) {

0 commit comments

Comments
 (0)