Skip to content

Commit fda957b

Browse files
committed
Improve pathway ontology configurability
1 parent 8d4383a commit fda957b

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/js/ideogram.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ import {
7070

7171
import {
7272
drawPathway as _drawPathway,
73-
getPathwayGenes as _getPathwayGenes
73+
getPathwayGenes as _getPathwayGenes,
74+
getPathwayAnnotations
7475
} from './kit/pathway-viewer.js';
7576

7677
import {
@@ -362,6 +363,7 @@ export default class Ideogram {
362363
* @param {Function} geneNodeHoverFn Function to call upon hovering gene
363364
* @param {Function} pathwayNodeClickFn Function to call upon clicking pathway
364365
* @param {Boolean} showDescription Whether to display pathway description
366+
* @param {Boolean} showOntologies Whether to display ontology annotations
365367
* @param {Boolean} showDefaultTooltips Whether to display default tooltips
366368
*/
367369
static drawPathway(
@@ -372,6 +374,7 @@ export default class Ideogram {
372374
geneNodeHoverFn=undefined,
373375
pathwayNodeClickFn=undefined,
374376
showDescription=true,
377+
showOntologies=true,
375378
showDefaultTooltips=true
376379
) {
377380
_drawPathway(
@@ -382,6 +385,7 @@ export default class Ideogram {
382385
geneNodeHoverFn=geneNodeHoverFn,
383386
pathwayNodeClickFn=pathwayNodeClickFn,
384387
showDescription=showDescription,
388+
showOntologies=showOntologies,
385389
showDefaultTooltips=showDefaultTooltips
386390
);
387391
}
@@ -407,4 +411,8 @@ export default class Ideogram {
407411
static getPathwayGenes() {
408412
return _getPathwayGenes();
409413
}
414+
415+
static getPathwayOntologies(pathwayJson, selectedOntology) {
416+
return getPathwayAnnotations(pathwayJson, selectedOntology);
417+
}
410418
}

src/js/kit/pathway-viewer.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function parsePwAnnotations(entitiesById, keys, ontology) {
227227
return pwAnnotations;
228228
}
229229

230-
function getPathwayAnnotations(pathwayJson) {
230+
export function getPathwayAnnotations(pathwayJson, selectedOntology) {
231231
const entitiesById = pathwayJson.entitiesById;
232232
const keys = Object.keys(entitiesById).filter(k => k.startsWith('http://identifiers.org'));
233233
const sentenceCases = {
@@ -238,12 +238,19 @@ function getPathwayAnnotations(pathwayJson) {
238238
'Disease'
239239
// 'Pathway Ontology' // maybe later
240240
];
241-
const pathwayAnnotationsList = ontologies.map(ontology => {
241+
let selectedOntologies = ontologies;
242+
if (selectedOntology) {
243+
selectedOntologies = ontologies.find(
244+
ontology => ontology.toLowerCase() === selectedOntology.toLowerCase()
245+
);
246+
}
247+
const pathwayAnnotationsList = selectedOntologies.map(ontology => {
242248
const pwAnnotations = parsePwAnnotations(entitiesById, keys, ontology);
243249
const links = pwAnnotations.map(pwa => {
244250
const id = pwa.xrefIdentifier.replace(':', '_');
245251
const url = `https://purl.obolibrary.org/obo/${id}`;
246-
return `<a href="${url}" target="_blank">${pwa.term}</a>`;
252+
const cls = 'class="_ideoPathwayOntologyLink"';
253+
return `<a href="${url}" target="_blank" ${cls}>${pwa.term}</a>`;
247254
}).join(', ');
248255

249256
const refinedOntology = sentenceCases[ontology] ?? ontology;
@@ -281,9 +288,10 @@ export function getPathwayGenes() {
281288
}
282289

283290

284-
function addFooter(pathwayJson, pathwayContainer) {
291+
function addFooter(pathwayJson, pathwayContainer, showOntologies) {
285292
const description = getDescription(pathwayJson);
286-
const pathwayAnnotations = getPathwayAnnotations(pathwayJson);
293+
const pathwayAnnotations =
294+
showOntologies ? getPathwayAnnotations(pathwayJson) : '';
287295
const footer =
288296
`<br/>` +
289297
`<div class="_ideoPathwayFooter">` +
@@ -303,6 +311,7 @@ export async function drawPathway(
303311
geneNodeHoverFn,
304312
pathwayNodeClickFn,
305313
showDescription,
314+
showOntologies,
306315
showDefaultTooltips,
307316
retryAttempt=0
308317
) {
@@ -394,7 +403,7 @@ export async function drawPathway(
394403
addHeader(pwId, pathwayJson, pathwayContainer, showClose);
395404

396405
if (showDescription) {
397-
addFooter(pathwayJson, pathwayContainer);
406+
addFooter(pathwayJson, pathwayContainer, showOntologies);
398407
}
399408

400409
// zoomToEntity(sourceEntityId);

0 commit comments

Comments
 (0)