From 3d8d25091e2b45f0038ca1e50b47f7f461ff2cc1 Mon Sep 17 00:00:00 2001 From: jrobinso <933148+jrobinso@users.noreply.github.com> Date: Thu, 21 Nov 2024 11:23:45 -0800 Subject: [PATCH] Enable case-insensitive search for chromosomes if canonical name is lower case. --- js/genome/genome.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/js/genome/genome.js b/js/genome/genome.js index fa72c94ab..b5a5cf0b8 100644 --- a/js/genome/genome.js +++ b/js/genome/genome.js @@ -20,6 +20,7 @@ import ChromAliasDefaults from "./chromAliasDefaults.js" class Genome { #wgChromosomeNames + #aliasRecordCache = new Map() static async createGenome(options, browser) { @@ -162,11 +163,9 @@ class Genome { async loadChromosome(chr) { - if (this.chromAlias) { - const chromAliasRecord = await this.chromAlias.search(chr) - if (chromAliasRecord) { - chr = chromAliasRecord.chr - } + const chromAliasRecord = await this.getAliasRecord(chr) + if (chromAliasRecord) { + chr = chromAliasRecord.chr } if (!this.chromosomes.has(chr)) { @@ -183,8 +182,16 @@ class Genome { } async getAliasRecord(chr) { + if (this.#aliasRecordCache.has(chr)) { + return this.#aliasRecordCache.get(chr) + } if (this.chromAlias) { - return this.chromAlias.search(chr) + let aliasRecord = await this.chromAlias.search(chr) + if (!aliasRecord && chr !== chr.toLowerCase()) { + aliasRecord = await this.chromAlias.search(chr.toLowerCase()) + } + this.#aliasRecordCache.set(chr, aliasRecord) // Set even if undefined to prevent recurrent searches + return aliasRecord } }