Skip to content

Commit

Permalink
Merge pull request #246 from eweitz/refine-ensembl-resiliency
Browse files Browse the repository at this point in the history
Refine handling of Ensembl outages in related genes kit
  • Loading branch information
eweitz authored Oct 15, 2020
2 parents 94be519 + 8c257dc commit a5ae488
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/vanilla/related-genes.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
#ideogram .annot path {
cursor: pointer;
}

#ideogram-container #_ideogramInnerWrap {
visibility: hidden;
}
</style>
<script type="text/javascript" src="../../dist/js/ideogram.min.js"></script>
<link rel="icon" type="image/x-icon" href="img/ideogram_favicon.ico">
Expand Down Expand Up @@ -215,9 +219,17 @@ <h1>Related genes | Ideogram</h1>
document.querySelector('#search-genes').value = annot.name;
urlParams['q'] = annot.name;
updateUrl();

const selector = '#ideogram-container #_ideogramInnerWrap'
document.querySelector(selector).style.visibility = 'hidden';
ideogram.plotRelatedGenes(annot.name);
}

function showIdeogram() {
const selector = '#ideogram-container #_ideogramInnerWrap'
document.querySelector(selector).style.visibility = 'visible';
}

config = {
organism: organism,
container: '#ideogram-container',
Expand All @@ -227,6 +239,7 @@ <h1>Related genes | Ideogram</h1>
annotationHeight: 7,
onClickAnnot: onClickAnnot,
onLoad: plotGeneFromUrl,
onFindRelatedGenes: showIdeogram,
onPlotRelatedGenes: reportRelatedGenes
}

Expand Down
11 changes: 11 additions & 0 deletions src/js/ideogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,20 @@ export default class Ideogram {
// Method is POST, so content-type must be defined in header
init.headers = {'Content-Type': 'application/json'};
}

// const random = Math.random();
// console.log(random)
// if (random < 0.5) {
const response = await fetch(`https://rest.ensembl.org${path}`, init);
const json = await response.json();
return json;
// } else {
// // Mock error
// init.headers = {'Content-Type': 'application/json'};
// const response = await fetch('https://httpstat.us/500/cors', init);
// const json = await response.json();
// return json;
// }
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/js/kit/related-genes.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,9 @@ function finishPlotRelatedGenes(ideoInnerDom, ideo) {
if (b.color === 'purple' && a.color === 'pink') return -1;
return b.name.length - a.name.length;
});
if (annots.length > 1 && ideo.onFindRelatedGenesCallback) {
ideo.onFindRelatedGenesCallback();
}
ideo.drawAnnots(annots);
moveLegend(ideoInnerDom);
}
Expand Down Expand Up @@ -596,6 +599,10 @@ function _initRelatedGenes(config, annotsInList) {
ideogram.onPlotRelatedGenesCallback = config.onPlotRelatedGenes;
}

if (config.onFindRelatedGenes) {
ideogram.onFindRelatedGenesCallback = config.onFindRelatedGenes;
}

return ideogram;
}

Expand Down

0 comments on commit a5ae488

Please sign in to comment.