Skip to content

Commit

Permalink
[Platform]: SSP data download fix - gql query variable and reference …
Browse files Browse the repository at this point in the history
…change (#310)
  • Loading branch information
chinmehta authored Dec 4, 2023
1 parent ea7d57c commit 29da20b
Show file tree
Hide file tree
Showing 11 changed files with 219 additions and 143 deletions.
48 changes: 44 additions & 4 deletions packages/sections/src/evidence/Chembl/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,45 @@ const useStyles = makeStyles(() => ({
},
}));

const exportColumns = [
{
label: "diseaseId",
exportValue: row => row.disease.id,
},
{
label: "diseaseName",
exportValue: row => row.disease.name,
},
{
label: "targets",
exportValue: row => row.target,
},
{
label: "drug",
exportValue: row => row.drug,
},
{
label: "mechanismofAction",
exportValue: row => row.drug.mechanismsOfAction,
},
{
label: "clinicalPhase",
exportValue: row => row.clinicalPhase,
},
{
label: "clinicalStatus",
exportValue: row => row.clinicalStatus,
},
{
label: "studyStartDate",
exportValue: row => row.studyStartDate,
},
{
label: "source",
exportValue: row => row.urls,
},
];

function getColumns(classes) {
return [
{
Expand Down Expand Up @@ -224,7 +263,7 @@ function Body({ id, label, entity }) {
let isCurrent = true;

fetchData({ ensemblId, efoId, cursor: "", size }).then(res => {
const { cursor: newCursor, rows: newRows, count: newCount } = res.data.disease.evidences;
const { cursor: newCursor, rows: newRows, count: newCount } = res.data.disease.chembl;
if (isCurrent) {
setInitialLoading(false);
setCursor(newCursor);
Expand All @@ -244,15 +283,15 @@ function Body({ id, label, entity }) {
ensemblId,
efoId,
},
`data.disease.evidence`
`data.disease.chembl`
);

const handlePageChange = newPage => {
const newPageInt = Number(newPage);
if (size * newPageInt + size > rows.length && cursor !== null) {
setLoading(true);
fetchData({ ensemblId, efoId, cursor, size }).then(res => {
const { cursor: newCursor, rows: newRows } = res.data.disease.evidences;
const { cursor: newCursor, rows: newRows } = res.data.disease.chembl;
setRows([...rows, ...newRows]);
setLoading(false);
setCursor(newCursor);
Expand All @@ -268,7 +307,7 @@ function Body({ id, label, entity }) {
if (newPageSizeInt > rows.length && cursor !== null) {
setLoading(true);
fetchData({ ensemblId, efoId, cursor, size: newPageSizeInt }).then(res => {
const { cursor: newCursor, rows: newRows } = res.data.disease.evidences;
const { cursor: newCursor, rows: newRows } = res.data.disease.chembl;
setRows([...rows, ...newRows]);
setLoading(false);
setCursor(newCursor);
Expand Down Expand Up @@ -320,6 +359,7 @@ function Body({ id, label, entity }) {
onSortBy={handleSortBy}
query={CHEMBL_QUERY.loc.source.body}
dataDownloader
dataDownloaderColumns={exportColumns}
dataDownloaderRows={getWholeDataset}
dataDownloaderFileStem="chembl-evidence"
variables={{
Expand Down
2 changes: 1 addition & 1 deletion packages/sections/src/evidence/Chembl/ChemblQuery.gql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
query ChemblQuery($ensemblId: String!, $efoId: String!, $size: Int!, $cursor: String) {
disease(efoId: $efoId) {
id
evidences(
chembl: evidences(
ensemblIds: [$ensemblId]
enableIndirect: true
datasourceIds: ["chembl"]
Expand Down
149 changes: 74 additions & 75 deletions packages/sections/src/evidence/EVA/Body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,17 @@ function getColumns(label) {
<Typography variant="subtitle2" display="block" align="center">
Reported disease or phenotype:
</Typography>
<Typography
variant="caption"
display="block"
align="center"
gutterBottom
>
<Typography variant="caption" display="block" align="center" gutterBottom>
{diseaseFromSource}
</Typography>

{cohortPhenotypes?.length > 1 ? (
<>
<Typography
variant="subtitle2"
display="block"
align="center"
>
<Typography variant="subtitle2" display="block" align="center">
All reported phenotypes:
</Typography>
<Typography variant="caption" display="block">
{cohortPhenotypes.map((cp) => (
{cohortPhenotypes.map(cp => (
<div key={cp}>{cp}</div>
))}
</Typography>
Expand Down Expand Up @@ -137,22 +128,14 @@ function getColumns(label) {
label={variantConsequenceSource.VEP.label}
value={sentenceCase(variantFunctionalConsequence.label)}
tooltip={variantConsequenceSource.VEP.tooltip}
to={identifiersOrgLink(
"SO",
variantFunctionalConsequence.id.slice(3)
)}
to={identifiersOrgLink("SO", variantFunctionalConsequence.id.slice(3))}
/>
)}
{variantFunctionalConsequenceFromQtlId && (
<LabelChip
label={variantConsequenceSource.QTL.label}
value={sentenceCase(
variantFunctionalConsequenceFromQtlId.label
)}
to={identifiersOrgLink(
"SO",
variantFunctionalConsequenceFromQtlId.id.slice(3)
)}
value={sentenceCase(variantFunctionalConsequenceFromQtlId.label)}
to={identifiersOrgLink("SO", variantFunctionalConsequenceFromQtlId.id.slice(3))}
tooltip={variantConsequenceSource.QTL.tooltip}
/>
)}
Expand All @@ -167,10 +150,7 @@ function getColumns(label) {
</div>
);
},
filterValue: ({
variantFunctionalConsequence,
variantFunctionalConsequenceFromQtlId,
}) =>
filterValue: ({ variantFunctionalConsequence, variantFunctionalConsequenceFromQtlId }) =>
`${sentenceCase(variantFunctionalConsequence.label)}, ${sentenceCase(
variantFunctionalConsequenceFromQtlId.label
)}`,
Expand All @@ -181,8 +161,7 @@ function getColumns(label) {
label: "Clinical significance",
renderCell: ({ clinicalSignificances }) => {
if (!clinicalSignificances) return naLabel;
if (clinicalSignificances.length === 1)
return sentenceCase(clinicalSignificances[0]);
if (clinicalSignificances.length === 1) return sentenceCase(clinicalSignificances[0]);
return (
<ul
style={{
Expand All @@ -191,10 +170,8 @@ function getColumns(label) {
listStyle: "none",
}}
>
{clinicalSignificances.map((clinicalSignificance) => (
<li key={clinicalSignificance}>
{sentenceCase(clinicalSignificance)}
</li>
{clinicalSignificances.map(clinicalSignificance => (
<li key={clinicalSignificance}>{sentenceCase(clinicalSignificance)}</li>
))}
</ul>
);
Expand All @@ -211,14 +188,10 @@ function getColumns(label) {
<Tooltip
title={
<>
<Typography
variant="subtitle2"
display="block"
align="center"
>
<Typography variant="subtitle2" display="block" align="center">
Allelic requirements:
</Typography>
{allelicRequirements.map((r) => (
{allelicRequirements.map(r => (
<Typography variant="caption" key={r}>
{r}
</Typography>
Expand All @@ -227,14 +200,13 @@ function getColumns(label) {
}
showHelpIcon
>
{alleleOrigins.map((a) => sentenceCase(a)).join("; ")}
{alleleOrigins.map(a => sentenceCase(a)).join("; ")}
</Tooltip>
);

return alleleOrigins.map((a) => sentenceCase(a)).join("; ");
return alleleOrigins.map(a => sentenceCase(a)).join("; ");
},
filterValue: ({ alleleOrigins }) =>
alleleOrigins ? alleleOrigins.join() : "",
filterValue: ({ alleleOrigins }) => (alleleOrigins ? alleleOrigins.join() : ""),
},
{
id: "confidence",
Expand Down Expand Up @@ -263,17 +235,52 @@ function getColumns(label) {
}, []) || [];

return (
<PublicationsDrawer
entries={literatureList}
symbol={label.symbol}
name={label.name}
/>
<PublicationsDrawer entries={literatureList} symbol={label.symbol} name={label.name} />
);
},
},
];
}

const exportColumns = [
{
label: "diseaseId",
exportValue: row => row.disease.id,
},
{
label: "diseaseName",
exportValue: row => row.disease.name,
},
{
label: "variantId",
exportValue: row => row.variantId,
},
{
label: "variantRsId",
exportValue: row => row.variantRsId,
},
{
label: "variantHgvsId",
exportValue: row => row.variantHgvsId,
},
{
label: "variantConsequence",
exportValue: row => row.variantFunctionalConsequence,
},
{
label: "clinicalSignificances",
exportValue: row => row.clinicalSignificances,
},
{
label: "allelicRequirements",
exportValue: row => row.alleleOrigins,
},
{
label: "reviewStatus",
exportValue: row => row.confidence,
},
];

function fetchClinvar({ ensemblId, efoId, cursor, size, freeTextQuery }) {
return client.query({
query: CLINVAR_QUERY,
Expand Down Expand Up @@ -305,12 +312,8 @@ function Body({ id, label, entity }) {
useEffect(() => {
let isCurrent = true;

fetchClinvar({ ensemblId, efoId, cursor: "", size }).then((res) => {
const {
cursor: newCursor,
rows: newRows,
count: newCount,
} = res.data.disease.evidences;
fetchClinvar({ ensemblId, efoId, cursor: "", size }).then(res => {
const { cursor: newCursor, rows: newRows, count: newCount } = res.data.disease.eva;
if (isCurrent) {
setInitialLoading(false);
setCursor(newCursor);
Expand All @@ -330,15 +333,15 @@ function Body({ id, label, entity }) {
ensemblId,
efoId,
},
`data.disease.evaSummary`
`data.disease.eva`
);

const handlePageChange = (newPage) => {
const handlePageChange = newPage => {
const newPageInt = Number(newPage);
if (size * newPageInt + size > rows.length && cursor !== null) {
setLoading(true);
fetchClinvar({ ensemblId, efoId, cursor, size }).then((res) => {
const { cursor: newCursor, rows: newRows } = res.data.disease.evidences;
fetchClinvar({ ensemblId, efoId, cursor, size }).then(res => {
const { cursor: newCursor, rows: newRows } = res.data.disease.eva;
setRows([...rows, ...newRows]);
setLoading(false);
setCursor(newCursor);
Expand All @@ -349,28 +352,25 @@ function Body({ id, label, entity }) {
}
};

const handleRowsPerPageChange = (newPageSize) => {
const handleRowsPerPageChange = newPageSize => {
const newPageSizeInt = Number(newPageSize);
if (newPageSizeInt > rows.length && cursor !== null) {
setLoading(true);
fetchClinvar({ ensemblId, efoId, cursor, size: newPageSizeInt }).then(
(res) => {
const { cursor: newCursor, rows: newRows } =
res.data.disease.evidences;
setRows([...rows, ...newRows]);
setLoading(false);
setCursor(newCursor);
setPage(0);
setPageSize(newPageSizeInt);
}
);
fetchClinvar({ ensemblId, efoId, cursor, size: newPageSizeInt }).then(res => {
const { cursor: newCursor, rows: newRows } = res.data.disease.eva;
setRows([...rows, ...newRows]);
setLoading(false);
setCursor(newCursor);
setPage(0);
setPageSize(newPageSizeInt);
});
} else {
setPage(0);
setPageSize(newPageSizeInt);
}
};

const handleSortBy = (sortBy) => {
const handleSortBy = sortBy => {
setSortColumn(sortBy);
setSortOrder(
// eslint-disable-next-line
Expand All @@ -391,11 +391,9 @@ function Body({ id, label, entity }) {
entity={entity}
request={{
loading: initialLoading,
data: { [entity]: { evaSummary: { rows, count: rows.length } } },
data: { [entity]: { eva: { rows, count: rows.length } } },
}}
renderDescription={() => (
<Description symbol={label.symbol} name={label.name} />
)}
renderDescription={() => <Description symbol={label.symbol} name={label.name} />}
renderBody={() => (
<Table
// showGlobalFilter
Expand All @@ -414,6 +412,7 @@ function Body({ id, label, entity }) {
query={CLINVAR_QUERY.loc.source.body}
dataDownloader
dataDownloaderRows={getWholeDataset}
dataDownloaderColumns={exportColumns}
dataDownloaderFileStem="clinvar-evidence"
variables={{
ensemblId,
Expand Down
9 changes: 2 additions & 7 deletions packages/sections/src/evidence/EVA/ClinvarQuery.gql
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
query ClinvarQuery(
$ensemblId: String!
$efoId: String!
$size: Int!
$cursor: String
) {
query ClinvarQuery($ensemblId: String!, $efoId: String!, $size: Int!, $cursor: String) {
target(ensemblId: $ensemblId) {
approvedSymbol
}
disease(efoId: $efoId) {
id
name
evidences(
eva: evidences(
ensemblIds: [$ensemblId]
enableIndirect: true
datasourceIds: ["eva"]
Expand Down
Loading

0 comments on commit 29da20b

Please sign in to comment.