Skip to content

Commit

Permalink
opencga-clinical-review-cases.js amd variant-interpreter-browser-rd.j…
Browse files Browse the repository at this point in the history
…s external setting in progress opencb/jsorolla#152, opencb/iva#236
  • Loading branch information
antonioaltamura committed Jun 24, 2021
1 parent d67bb90 commit 7356b40
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 29 deletions.
31 changes: 29 additions & 2 deletions src/core/utilsNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,13 +419,14 @@ export default class UtilsNew {
}

/**
* It merges external filter list with internal one.
* @deprecated
* It merges external filter list with internal one. It support reorganisation of sections.
*
* @param internal
* @param external
* @return {Array} hydrated array
*/
static mergeFilters(internal, external) {
static mergeFiltersOld(internal, external) {
// console.log("internal, external", internal, external)
if (external) {
// flattening the whole list of fields
Expand All @@ -440,4 +441,30 @@ export default class UtilsNew {
}
}

/**
* It merges external filter list with internal one.
* It doesn't support sections reorder and fields reorganisation among sections. Sections are fixed from the internal config.
*
* @param internal Filter object
* @param external Simplified filter object
* @return {Array} hydrated array
*/
static mergeFilters(internal, external) {
// console.log("internal, external", internal, external)
if (external?.length) {
const updatedSections = internal.sections.map(section => {
const fields = [];
for (const ex of external) {
const internalField = section.fields.find(field => field.id === ex.id);
if (internalField) {
fields.push({...internalField, ...ex});
}
}
return {...section, fields: fields};
});
return {...internal, sections: updatedSections};
}
return internal;
}

}
3 changes: 2 additions & 1 deletion src/core/webcomponents/clinical/opencga-clinical-portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ export default class OpencgaClinicalPortal extends LitElement {
<div style="padding: 0px 10px">
<div id="${this._prefix}ReviewCases" class="clinical-portal-content">
<opencga-clinical-review-cases .opencgaSession="${this.opencgaSession}"
.config="${this._config.reviewCases}">
.config="${this._config.reviewCases}"
.settings="${OpencgaClinicalReviewCasesSettings}">
</opencga-clinical-review-cases>
</div>
Expand Down
26 changes: 18 additions & 8 deletions src/core/webcomponents/clinical/opencga-clinical-review-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export default class OpencgaClinicalReviewCases extends LitElement {
},
config: {
type: Object
},
settings: {
type: Object
}
};
}
Expand All @@ -65,11 +68,16 @@ export default class OpencgaClinicalReviewCases extends LitElement {

connectedCallback() {
super.connectedCallback();
this.mergeSetting();
// settings is a prop, therefore the first render is performed without it
this._config = {...this.getDefaultConfig(), ...this.config};

}

updated(changedProperties) {
if (changedProperties.has("settings")) {
this.settingsObserver();
}

if (changedProperties.has("opencgaSession")) {
this.opencgaSessionObserver();
}
Expand All @@ -79,7 +87,8 @@ export default class OpencgaClinicalReviewCases extends LitElement {
}

opencgaSessionObserver() {
this.filters = this._config.filter.examples;
//console.error(this._config.filter)
this.filters = this._config?.filter?.examples;
if (this?.opencgaSession?.study) {
this.checkProjects = true;
this.refreshFilters();
Expand All @@ -90,14 +99,20 @@ export default class OpencgaClinicalReviewCases extends LitElement {
}

propertyObserver() {
this.mergeSetting();
this.settingsObserver();

if (UtilsNew.isNotUndefinedOrNull(this.query)) {
this._query = {...this.query};
}
this.requestUpdate();
}

settingsObserver() {
this._config = {...this.getDefaultConfig(), ...this.config};
this._config.filter = UtilsNew.mergeFilters(this._config?.filter, this.settings.filters);
this.requestUpdate();
}

isLoggedIn() {
return !!this?.opencgaSession?.token;
}
Expand Down Expand Up @@ -317,11 +332,6 @@ export default class OpencgaClinicalReviewCases extends LitElement {
}
}

mergeSetting() {
this._config = {...this.getDefaultConfig(), ...this.config};
this._config.filter = UtilsNew.mergeFilters(this._config.filter, OpencgaClinicalReviewCasesSettings.filter);
}

// TODO better adapt config to the a dynamic view
getDefaultConfig() {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export default class FileQualityFilter extends LitElement {

if (changedProperties.has("config")) {
this._config = {...this.getDefaultConfig(), ...this.config};
this.requestUpdate();
}
}

Expand Down Expand Up @@ -172,7 +173,6 @@ export default class FileQualityFilter extends LitElement {
@change="${this.filterChange}" .checked="${this.filter === "PASS"}" style="margin-right: 5px" data-cy="filter-pass">
<span>Include only <span style="font-weight: bold;">PASS</span> variants</span>
</div>
${this._config.showDepth ? html`
<form class="form-horizontal subsection-content">
<div id="${this._prefix}FileDepthCheckboxDiv" class="subsection-content form-group">
Expand Down
15 changes: 10 additions & 5 deletions src/core/webcomponents/sample/sample-variant-stats-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,16 @@ export default class SampleVariantStatsBrowser extends LitElement {
}

sampleObserver() {
if (this.sample?.qualityControl?.variantMetrics.variantStats?.length) {
console.log("this.sample", this.sample)
if (this.sample?.qualityControl?.variantMetrics?.variantStats?.length) {

console.error("old data model")
this.selectVariantStats("ALL", this.sample.qualityControl.variantMetrics.variantStats[0]);
}
if (this.sample?.qualityControl?.variant?.variantStats?.length) {
console.error("new data model")
this.selectVariantStats("ALL", this.sample.qualityControl.variant.variantStats[0]);
}
}

sampleIdObserver() {
Expand Down Expand Up @@ -438,9 +445,7 @@ export default class SampleVariantStatsBrowser extends LitElement {
<span><i class="fas fa-folder-open icon-padding"></i>Load <span class="caret" style="padding-left: 5px"></span></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="${this._prefix}ResetMenu" style="width: 360px">
<li style="margin: 5px 10px">
<span style="font-weight: bold">Saved Variant Stats</span>
</li>
<li style="padding: 3px 20px;"><b>Saved Variant Stats</b></li>
${this.sample?.qualityControl?.variantMetrics?.variantStats?.length > 0
? this.sample.qualityControl.variantMetrics.variantStats.map(qcVariantStat => html`
<li>
Expand All @@ -449,7 +454,7 @@ export default class SampleVariantStatsBrowser extends LitElement {
</a>
</li>
`)
: html`<div style="margin: 5px 5px">No Variant Stats found</div>`
: html`<li style="padding: 3px 20px;" class="text-muted">No Variant Stats found</li>`
}
</ul>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ class VariantInterpreterBrowserRd extends LitElement {
},
config: {
type: Object
},
settings: {
type: Object
}
};
}
Expand Down Expand Up @@ -90,6 +93,9 @@ class VariantInterpreterBrowserRd extends LitElement {
}

updated(changedProperties) {
if (changedProperties.has("settings") || changedProperties.has("config")) {
this.settingsObserver();
}
if (changedProperties.has("opencgaSession")) {
this.clinicalAnalysisManager = new ClinicalAnalysisManager(this.clinicalAnalysis, this.opencgaSession);
}
Expand All @@ -102,9 +108,12 @@ class VariantInterpreterBrowserRd extends LitElement {
if (changedProperties.has("query")) {
this.queryObserver();
}
if (changedProperties.has("config")) {
this._config = {...this.getDefaultConfig(), ...this.config};
}
}

settingsObserver() {
this._config = {...this.getDefaultConfig(), ...this.config};
this._config.filter = UtilsNew.mergeFilters(this._config?.filter, this.settings.filters);
this.requestUpdate();
}

queryObserver() {
Expand All @@ -121,6 +130,8 @@ class VariantInterpreterBrowserRd extends LitElement {
}

clinicalAnalysisObserver() {
console.log("clinicalAnalysisObserver")

this.clinicalAnalysisManager = new ClinicalAnalysisManager(this.clinicalAnalysis, this.opencgaSession);

// If sample is not defined and proband exists then we set the default samples
Expand Down Expand Up @@ -180,7 +191,7 @@ class VariantInterpreterBrowserRd extends LitElement {
this.savedVariants = this.clinicalAnalysis?.interpretation?.primaryFindings?.map(v => v.id);
}

this._config = {...this.getDefaultConfig(), ...this.config};
//this._config = {...this.getDefaultConfig(), ...this.config};
this.requestUpdate();
}

Expand Down Expand Up @@ -339,7 +350,7 @@ class VariantInterpreterBrowserRd extends LitElement {
id: "file-quality",
title: "Quality Filters",
tooltip: "VCF file based FILTER and QUAL filters",
showDepth: application.appConfig === "opencb"
// showDepth: false
},
{
id: "cohort",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class VariantInterpreterBrowser extends LitElement {
.clinicalAnalysis="${this.clinicalAnalysis}"
.query="${this.query}"
.cellbaseClient="${this.cellbaseClient}"
.settings="${variantInterpreterBrowserRdSettings}"
@clinicalAnalysisUpdate="${this.onClinicalAnalysisUpdate}"
@samplechange="${this.onSampleChange}">
</variant-interpreter-browser-rd>
Expand Down
12 changes: 5 additions & 7 deletions src/core/webcomponents/variant/opencga-variant-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,9 @@ export default class OpencgaVariantFilter extends LitElement {
const id = section.title.replace(/ /g, "");
const collapsed = section.collapsed ? "" : "in";

return html`
// whole section is hidden if there are no filters to show
if (section?.fields?.length) {
return html`
<div class="panel panel-default filter-section shadow-sm">
<div class="panel-heading" role="tab" id="${this._prefix}${id}Heading">
<h4 class="panel-title">
Expand All @@ -319,16 +321,12 @@ export default class OpencgaVariantFilter extends LitElement {
</div>
<div id="${this._prefix}${id}" class="panel-collapse collapse ${collapsed}" role="tabpanel" aria-labelledby="${this._prefix}${id}Heading">
<div class="panel-body" style="padding-top: 5px">
${section.fields && section.fields.length && section.fields.map(field => html`
${this._isFilterVisible(field) ?
this._createSubSection(field) :
null
}`
)}
${section.fields.map(field => html`${this._isFilterVisible(field) ? this._createSubSection(field) : ""}`)}
</div>
</div>
</div>
`;
}
}

_createSubSection(subsection) {
Expand Down

0 comments on commit 7356b40

Please sign in to comment.