Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ref string #1287

Merged
merged 7 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/components/dataTable/AnnotatedEntitiesPopupCuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ function renderLink(entity) {
return <Link to={`/gene/${entity.subject.curie}`}>{inner}</Link>;
} else {
const inner = <span dangerouslySetInnerHTML={{__html: entity.subject.name}}/>;
return <ExternalLink href={url}>{inner}</ExternalLink>;
return <ExternalLink href={url}>{inner}</ExternalLink>;
}
}

function AnnotatedEntitiesPopupCuration({ children, entities, parentPage, mainRowCurie }) {


function AnnotatedEntitiesPopupCuration({ children, entities, parentPage, mainRowCurie, pubModIds }) {

if (!entities || !entities.length) {
return null;
Expand Down Expand Up @@ -99,7 +101,7 @@ function AnnotatedEntitiesPopupCuration({ children, entities, parentPage, mainRo
<td><AnnotationType annotationType={entity.annotationType}/></td>
<td><EvidenceCodesCellCuration evidenceCodes={entity.evidenceCodes}/></td>
<td><ProviderCellCuration provider={provider} /></td>
<td><SingleReferenceCellCuration singleReference={entity.singleReference}/></td>
<td><SingleReferenceCellCuration singleReference={entity.singleReference} pubModIds={pubModIds}/></td>
</tr>
)
})
Expand Down
4 changes: 2 additions & 2 deletions src/components/dataTable/DiseaseQualifiersColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const DiseaseQualifiersColumn = ({qualifiers}) => {
if (!qualifiers || !qualifiers.length) {
return null;
}

return (
<CommaSeparatedList>
{qualifiers.map(qualifier => qualifier)}
{qualifiers.map(qualifier => qualifier.replaceAll("_", " "))}
</CommaSeparatedList>
);
};
Expand Down
18 changes: 9 additions & 9 deletions src/components/dataTable/referencesCellCuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ import React from 'react';

import ExternalLink from '../ExternalLink';
import { CollapsibleList } from '../collapsibleList';
import { getMultipleReferencesCuriesAndUrls } from "./utils";
import { getMultipleReferencesUrls } from "./utils";

const removeDuplicates = (refs) => {
const newArray = refs.map((ref) => [ref.curie, ref]);
const newArray = refs.map((ref) => [ref.pubModId, ref]);
const newMap = new Map(newArray);
const iterator = newMap.values();
const uniqueRefs = [...iterator];

return uniqueRefs;
}
};

const ReferencesCellCuration = (refs) => {
const refStringsAndUrls = getMultipleReferencesCuriesAndUrls(refs);
const uniqueRefs = removeDuplicates(refStringsAndUrls);
const ReferencesCellCuration = ({ pubModIds }) => {
const refStringsAndUrls = getMultipleReferencesUrls(pubModIds);
const uniqueRefs = removeDuplicates(refStringsAndUrls);

return refs &&
return pubModIds &&
<CollapsibleList>
{
uniqueRefs.map(({ curie, url }) => {
return <ExternalLink href={url} key={curie} title={curie}>{curie}</ExternalLink>;
uniqueRefs.map(({ pubModId, url }) => {
return <ExternalLink href={url} key={pubModId} title={pubModId}>{pubModId}</ExternalLink>;
})
}
</CollapsibleList>;
Expand Down
21 changes: 13 additions & 8 deletions src/components/dataTable/singleReferenceCellCuration.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React from 'react';

import ExternalLink from '../ExternalLink';
import { getSingleReferenceCurieAndUrl } from "./utils";

const SingleReferenceCellCuration = ({singleReference}) => {
if (singleReference) {
const { curie, url } = getSingleReferenceCurieAndUrl(singleReference);
return <ExternalLink href={url} key={curie} title={curie}>{curie}</ExternalLink>;
}
return <></>;
import { getSingleReferenceUrl } from "./utils";

const SingleReferenceCellCuration = ({ singleReference, pubModIds }) => {
if (!singleReference) return <></>;
const pubModId = getSingleReferencePubModId(singleReference, pubModIds);
const { url } = getSingleReferenceUrl(pubModId);
return <ExternalLink href={url} key={pubModId} title={pubModId}>{pubModId}</ExternalLink>;
};

const getSingleReferencePubModId = (reference, pubModIds) => {
return reference.crossReferences
.filter(crossRef => pubModIds.includes(crossRef.referencedCurie))
.map(crossRef => crossRef.referencedCurie)[0];
};


Expand Down
62 changes: 5 additions & 57 deletions src/components/dataTable/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,13 @@ export const getIsViaOrthology = (annotation) => {
return annotation.generatedRelationString.includes("orthology");
};

export function getRefStrings(referenceItems) {
if (!referenceItems)
return;

let refStrings = referenceItems.map((referenceItem) => getRefString(referenceItem));

return refStrings.sort();
}

export function getRefString(referenceItem) {
if (!referenceItem)
return;

if (!referenceItem.cross_references && !referenceItem.crossReferences){
return referenceItem.curie
}
let xrefCuries = referenceItem.crossReferences.map((crossReference) => crossReference.referencedCurie);
let primaryXrefCurie = '';

if (indexWithPrefix(xrefCuries, 'PMID:') > -1) {
[primaryXrefCurie] = xrefCuries.splice(indexWithPrefix(xrefCuries, 'PMID:'), 1);
} else if (indexWithPrefix(xrefCuries, 'FB:') > -1) {
[primaryXrefCurie] = xrefCuries.splice(indexWithPrefix(xrefCuries, 'FB:'), 1);
} else if (indexWithPrefix(xrefCuries, 'MGI:') > -1) {
[primaryXrefCurie] = xrefCuries.splice(indexWithPrefix(xrefCuries, 'MGI:'), 1);
} else if (indexWithPrefix(xrefCuries, 'RGD:') > -1) {
[primaryXrefCurie] = xrefCuries.splice(indexWithPrefix(xrefCuries, 'RGD:'), 1);
} else if (indexWithPrefix(xrefCuries, 'SGD:') > -1) {
[primaryXrefCurie] = xrefCuries.splice(indexWithPrefix(xrefCuries, 'SGD:'), 1);
} else if (indexWithPrefix(xrefCuries, 'WB:') > -1) {
[primaryXrefCurie] = xrefCuries.splice(indexWithPrefix(xrefCuries, 'WB:'), 1);
} else if (indexWithPrefix(xrefCuries, 'ZFIN:') > -1) {
[primaryXrefCurie] = xrefCuries.splice(indexWithPrefix(xrefCuries, 'ZFIN:'), 1);
} else {
[primaryXrefCurie] = xrefCuries.splice(0, 1);
}

return primaryXrefCurie;
}


function indexWithPrefix(array, prefix) {

for (let i = 0; i < array.length; i++) {
if (array[i].startsWith(prefix)) {
return i;
}
}
return -1;
}

export const getSingleReferenceCurieAndUrl = (reference) => {
const curie = getRefString(reference);
const url = getResourceUrl(curie);
return {curie, url};
export const getSingleReferenceUrl = (pubModId) => {
const url = getResourceUrl(pubModId);
return {pubModId, url};
}

export const getMultipleReferencesCuriesAndUrls = (references) => {
return references.map((reference) => getSingleReferenceCurieAndUrl(reference));
export const getMultipleReferencesUrls = (pubModIds) => {
return pubModIds.sort().map((pubModId) => getSingleReferenceUrl(pubModId));
}

const buildProvider = (annotation) => {
Expand Down
11 changes: 8 additions & 3 deletions src/components/disease/diseaseAnnotationTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ const DiseaseAnnotationTable = ({
<React.Fragment>
<div>{GeneCellCuration(row.subject)}</div>
<small>
<AnnotatedEntitiesPopupCuration parentPage='gene' entities={row.primaryAnnotations} mainRowCurie={row.subject.curie}>
<AnnotatedEntitiesPopupCuration
parentPage='gene'
entities={row.primaryAnnotations}
mainRowCurie={row.subject.curie}
pubModIds={row.pubmedPubModIDs}
>
Annotation details
</AnnotatedEntitiesPopupCuration>
</small>
Expand Down Expand Up @@ -142,12 +147,12 @@ const DiseaseAnnotationTable = ({
formatter: BasedOnGeneCellCuration,
},
{
dataField: 'references',
dataField: 'pubmedPubModIDs',
text: 'References',
filterable: true,
filterName: 'reference',
headerStyle: {width: '150px'},
formatter: ReferencesCellCuration,
formatter: (pubModIds) => <ReferencesCellCuration pubModIds={pubModIds}/>,
}
];

Expand Down
6 changes: 3 additions & 3 deletions src/containers/allelePage/AlleleToDiseaseTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const AlleleToDiseaseTable = ({alleleId}) => {
{
dataField: 'primaryAnnotations',
text: 'Annotation details',
formatter: entities => <AnnotatedEntitiesPopupCuration parentPage='allele' entities={entities}/>,
formatter: (entities, row) => <AnnotatedEntitiesPopupCuration parentPage='allele' entities={entities} pubModIds={row.pubmedPubModIDs}/>,
headerStyle: {width: '90px'},
},
{
Expand All @@ -71,9 +71,9 @@ const AlleleToDiseaseTable = ({alleleId}) => {
filterName: 'dataProvider',
},
{
dataField: 'references',
dataField: 'pubmedPubModIDs',
text: 'References',
formatter: references => ReferencesCellCuration(references),
formatter: (pubModIds) => <ReferencesCellCuration pubModIds={pubModIds}/>,
headerStyle: {width: '150px'},
filterable: true,
filterName: 'reference',
Expand Down
15 changes: 9 additions & 6 deletions src/containers/diseasePage/DiseaseToGeneTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import DiseaseQualifiersColumn from '../../components/dataTable/DiseaseQualifier
import AnnotatedEntitiesPopupCuration from '../../components/dataTable/AnnotatedEntitiesPopupCuration';
import ReferenceCellViaOrthologyCuration from '../../components/dataTable/ReferencesCellViaOrthologyCuration';

//TODO: once tickets SCRUM-3647, SCRUM-3648, and SCRUM-3649 are complete, refactor this and the diseaseAnnotationTable component
//if needed
const DiseaseToGeneTable = ({ id }) => {
const {
data: results,
Expand All @@ -43,7 +41,12 @@ const DiseaseToGeneTable = ({ id }) => {
<div>{GeneCellCuration(row.subject)}</div>
{!isViaOrthology && (
<small>
<AnnotatedEntitiesPopupCuration parentPage='disease' entities={row.primaryAnnotations} mainRowCurie={row.subject.curie}>
<AnnotatedEntitiesPopupCuration
parentPage='disease'
entities={row.primaryAnnotations}
mainRowCurie={row.subject.curie}
pubModIds={row.pubmedPubModIDs}
>
Annotation details
</AnnotatedEntitiesPopupCuration>
</small>
Expand Down Expand Up @@ -133,12 +136,12 @@ const DiseaseToGeneTable = ({ id }) => {
filterName: 'dataProvider',
},
{
dataField: 'references',
dataField: 'pubmedPubModIDs',
text: 'References',
headerStyle: { width: '150px' },
formatter: (references, row) => {
formatter: (pubModIds, row) => {
const isViaOrthology = getIsViaOrthology(row);
if(!isViaOrthology) return ReferencesCellCuration(references);
if(!isViaOrthology) return <ReferencesCellCuration pubModIds={pubModIds}/>
return <ReferenceCellViaOrthologyCuration/>
},
filterable: true,
Expand Down
Loading