Skip to content

Commit

Permalink
Merge pull request #312 from eweitz/enrich-tsv-parser
Browse files Browse the repository at this point in the history
Enrich TSV parser, related genes configurability
  • Loading branch information
eweitz committed Aug 27, 2022
2 parents 074f648 + b679df7 commit a7e5ceb
Show file tree
Hide file tree
Showing 6 changed files with 387 additions and 325 deletions.
80 changes: 61 additions & 19 deletions examples/vanilla/related-genes.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
cursor: pointer;
}

._ideogramTooltip th, ._ideogramTooltip td {
text-align: left;
}

</style>
<script type="text/javascript" src="../../dist/js/ideogram.min.js"></script>
<link rel="preconnect" href="https://fonts.gstatic.com">
Expand Down Expand Up @@ -203,6 +207,51 @@ <h1>Related genes | Ideogram</h1>
return geneSymbol;
}

/** Parse differential expression items, return as table for tooltip */
function parseDE(items) {

if (items.length < 1) return '';

const rows = '<tbody><tr>' + items.map(item => {
return (
`<td>${item.group}</td>` +
`<td>${item.log2fc}</td>` +
`<td>${item.adjustedPval}</td>`
+ `<td>${item.scoresRank}</td>`
);
}).join('</tr><tr>') + '</tr></tbody>';

const head =
'<thead><th>Group</th><th>log2(FC)</th><th>Adj. p-value</th><th>Rank in group</th></thead>';

const summary = 'summary="Differential expression"'
const result = '<table>' + head + rows + '</table>'

return result;
}

/** Called immediately before displaying features along chromosomes */
function onDrawAnnots() {
const ideo = this;

if (ideo.config.relatedGenesMode !== 'leads') return;

const deInnerFields =
ideo.rawAnnots.innerKeysByField['differentialExpression'];

const chrAnnots = ideo.annots;

for (let i = 0; i < chrAnnots.length; i++) {
const annots = chrAnnots[i].annots;

for (let j = 0; j < annots.length; j++) {
const annot = annots[j];
ideo.annotDescriptions.annots[annot.name].description =
parseDE(annot.differentialExpression, deInnerFields);
}
}
}

function updateExamples(organism) {
const rawExamples = examplesByOrganism[organism];

Expand Down Expand Up @@ -285,33 +334,15 @@ <h1>Related genes | Ideogram</h1>
ideogram.plotRelatedGenes(annot.name);
}

function onWillShowAnnotTooltip(annot) {
const ideo = this;
const tooltipAnalytics = ideo.getTooltipAnalytics(annot);

// Reduces analytics noise. Accounts for quick moves from label to
// annot, which flickers tooltip and represents an technical artifact
// that is not worth analyzing.
if (tooltipAnalytics) console.log(tooltipAnalytics);

return annot
}

updateExamples(organism);

config = {
organism: organism,
container: '#ideogram-container',
chrWidth: 9,
chrHeight: 100,
chrLabelSize: 12,
annotationHeight: 7,
// fontFamily: "'Montserrat', sans-serif",
onLoad: plotGeneFromUrl,
onPlotRelatedGenes: reportRelatedGenes,
showParalogNeighborhoods: organism === 'homo-sapiens',
showGeneStructureInTooltip: true,
cacheDir: '/dist/data/cache/',
onClickAnnot
}

Expand All @@ -328,11 +359,22 @@ <h1>Related genes | Ideogram</h1>
}
if ('org' in urlParams) {
if (urlParams.org === 'homo-sapiens') {
ideogram = Ideogram.initGeneHints(config);
if ('gene-leads' in urlParams) {
config.legendName = 'Gene leads'
config.onDrawAnnots = onDrawAnnots
ideogram = Ideogram.initGeneLeads(config);
} else {
ideogram = Ideogram.initGeneHints(config);
}
} else {
ideogram = Ideogram.initRelatedGenes(config);
}
} else {
if ('gene-leads' in urlParams) {
config.legendName = 'Gene leads'
config.onDrawAnnots = onDrawAnnots
ideogram = Ideogram.initGeneLeads(config);
}
ideogram = Ideogram.initGeneHints(config);
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/js/ideogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ import {
} from './views/chromosome-labels.js';

import {
_initGeneHints, _initRelatedGenes, plotRelatedGenes, getRelatedGenesByType
_initGeneHints, _initGeneLeads, _initRelatedGenes,
plotRelatedGenes, getRelatedGenesByType
} from './kit/related-genes';

export default class Ideogram {
Expand Down Expand Up @@ -336,4 +337,13 @@ export default class Ideogram {
static initGeneHints(config, annotsInList='all') {
return _initGeneHints(config, annotsInList);
}

/**
* Wrapper for Ideogram constructor, with generic "Related genes" options
*
* @param {Object} config Ideogram configuration object
*/
static initGeneLeads(config, annotsInList='all') {
return _initGeneLeads(config, annotsInList);
}
}
36 changes: 24 additions & 12 deletions src/js/init/caches/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,30 @@ export async function initCaches(ideo) {
let cacheDir = null;
if (config.cacheDir) cacheDir = config.cacheDir;

// Start all these in parallel. Only initGeneCache blocks; it internally
// resolves a Promise, whereas the others return upon completing their
// respective initializations.
const cachePromise = Promise.all([
cacheFactory('gene', organism, ideo, cacheDir),
cacheFactory('paralog', organism, ideo, cacheDir),
cacheFactory('interaction', organism, ideo, cacheDir)
]);

cacheFactory('geneStructure', organism, ideo, cacheDir);

return cachePromise;
if (config.awaitCache) {
// Start all these in parallel. Only initGeneCache blocks; it internally
// resolves a Promise, whereas the others return upon completing their
// respective initializations.
const cachePromise = Promise.all([
cacheFactory('gene', organism, ideo, cacheDir),
cacheFactory('paralog', organism, ideo, cacheDir),
cacheFactory('interaction', organism, ideo, cacheDir)
]);

if (config.showGeneStructureInTooltip) {
cacheFactory('geneStructure', organism, ideo, cacheDir);
}

return cachePromise;

} else {
cacheFactory('gene', organism, ideo, cacheDir);
cacheFactory('paralog', organism, ideo, cacheDir);
cacheFactory('interaction', organism, ideo, cacheDir);
if (config.showGeneStructureInTooltip) {
cacheFactory('geneStructure', organism, ideo, cacheDir);
}
}
}

const allCacheProps = {
Expand Down
Loading

0 comments on commit a7e5ceb

Please sign in to comment.