Skip to content

Commit

Permalink
Enable use of annotations include list
Browse files Browse the repository at this point in the history
  • Loading branch information
eweitz committed Sep 28, 2020
1 parent ebf381d commit 3b561bc
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 3 additions & 0 deletions examples/vanilla/related-genes.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ <h1>Related genes | Ideogram</h1>
showTools: true
}

// annotsInList = ['CDK9', 'CDK19', 'CDK1'];
// let ideogram = Ideogram.initRelatedGenes(config, annotsInList)

let ideogram = Ideogram.initRelatedGenes(config)
</script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions src/js/ideogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ export default class Ideogram {
*
* @param {Object} config Ideogram configuration object
*/
static initRelatedGenes(config) {
return _initRelatedGenes(config);
static initRelatedGenes(config, annotsInList='all') {
return _initRelatedGenes(config, annotsInList);
}
}
25 changes: 23 additions & 2 deletions src/js/kit/related-genes.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ function parseAnnotFromMgiGene(gene, ideo, color='red') {
return annot;
}

/** Filter annotations to only include those in configured list */
function applyAnnotsIncludeList(annots, ideo) {

if (ideo.config.annotsInList === 'all') return annots;

const includedAnnots = [];
annots.forEach(annot => {
if (ideo.config.annotsInList.includes(annot.name.toLowerCase())) {
includedAnnots.push(annot);
}
});
return includedAnnots;
}

/**
* For given gene, finds and draws interacting genes and paralogs
*
Expand Down Expand Up @@ -345,13 +359,15 @@ async function plotRelatedGenes(geneSymbol) {
width: 140px;`;

// Draw interacting genes immediately
annots = applyAnnotsIncludeList(annots, ideo);
annots.sort((a, b) => {return b.name.length - a.name.length;});
ideo.drawAnnots(annots);
document.querySelector('#_ideogramLegend').style = legendStyle;

await fetchParalogPositions(annot, annots, ideo);

// Add paralogs to related genes, and draw all related genes
annots = applyAnnotsIncludeList(annots, ideo);
annots.sort((a, b) => {return b.name.length - a.name.length;});
ideo.drawAnnots(annots);
document.querySelector('#_ideogramLegend').style = legendStyle;
Expand Down Expand Up @@ -410,13 +426,18 @@ const legend = [{
*
* @param {Object} config Ideogram configuration object
*/
function _initRelatedGenes(config) {
function _initRelatedGenes(config, annotsInList) {

if (annotsInList !== 'all') {
annotsInList = annotsInList.map(name => name.toLowerCase());
}

Object.assign(config, {
showFullyBanded: false,
rotatable: false,
legend: legend,
onWillShowAnnotTooltip: decorateGene
onWillShowAnnotTooltip: decorateGene,
annotsInList: annotsInList
});

const ideogram = new Ideogram(config);
Expand Down

0 comments on commit 3b561bc

Please sign in to comment.