From abae471662ddeefc3efa5fdd66e2cfde70532872 Mon Sep 17 00:00:00 2001 From: sagely1 <114952739+sagely1@users.noreply.github.com> Date: Thu, 9 May 2024 15:51:23 -0700 Subject: [PATCH] AG-1425 updating variables and comments for clarity, fixing plural bug for protein header label --- .../gene-comparison-tool.component.html | 14 +-- .../gene-comparison-tool.component.spec.ts | 10 +- .../gene-comparison-tool.component.ts | 113 +++++++++--------- 3 files changed, 70 insertions(+), 67 deletions(-) diff --git a/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.html b/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.html index 50f85963..987a12e5 100644 --- a/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.html +++ b/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.html @@ -284,20 +284,20 @@

Gene Comparison Tool

- Pinned Genes ({{ pinnedGenes.length }}/50) + Pinned Genes ({{ pinnedItems.length }}/50)
Pinned Genes ({{ uniquePinnedGenesCount }}/50)   
- {{ pinnedGenes.length }} Proteins + {{ pinnedItems.length }} Proteins
@@ -314,7 +314,7 @@

Gene Comparison Tool

Gene Comparison Tool
@@ -573,8 +573,8 @@

Gene Comparison Tool

diff --git a/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.spec.ts b/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.spec.ts index da5e0f7c..c754110b 100644 --- a/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.spec.ts +++ b/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.spec.ts @@ -106,7 +106,7 @@ describe('Component: GeneComparisonToolComponent', () => { fixture.detectChanges(); expect(component.genes).toEqual([comparisonGeneMock1, comparisonGeneMock2]); - expect(component.pinnedGenes).toEqual([comparisonGeneMock1]); + expect(component.pinnedItems).toEqual([comparisonGeneMock1]); flush(); })); @@ -190,15 +190,15 @@ describe('Component: GeneComparisonToolComponent', () => { component.clearPinnedGenes(); fixture.detectChanges(); - expect(component.pinnedGenes.length).toEqual(0); + expect(component.pinnedItems.length).toEqual(0); component.onPinGeneClick(comparisonGeneMock1); fixture.detectChanges(); - expect(component.pinnedGenes.length).toEqual(1); + expect(component.pinnedItems.length).toEqual(1); component.onUnPinGeneClick(comparisonGeneMock1, true); fixture.detectChanges(); - expect(component.pinnedGenes.length).toEqual(0); + expect(component.pinnedItems.length).toEqual(0); }); it('should clear pinned genes', fakeAsync(() => { @@ -207,7 +207,7 @@ describe('Component: GeneComparisonToolComponent', () => { component.clearPinnedGenes(); fixture.detectChanges(); - expect(component.pinnedGenes.length).toEqual(0); + expect(component.pinnedItems.length).toEqual(0); flush(); })); diff --git a/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.ts b/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.ts index 2364d357..153a8c16 100644 --- a/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.ts +++ b/src/app/features/genes/components/gene-comparison-tool/gene-comparison-tool.component.ts @@ -100,10 +100,10 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { lastPinnedCategory = ''; lastPinnedSubCategory = ''; - pinnedGenes: GCTGene[] = []; + pinnedItems: GCTGene[] = []; uniquePinnedGenesCount = 0; - pinnedGenesCache: GCTGene[] = []; - pendingPinnedGenes: GCTGene[] = []; + pinnedItemsCache: GCTGene[] = []; + pendingPinnedItems: GCTGene[] = []; maxPinnedGenes = 50; /* ----------------------------------------------------------------------- */ @@ -240,53 +240,56 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { getGeneProperty(gene: GCTGene, property: string) { return property.split('.').reduce((o: any, i: any) => o[i], gene); } - - initData(genes: GCTGene[]) { - // hide brain region columns initially - this.brainRegionsColumns.forEach(c => c.visible = false); - - const pinnedGenes: GCTGene[] = []; - - const currentPinnedGenesCache = this.pinnedGenesCache; - let previousPins: (string | undefined)[] = []; + getUid(item: GCTGene) { + // rna is just the ensembl gene id + // protein is a combination of ensembl gene id and uniprotid + if (this.category === 'RNA - Differential Expression') + return item.ensembl_gene_id; + else + return item.ensembl_gene_id + item.uniprotid; + } + getPreviousPins() { if (this.currentCategoriesMatchLastPinnedCategories()) { - // no need to load from cache if it was last pinned from the current page - // previousPins = this.getUrlParam('pinned', true); - previousPins = currentPinnedGenesCache.map((g: GCTGene) => g.uid); + // load from cache since it has been previously cached + return this.pinnedItemsCache.map((g: GCTGene) => g.uid); } else { - // if it is the initial load, the categories will not match since the last pinned categories - // will be empty strings. In this case we want to check the url to see if this was a shared url - // with pinned genes/proteins. - - // since the last pinned category is blank, we don't need to check the subcategory + // if the last pinned category is blank, then this means this is the initial load + // note: we only need to check the category for blank but subcategory will also be blank + // In this scenario, we check the url to see if this was a shared url with pinned genes/proteins if (this.lastPinnedCategory === '') { // check the url for pinned genes/proteins - previousPins = this.getUrlParam('pinned', true); this.setLastPinnedCategories(); + return this.getUrlParam('pinned', true); } else { // categories don't match, so grab it from the cache if (this.category === 'RNA - Differential Expression') { - previousPins = currentPinnedGenesCache - .map((g: GCTGene) => g.uid?.substring(0, 15)); + return this.pinnedItemsCache.map((g: GCTGene) => g.ensembl_gene_id); } else { - previousPins = currentPinnedGenesCache.map((g: GCTGene) => g.uid); + return this.pinnedItemsCache.map((g: GCTGene) => g.uid); } } } - + } + + initData(genes: GCTGene[]) { + // hide brain region columns initially + this.brainRegionsColumns.forEach(c => c.visible = false); + + const pinnedGenes: GCTGene[] = []; + + // load the previous pins and format previousPins to match the current category + const previousPins = this.getPreviousPins(); + genes.forEach((gene: GCTGene) => { - gene.uid = gene.ensembl_gene_id; + gene.uid = this.getUid(gene); gene.search_array = [ gene.ensembl_gene_id.toLowerCase(), gene.hgnc_symbol.toLowerCase(), ]; if (this.category === 'Protein - Differential Expression') { - // for this category, the uid will be ensg + uniprotid - gene.uid += gene.uniprotid; - gene.search_array.push(gene.uniprotid?.toLowerCase() || ''); // if there is a match on uid or ensembl_gene_id, add it to pinnedGenes @@ -356,16 +359,16 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { 'Protein - Differential Expression' === this.category && this.uniquePinnedGenesCount > this.maxPinnedGenes ) { - this.pendingPinnedGenes = pinnedGenes; + this.pendingPinnedItems = pinnedGenes; this.pinnedGenesModal.show(); } else { - this.pinnedGenes = []; - this.pendingPinnedGenes = []; + this.pinnedItems = []; + this.pendingPinnedItems = []; this.uniquePinnedGenesCount = this.getCountOfUniqueGenes(); this.pinGenes(pinnedGenes); } } else { - this.pinnedGenes = []; + this.pinnedItems = []; } this.genes = genes; @@ -659,16 +662,16 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { } setPinnedGenesCache(genes: GCTGene[]) { - this.pinnedGenesCache = genes; + this.pinnedItemsCache = genes; } clearPinnedGenesCache() { - this.pinnedGenesCache = []; + this.pinnedItemsCache = []; this.uniquePinnedGenesCount = this.getCountOfUniqueGenes(); } refreshPinnedGenes() { - this.setPinnedGenesCache(this.pinnedGenes); + this.setPinnedGenesCache(this.pinnedItems); this.filter(); this.updateUrl(); } @@ -684,11 +687,11 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { } pinGene(gene: GCTGene, refresh = true) { - const index = this.pinnedGenes.findIndex( + const index = this.pinnedItems.findIndex( (g: GCTGene) => g.uid === gene.uid ); if (this.category === 'RNA - Differential Expression') { - if (index > -1 || this.pinnedGenes.length >= this.maxPinnedGenes) + if (index > -1 || this.pinnedItems.length >= this.maxPinnedGenes) return; } else { // the same unique id exists, so don't allow it to be added @@ -698,7 +701,7 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { // border condition: if we are at the max allowable pinned genes // check if the pinned genes list has a gene with the ensembl id, // in which case the protein can be added - const ensemblIndex = this.pinnedGenes.findIndex( + const ensemblIndex = this.pinnedItems.findIndex( (g: GCTGene) => g.ensembl_gene_id === gene.ensembl_gene_id ); if (ensemblIndex < 0) { @@ -708,7 +711,7 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { } } - this.pinnedGenes.push(gene); + this.pinnedItems.push(gene); if (refresh) { this.clearPinnedGenesCache(); @@ -720,7 +723,7 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { // this method is used for protein views since there can be multiple pinned proteins // that have the same ensg value but different uniprotids // so this will return the count of genes with unique ensgs - const uids = this.pinnedGenes.map(g => g.ensembl_gene_id); + const uids = this.pinnedItems.map(g => g.ensembl_gene_id); const uniqueUids = new Set(uids); return uniqueUids.size; } @@ -752,7 +755,7 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { } pinGenes(genes: GCTGene[]) { - const remaining = this.maxPinnedGenes - this.pinnedGenes.length; + const remaining = this.maxPinnedGenes - this.pinnedItems.length; if (remaining < 1) { return; @@ -793,7 +796,7 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { } ensgExistsInProteins(ensemblGeneId: string) { - const ensemblIndex = this.pinnedGenes.findIndex( + const ensemblIndex = this.pinnedItems.findIndex( (g: GCTGene) => g.ensembl_gene_id === ensemblGeneId ); if (ensemblIndex < 0) { @@ -837,7 +840,7 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { onUnPinGeneClick(gene: GCTGene, refresh = true) { this.setLastPinnedCategories(); - const index = this.pinnedGenes.findIndex( + const index = this.pinnedItems.findIndex( (g: GCTGene) => g.uid === gene.uid ); @@ -845,7 +848,7 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { return; } - this.pinnedGenes.splice(index, 1); + this.pinnedItems.splice(index, 1); if (refresh) { this.clearPinnedGenesCache(); @@ -862,22 +865,22 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { } clearPinnedGenes() { - this.pinnedGenes = []; + this.pinnedItems = []; this.clearPinnedGenesCache(); this.refreshPinnedGenes(); } getPinnedEnsemblGeneIds() { - return this.pinnedGenes.map((g: GCTGene) => g.ensembl_gene_id); + return this.pinnedItems.map((g: GCTGene) => g.ensembl_gene_id); } getPinnedUniProtIds() { - return this.pinnedGenes.map((g: GCTGene) => g.uniprotid); + return this.pinnedItems.map((g: GCTGene) => g.uniprotid); } getPinDisabledStatus() { if (this.category === 'RNA - Differential Expression') - return this.pinnedGenes.length >= this.maxPinnedGenes; + return this.pinnedItems.length >= this.maxPinnedGenes; else { // default to showing pin all button for protein view return false; @@ -904,13 +907,13 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { onPinnedGenesModalChange(response: boolean) { if (response) { - this.pinnedGenes = []; - this.pinGenes(this.pendingPinnedGenes); + this.pinnedItems = []; + this.pinGenes(this.pendingPinnedItems); } else { this.category = this.categories[0].value; this.onCategoryChange(); } - this.pendingPinnedGenes = []; + this.pendingPinnedItems = []; } /* ----------------------------------------------------------------------- */ @@ -945,8 +948,8 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { params['sortOrder'] = this.sortOrder; } - if (this.pinnedGenes.length > 0) { - params['pinned'] = this.pinnedGenes.map( + if (this.pinnedItems.length > 0) { + params['pinned'] = this.pinnedItems.map( (g: GCTGene) => g.uid ); params['pinned'].sort(); @@ -1167,7 +1170,7 @@ export class GeneComparisonToolComponent implements OnInit, AVI, OnDestroy { ]; const data: any[][] = []; - this.pinnedGenes.forEach((g: GCTGene) => { + this.pinnedItems.forEach((g: GCTGene) => { const baseRow = [ g.ensembl_gene_id, g.hgnc_symbol,