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

feat: Convert deposition page query to V2 #1452

Merged
merged 9 commits into from
Jan 14, 2025
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
258 changes: 257 additions & 1 deletion frontend/packages/data-portal/app/graphql/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { Depositions_Bool_Exp } from 'app/__generated__/graphql'
import { Tomogram_Reconstruction_Method_Enum } from 'app/__generated_v2__/graphql'
import {
Annotation_File_Shape_Type_Enum,
DatasetWhereClause,
Fiducial_Alignment_Status_Enum,
Tomogram_Reconstruction_Method_Enum,
} from 'app/__generated_v2__/graphql'
import {
DEFAULT_TILT_RANGE_MAX,
DEFAULT_TILT_RANGE_MIN,
} from 'app/constants/tiltSeries'
import { FilterState } from 'app/hooks/useFilter'

export const depositionWithAnnotationFilter: Depositions_Bool_Exp = {
annotations_aggregate: {
Expand Down Expand Up @@ -28,3 +38,249 @@ export function convertReconstructionMethodToV2(
return Tomogram_Reconstruction_Method_Enum.Unknown
}
}

export interface GetDatasetsFilterParams {
filterState: FilterState
depositionId?: number
searchText?: string
}

export function getDatasetsFilter({
filterState,
depositionId,
searchText,
}: GetDatasetsFilterParams): DatasetWhereClause {
const where: DatasetWhereClause = {}

// Search by Dataset Name
if (searchText) {
where.title = {
_ilike: `%${searchText}%`,
}
}

// INCLUDED CONTENTS SECTION
// Ground Truth Annotation
if (filterState.includedContents.isGroundTruthEnabled) {
where.runs ??= { annotations: {} }
where.runs.annotations ??= {}
where.runs.annotations.groundTruthStatus = {
_eq: true,
}
}
// Available Files
// TODO(bchu): Implement when available in API.
// filterState.includedContents.availableFiles.forEach((file) =>
// match(file)
// .with('raw-frames', () =>
// where.push({
// runs: {
// tiltseries: {
// frames_count: {
// _gt: 0,
// },
// },
// },
// }),
// )
// .with('tilt-series', () =>
// where.push({
// runs: {
// tiltseries_aggregate: {
// count: {
// predicate: {
// _gt: 0,
// },
// },
// },
// },
// }),
// )
// .with('tilt-series-alignment', () =>
// where.push({
// runs: {
// tiltseries: {
// https_alignment_file: {
// _is_null: false,
// },
// },
// },
// }),
// )
// .with('tomogram', () =>
// where.push({
// runs: {
// tomogram_voxel_spacings: {
// tomograms_aggregate: {
// count: {
// predicate: {
// _gt: 0,
// },
// },
// },
// },
// },
// }),
// )
// .exhaustive(),
// )
// Number of Runs
// TODO: Implement when available in API.
// if (filterState.includedContents.numberOfRuns) {
// const runCount = +filterState.includedContents.numberOfRuns.slice(1)
// where.push({
// runs_aggregate: {
// count: {
// predicate: { _gte: runCount },
// },
// },
// })
// }

// NAME/ID SECTION
// Dataset IDs
const datasetId =
filterState.ids.dataset !== null
? parseInt(filterState.ids.dataset)
: undefined
if (Number.isInteger(datasetId)) {
where.id = {
_eq: datasetId,
}
}
const empiarId = filterState.ids.empiar
const emdbId = filterState.ids.emdb
if (empiarId && emdbId) {
where.relatedDatabaseEntries = {
_regex: `(EMPIAR-${empiarId}.*EMD-${emdbId})|(EMD-${emdbId}.*EMPIAR-${empiarId})`, // Ignores order
}
} else if (empiarId) {
where.relatedDatabaseEntries = {
_regex: `EMPIAR-${empiarId}`,
}
} else if (emdbId) {
where.relatedDatabaseEntries = {
_regex: `EMD-${emdbId}`,
}
}
// Dataset Author
if (filterState.author.name) {
where.authors ??= {}
where.authors.name = {
_ilike: `%${filterState.author.name}%`,
}
}
if (filterState.author.orcid) {
where.authors ??= {}
where.authors.orcid = {
_ilike: `%${filterState.author.orcid}%`,
}
}
// Deposition ID
const filterDepositionId =
filterState.ids.deposition !== null
? parseInt(filterState.ids.deposition)
: undefined
if (depositionId !== undefined || Number.isInteger(filterDepositionId)) {
where.runs ??= { annotations: {} }
where.runs.annotations ??= {}
where.runs.annotations.depositionId = {
_eq: depositionId ?? filterDepositionId,
}
}

// SAMPLE AND EXPERIMENT CONDITIONS SECTION
const { organismNames } = filterState.sampleAndExperimentConditions
if (organismNames.length > 0) {
where.organismName = {
_in: organismNames,
}
}

// ANNOTATION METADATA SECTION
const { objectNames, objectId, objectShapeTypes } = filterState.annotation
// Object Name
if (objectNames.length > 0) {
where.runs ??= { annotations: {} }
where.runs.annotations ??= {}
where.runs.annotations.objectName = {
_in: objectNames,
}
}
// Object ID
if (objectId) {
where.runs ??= { annotations: {} }
where.runs.annotations ??= {}
where.runs.annotations.objectId = {
_eq: objectId,
}
}
// Object Shape Type
if (objectShapeTypes.length > 0) {
where.runs ??= { annotations: {} }
where.runs.annotations ??= {}
where.runs.annotations.annotationShapes = {
shapeType: {
_in: objectShapeTypes as Annotation_File_Shape_Type_Enum[], // TODO(bchu): Remove typecast.
},
}
}

// HARDWARE SECTION
if (filterState.hardware.cameraManufacturer) {
where.runs ??= { tiltseries: {} }
where.runs.tiltseries ??= {}
where.runs.tiltseries.cameraManufacturer = {
_eq: filterState.hardware.cameraManufacturer,
}
}

// TILT SERIES METADATA SECTION
const tiltRangeMin = parseFloat(filterState.tiltSeries.min)
const tiltRangeMax = parseFloat(filterState.tiltSeries.max)
if (Number.isFinite(tiltRangeMin) || Number.isFinite(tiltRangeMax)) {
where.runs ??= { tiltseries: {} }
where.runs.tiltseries ??= {}
where.runs.tiltseries.tiltRange = {
_gte: Number.isFinite(tiltRangeMin)
? tiltRangeMin
: DEFAULT_TILT_RANGE_MIN,
_lte: Number.isFinite(tiltRangeMax)
? tiltRangeMax
: DEFAULT_TILT_RANGE_MAX,
}
}

// TOMOGRAM METADATA SECTION
// Fiducial Alignment Status
if (filterState.tomogram.fiducialAlignmentStatus) {
where.runs ??= { tomograms: {} }
where.runs.tomograms ??= {}
where.runs.tomograms.fiducialAlignmentStatus = {
_eq:
filterState.tomogram.fiducialAlignmentStatus === 'true'
? Fiducial_Alignment_Status_Enum.Fiducial
: Fiducial_Alignment_Status_Enum.NonFiducial,
}
}
// Reconstruction Method
if (filterState.tomogram.reconstructionMethod) {
where.runs ??= { tomograms: {} }
where.runs.tomograms ??= {}
where.runs.tomograms.reconstructionMethod = {
_eq: convertReconstructionMethodToV2(
filterState.tomogram.reconstructionMethod,
),
}
}
// Reconstruction Software
if (filterState.tomogram.reconstructionSoftware) {
where.runs ??= { tomograms: {} }
where.runs.tomograms ??= {}
where.runs.tomograms.reconstructionSoftware = {
_eq: filterState.tomogram.reconstructionSoftware,
}
}

return where
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import { gql } from 'app/__generated_v2__'
* Shares aggregate queries between datasets and deposition pages (the 2 pages are very similar).
*
* Parent query must define the following variables:
* - $datasetsFilter
* - $datasetsByDepositionFilter
* - $tiltseriesByDepositionFilter
* - $tomogramsByDepositionFilter
* - $annotationsByDepositionFilter
* - $annotationShapesByDepositionFilter
* - $datasetsFilter: DatasetWhereClause
* - $datasetsByDepositionFilter: DatasetWhereClause
* - $tiltseriesByDepositionFilter: TiltseriesWhereClause
* - $tomogramsByDepositionFilter: TomogramWhereClause
* - $annotationsByDepositionFilter: AnnotationWhereClause
* - $annotationShapesByDepositionFilter: AnnotationShapeWhereClause
*/
export const GET_DATASETS_AGGREGATES_FRAGMENT = gql(`
fragment DatasetsAggregates on Query {
Expand Down
Loading
Loading