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: Start writing run query for new API #1149

Merged
merged 9 commits into from
Sep 17, 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
11 changes: 5 additions & 6 deletions frontend/packages/data-portal/app/graphql/getRunById.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ const GET_RUN_BY_ID_QUERY = gql(`
primary_author_status
}

authors_with_affiliation: authors(where: { affiliation_name: { _is_null: false } }) {
name
affiliation_name
}

funding_sources {
funding_sources(
order_by: {
funding_agency_name: asc
}
) {
funding_agency_name
grant_id
}
Expand Down
122 changes: 122 additions & 0 deletions frontend/packages/data-portal/app/graphql/getRunByIdDiffer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { diff } from 'deep-object-diff'

import { GetRunByIdQuery } from 'app/__generated__/graphql'
import {
GetRunByIdV2Query,
Sample_Type_Enum,
Tiltseries_Microscope_Manufacturer_Enum,
} from 'app/__generated_v2__/graphql'

/* eslint-disable no-console */
export function logIfHasDiff(
url: string,
v1: GetRunByIdQuery,
v2: GetRunByIdV2Query,
): void {
console.log('Checking for run query diffs')

const v1Transformed: GetRunByIdV2Query = {
runs: v1.runs.map((run) => ({
__typename: 'Run',
id: run.id,
name: run.name,
tiltseries: {
__typename: 'TiltseriesConnection',
edges: run.tiltseries.map((runTiltseries) => ({
__typename: 'TiltseriesEdge',
node: {
__typename: 'Tiltseries',
accelerationVoltage: runTiltseries.acceleration_voltage,
alignedTiltseriesBinning: runTiltseries.aligned_tiltseries_binning,
binningFromFrames: runTiltseries.binning_from_frames,
cameraManufacturer: runTiltseries.camera_manufacturer,
cameraModel: runTiltseries.camera_model,
dataAcquisitionSoftware: runTiltseries.data_acquisition_software,
id: runTiltseries.id,
isAligned: runTiltseries.is_aligned,
microscopeAdditionalInfo: runTiltseries.microscope_additional_info,
microscopeEnergyFilter: runTiltseries.microscope_energy_filter,
microscopeImageCorrector: runTiltseries.microscope_image_corrector,
microscopeManufacturer:
runTiltseries.microscope_manufacturer as Tiltseries_Microscope_Manufacturer_Enum,
microscopeModel: runTiltseries.microscope_model,
microscopePhasePlate: runTiltseries.microscope_phase_plate,
pixelSpacing: runTiltseries.pixel_spacing!,
relatedEmpiarEntry: runTiltseries.related_empiar_entry,
sphericalAberrationConstant:
runTiltseries.spherical_aberration_constant,
tiltAxis: runTiltseries.tilt_axis,
tiltMax: runTiltseries.tilt_max,
tiltMin: runTiltseries.tilt_min,
tiltRange: runTiltseries.tilt_range,
tiltSeriesQuality: runTiltseries.tilt_series_quality,
tiltStep: runTiltseries.tilt_step,
tiltingScheme: runTiltseries.tilting_scheme,
totalFlux: runTiltseries.total_flux,
},
})),
},
dataset: {
__typename: 'Dataset',
cellComponentName: run.dataset.cell_component_name,
cellComponentId: run.dataset.cell_component_id,
cellName: run.dataset.cell_name,
cellStrainName: run.dataset.cell_strain_name,
cellStrainId: run.dataset.cell_strain_id,
cellTypeId: run.dataset.cell_type_id,
depositionDate: `${run.dataset.deposition_date}T00:00:00+00:00`,
description: run.dataset.description,
gridPreparation: run.dataset.grid_preparation,
id: run.dataset.id,
lastModifiedDate: `${run.dataset.last_modified_date}T00:00:00+00:00`,
organismName: run.dataset.organism_name!,
organismTaxid: Number(run.dataset.organism_taxid),
otherSetup: run.dataset.other_setup,
publications: run.dataset.dataset_publications,
relatedDatabaseEntries: run.dataset.related_database_entries,
releaseDate: `${run.dataset.release_date}T00:00:00+00:00`,
s3Prefix: run.dataset.s3_prefix,
samplePreparation: run.dataset.sample_preparation,
sampleType: run.dataset.sample_type as Sample_Type_Enum,
tissueName: run.dataset.tissue_name,
tissueId: run.dataset.tissue_id,
title: run.dataset.title,
fundingSources: {
__typename: 'DatasetFundingConnection',
edges: run.dataset.funding_sources.map((source) => ({
__typename: 'DatasetFundingEdge',
node: {
__typename: 'DatasetFunding',
fundingAgencyName: source.funding_agency_name,
grantId: source.grant_id,
},
})),
},
authors: {
__typename: 'DatasetAuthorConnection',
edges: run.dataset.authors.map((author) => ({
__typename: 'DatasetAuthorEdge',
node: {
__typename: 'DatasetAuthor',
correspondingAuthorStatus: author.corresponding_author_status,
email: author.email,
name: author.name,
orcid: author.orcid,
primaryAuthorStatus: author.primary_author_status,
},
})),
},
},
})),
}

const diffObject = diff(v1Transformed, v2)

if (Object.keys(diffObject).length > 0) {
console.log(
`DIFF AT ${url}: ${JSON.stringify(diffObject)} | ${JSON.stringify(
diff(v2, v1Transformed),
)}`,
)
}
}
109 changes: 102 additions & 7 deletions frontend/packages/data-portal/app/graphql/getRunByIdV2.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,112 @@ import { gql } from 'app/__generated_v2__'
import { GetRunByIdV2Query } from 'app/__generated_v2__/graphql'

const GET_RUN_BY_ID_QUERY_V2 = gql(`
query GetRunByIdV2 {
__typename
query GetRunByIdV2(
$id: Int
) {
runs(where: { id: { _eq: $id } }) {
id
name

tiltseries(first: 1) {
edges {
node {
accelerationVoltage
alignedTiltseriesBinning
binningFromFrames
cameraManufacturer
cameraModel
dataAcquisitionSoftware
id
isAligned
microscopeAdditionalInfo
microscopeEnergyFilter
microscopeImageCorrector
microscopeManufacturer
microscopeModel
microscopePhasePlate
pixelSpacing
relatedEmpiarEntry
sphericalAberrationConstant
tiltAxis
tiltMax
tiltMin
tiltRange
tiltSeriesQuality
tiltStep
tiltingScheme
totalFlux
}
}
}

dataset {
cellComponentName
cellComponentId
cellName
cellStrainName
cellStrainId
cellTypeId
depositionDate
description
gridPreparation
id
lastModifiedDate
organismName
organismTaxid
otherSetup
publications
relatedDatabaseEntries
relatedDatabaseEntries
releaseDate
s3Prefix
samplePreparation
sampleType
tissueName
tissueId
title

fundingSources(
orderBy: {
fundingAgencyName: asc
}
) {
edges {
node {
fundingAgencyName
grantId
}
}
}

authors(
orderBy: {
authorListOrder: asc,
},
) {
edges {
node {
correspondingAuthorStatus
email
name
orcid
primaryAuthorStatus
}
}
}
}
}
}
`)

export async function getRunById({
client,
}: {
client: ApolloClient<NormalizedCacheObject>
}): Promise<ApolloQueryResult<GetRunByIdV2Query>> {
export async function getRunByIdV2(
client: ApolloClient<NormalizedCacheObject>,
id: number,
): Promise<ApolloQueryResult<GetRunByIdV2Query>> {
return client.query({
query: GET_RUN_BY_ID_QUERY_V2,
variables: {
id,
},
})
}
38 changes: 22 additions & 16 deletions frontend/packages/data-portal/app/hooks/useRunById.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
import { useTypedLoaderData } from 'remix-typedjson'

import { GetRunByIdQuery } from 'app/__generated__/graphql'
import { GetRunByIdV2Query } from 'app/__generated_v2__/graphql'
import { isNotNullish } from 'app/utils/nullish'

export function useRunById() {
const data = useTypedLoaderData<GetRunByIdQuery>()
const { v1 } = useTypedLoaderData<{
v1: GetRunByIdQuery
v2: GetRunByIdV2Query
}>()

const run = data.runs[0]
const run = v1.runs[0]

const annotationFiles = data.annotation_files
const annotationFiles = v1.annotation_files

const { tomograms } = data
const { tomograms } = v1

const tomogramsForDownload = data.tomograms_for_download
const tomogramsForDownload = v1.tomograms_for_download

const processingMethods = data.tomograms_for_distinct_processing_methods.map(
const processingMethods = v1.tomograms_for_distinct_processing_methods.map(
(tomogram) => tomogram.processing,
)

const objectNames = data.annotations_for_object_names.map(
const objectNames = v1.annotations_for_object_names.map(
(annotation) => annotation.object_name,
)

const objectShapeTypes = data.annotation_files_for_shape_types.map(
const objectShapeTypes = v1.annotation_files_for_shape_types.map(
(file) => file.shape_type,
)

const annotationSoftwares = data.annotations_for_softwares
const annotationSoftwares = v1.annotations_for_softwares
.map((annotation) => annotation.annotation_software)
.filter(isNotNullish)

const resolutions = data.tomograms_for_resolutions.map(
const resolutions = v1.tomograms_for_resolutions.map(
(tomogram) => tomogram.voxel_spacing,
)

const annotationFilesAggregates = {
totalCount: data.annotation_files_aggregate_for_total.aggregate?.count ?? 0,
totalCount: v1.annotation_files_aggregate_for_total.aggregate?.count ?? 0,
filteredCount:
data.annotation_files_aggregate_for_filtered.aggregate?.count ?? 0,
v1.annotation_files_aggregate_for_filtered.aggregate?.count ?? 0,
groundTruthCount:
data.annotation_files_aggregate_for_ground_truth.aggregate?.count ?? 0,
otherCount: data.annotation_files_aggregate_for_other.aggregate?.count ?? 0,
v1.annotation_files_aggregate_for_ground_truth.aggregate?.count ?? 0,
otherCount: v1.annotation_files_aggregate_for_other.aggregate?.count ?? 0,
}

const tomogramsCount = data.tomograms_aggregate.aggregate?.count ?? 0
const tomogramsCount = v1.tomograms_aggregate.aggregate?.count ?? 0

const { deposition } = v1

return {
run,
Expand All @@ -57,6 +63,6 @@ export function useRunById() {
resolutions,
annotationFilesAggregates,
tomogramsCount,
deposition: data.deposition,
deposition,
}
}
Loading
Loading