Skip to content

Commit

Permalink
Bug fix - custom nucleotide colors were ignored. Fixes #1849
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Jul 19, 2024
1 parent a859eb9 commit cc020f9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
6 changes: 6 additions & 0 deletions dev/misc/sequence_track.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@


const config = {
nucleotideColors: {
"A": "blue",
"C": "red",
"G": "cyan",
"T": "purple"
},
locus: ["chr1:248752514", "chrY:57,217,299-57,217,380"],
reference: {
id: "hg38",
Expand Down
41 changes: 19 additions & 22 deletions js/sequenceTrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import IGVGraphics from "./igv-canvas.js"
import {isSecureContext} from "./util/igvUtils.js"
import {reverseComplementSequence} from "./util/sequenceUtils.js"
import {loadSequence} from "./genome/fasta.js"
import {defaultNucleotideColors} from "./util/nucleotideColors.js";
import {defaultNucleotideColors} from "./util/nucleotideColors.js"
import {createBlatTrack} from "./blat/blatTrack.js"

const defaultSequenceTrackOrder = Number.MIN_SAFE_INTEGER
Expand Down Expand Up @@ -137,11 +137,11 @@ class SequenceTrack {
this.height = this.frameTranslate ? TRANSLATED_HEIGHT : DEFAULT_HEIGHT

// Hack for backward compatibility
if(config.url) {
if (config.url) {
config.fastaURL = config.url
}

if(!config.fastaURL) {
if (!config.fastaURL) {
// Mark this as the genome reference sequence ==> backward compatibility convention
this.id = config.id || "sequence"
}
Expand Down Expand Up @@ -224,17 +224,17 @@ class SequenceTrack {

items.push({
label: 'BLAT read sequence',
click: async () => {
let sequence = await this.browser.genome.getSequence(chr, start, end)
if (sequence) {
if (this.reversed) {
sequence = reverseComplementSequence(sequence)
}
const name = `blat: ${chr}:${start + 1}-${end}`
const title = `blat: ${chr}:${start + 1}-${end}`
createBlatTrack({sequence, browser: this.browser, name, title})
click: async () => {
let sequence = await this.browser.genome.getSequence(chr, start, end)
if (sequence) {
if (this.reversed) {
sequence = reverseComplementSequence(sequence)
}
const name = `blat: ${chr}:${start + 1}-${end}`
const title = `blat: ${chr}:${start + 1}-${end}`
createBlatTrack({sequence, browser: this.browser, name, title})
}
}
})


Expand Down Expand Up @@ -278,8 +278,8 @@ class SequenceTrack {
* @returns {Promise<WrappedFasta|*>}
*/
async getSequenceSource() {
if(this.config.fastaURL) {
if(!this.fasta) {
if (this.config.fastaURL) {
if (!this.fasta) {
this.fasta = new WrappedFasta(this.config, this.browser.genome)
await this.fasta.init()
}
Expand Down Expand Up @@ -314,7 +314,7 @@ class SequenceTrack {
if (options.features) {

let sequence = options.features.sequence
if(!sequence) {
if (!sequence) {
return
}

Expand Down Expand Up @@ -345,8 +345,6 @@ class SequenceTrack {
const textPixel = aPixel + 0.5 * (pixelWidth - ctx.measureText(baseLetter).width)




if ('y' === options.axis) {
ctx.save()
IGVGraphics.labelTransformWithContext(ctx, textPixel)
Expand Down Expand Up @@ -421,8 +419,7 @@ class SequenceTrack {
if (this.color) {
return this.color
} else if ("dna" === this.sequenceType) {
// return this.browser.nucleotideColors[index] || 'gray'
return defaultNucleotideColors[index] || 'gray'
return this.browser.nucleotideColors[index] || 'gray'
} else {
return 'rgb(0, 0, 150)'
}
Expand Down Expand Up @@ -456,14 +453,14 @@ class SequenceTrack {
class WrappedFasta {

constructor(config, genome) {
this.config = config;
this.config = config
this.genome = genome
}

async init() {
this.fasta = await loadSequence(this.config)
this.chrNameMap = new Map()
for(let name of this.fasta.chromosomeNames) {
for (let name of this.fasta.chromosomeNames) {
this.chrNameMap.set(this.genome.getChromosomeName(name), name)
}
}
Expand All @@ -475,7 +472,7 @@ class WrappedFasta {

}

export {defaultSequenceTrackOrder, bppSequenceThreshold, translationDict }
export {defaultSequenceTrackOrder, bppSequenceThreshold, translationDict}

export default SequenceTrack

Expand Down

0 comments on commit cc020f9

Please sign in to comment.