From 638f8ac99818fa98ba59b03719ab68fd78e2be36 Mon Sep 17 00:00:00 2001 From: HaneenT Date: Mon, 26 Aug 2024 16:13:55 -0400 Subject: [PATCH 1/4] KPMP-5528: get PhysicalSize vars from ome.xml --- package.json | 2 + .../SpatialViewer/segmentationViewConfig.json | 59 +++++++++++++++++++ .../SpatialViewer/viewConfigHelper.js | 13 ++++ 3 files changed, 74 insertions(+) create mode 100644 src/components/SpatialViewer/segmentationViewConfig.json diff --git a/package.json b/package.json index cb899c7e..ab9e85bf 100644 --- a/package.json +++ b/package.json @@ -23,10 +23,12 @@ "bootstrap": "5.2.3", "bootstrap-5-css-only": "5.1.3", "history": "5.1.0", + "@hms-dbmi/viv": "0.16.1", "immutability-helper": "3.1.1", "isomorphic-unfetch": "3.1.0", "kpmp-common-components": "1.2.14", "kpmp-common-styles": "1.0.13", + "mathjs": "13.1.0", "react": "17.0.2", "react-dnd": "15.1.1", "react-dnd-html5-backend": "15.1.2", diff --git a/src/components/SpatialViewer/segmentationViewConfig.json b/src/components/SpatialViewer/segmentationViewConfig.json new file mode 100644 index 00000000..faccae4d --- /dev/null +++ b/src/components/SpatialViewer/segmentationViewConfig.json @@ -0,0 +1,59 @@ +{ + "coordinationSpace": { + "dataset": { + "A": "A" + } + }, + "datasets": [ + { + "files": [ + { + "name": "", + "url": "", + "fileType": "image.ome-tiff" + }, + { + "name": "", + "url": "", + "fileType": "obsSegmentations.ome-tiff", + "options": { + "obsTypesFromChannelNames": true, + "coordinateTransformations": [ + { + "type": "scale", + "scale": [ + "", + "", + 1, + 1, + 1 + ] + } + ] + } + } + ], + "name": "Visualization Files", + "uid": "A" + } + ], + "layout": [ + { + "component": "spatialBeta", + "x": 0, + "y": 0, + "w": 6, + "h": 12 + }, + { + "component": "layerControllerBeta", + "x": 6, + "y": 0, + "w": 6, + "h": 12 + } + ], + "initStrategy": "auto", + "name": "KPMP Spatial Viewer", + "version": "1.0.4" +} \ No newline at end of file diff --git a/src/components/SpatialViewer/viewConfigHelper.js b/src/components/SpatialViewer/viewConfigHelper.js index f188fa4a..e7ba673e 100644 --- a/src/components/SpatialViewer/viewConfigHelper.js +++ b/src/components/SpatialViewer/viewConfigHelper.js @@ -2,7 +2,10 @@ import lmViewConfig from './lightMicroscopyViewConfig.json'; import threeDCytometryViewConfig from './threeDCytometryViewConfig.json'; import threeDCytometryViewNoChannelsConfig from './threeDCytometryViewNoChannelsConfig.json'; import stViewConfig from './spatialTranscriptomicsViewConfig.json' +import segmentationConfig from './segmentationViewConfig.json'; import { getFileLink } from "../../helpers/Api"; +import { loadOmeTiff } from '@hms-dbmi/viv'; +import { unit } from 'mathjs'; export const getViewConfig = (type) => { switch (type) { @@ -16,6 +19,8 @@ export const getViewConfig = (type) => { return lmViewConfig; case 'Spatial Transcriptomics': return stViewConfig; + case 'Segmentation': + return segmentationConfig; default: return threeDCytometryViewConfig } @@ -45,6 +50,14 @@ export const populateViewConfig = async (viewConfig, selectedDataset) => { }); let dataUrl = getPublicFileLink(selectedDataset["packageid"], relatedFiles[0]['filename']); stringifiedConfig = stringifiedConfig.replace(//gi, dataUrl); + stringifiedConfig = stringifiedConfig.replace('', relatedFiles[0]['filename']); + stringifiedConfig = stringifiedConfig.replace('', dataUrl); + + const loaders = await loadOmeTiff(dataUrl); + const physicalSizeX = unit(loaders.metadata.Pixels.PhysicalSizeX, (loaders.metadata.Pixels.PhysicalSizeXUnit.replace('µ', 'u'))).to("um").toNumber(); + const physicalSizeY = unit(loaders.metadata.Pixels.PhysicalSizeY, (loaders.metadata.Pixels.PhysicalSizeYUnit.replace('µ', 'u'))).to("um").toNumber(); + stringifiedConfig = stringifiedConfig.replace('""', physicalSizeX); + stringifiedConfig = stringifiedConfig.replace('""', physicalSizeY); } stringifiedConfig = stringifiedConfig.replace('', selectedDataset["filename"]); stringifiedConfig = stringifiedConfig.replace('', imageUrlResponse.data); From 60fafbee193f08881d4c82a179dbf0d33da37d0b Mon Sep 17 00:00:00 2001 From: HaneenT Date: Tue, 27 Aug 2024 11:54:55 -0400 Subject: [PATCH 2/4] fix test script --- package.json | 3 ++- src/components/SpatialViewer/viewConfigHelper.js | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index ab9e85bf..c2eafcce 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "scripts": { "start": "npm-run-all -p start-js --max_old_space_size=8192", "build": "npm-run-all build-css build-js", - "test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!vitessce|@devexpress|@elastic|react-ga4)'", + "test": "react-scripts test", "eject": "react-scripts eject", "start-js": "craco --max_old_space_size=8192 start", "build-js": "craco --max_old_space_size=8192 build", @@ -70,6 +70,7 @@ }, "jest": { "transformIgnorePatterns": [ + "node_modules/(?!vitessce|@devexpress|@elastic|react-ga4|@hms-dbmi|@deck.gl|@vivjs|quick-lru)", "node_modules/(?!(@ui5|lit-html)).*\\.js$" ] }, diff --git a/src/components/SpatialViewer/viewConfigHelper.js b/src/components/SpatialViewer/viewConfigHelper.js index e7ba673e..2d3cf633 100644 --- a/src/components/SpatialViewer/viewConfigHelper.js +++ b/src/components/SpatialViewer/viewConfigHelper.js @@ -50,14 +50,16 @@ export const populateViewConfig = async (viewConfig, selectedDataset) => { }); let dataUrl = getPublicFileLink(selectedDataset["packageid"], relatedFiles[0]['filename']); stringifiedConfig = stringifiedConfig.replace(//gi, dataUrl); - stringifiedConfig = stringifiedConfig.replace('', relatedFiles[0]['filename']); - stringifiedConfig = stringifiedConfig.replace('', dataUrl); - const loaders = await loadOmeTiff(dataUrl); - const physicalSizeX = unit(loaders.metadata.Pixels.PhysicalSizeX, (loaders.metadata.Pixels.PhysicalSizeXUnit.replace('µ', 'u'))).to("um").toNumber(); - const physicalSizeY = unit(loaders.metadata.Pixels.PhysicalSizeY, (loaders.metadata.Pixels.PhysicalSizeYUnit.replace('µ', 'u'))).to("um").toNumber(); - stringifiedConfig = stringifiedConfig.replace('""', physicalSizeX); - stringifiedConfig = stringifiedConfig.replace('""', physicalSizeY); + if (selectedDataset["configtype"] === "Segmentation") { + stringifiedConfig = stringifiedConfig.replace('', relatedFiles[0]['filename']); + stringifiedConfig = stringifiedConfig.replace('', dataUrl); + const loaders = await loadOmeTiff(dataUrl); + const physicalSizeX = unit(loaders.metadata.Pixels.PhysicalSizeX, (loaders.metadata.Pixels.PhysicalSizeXUnit.replace('µ', 'u'))).to("um").toNumber(); + const physicalSizeY = unit(loaders.metadata.Pixels.PhysicalSizeY, (loaders.metadata.Pixels.PhysicalSizeYUnit.replace('µ', 'u'))).to("um").toNumber(); + stringifiedConfig = stringifiedConfig.replace('""', physicalSizeX); + stringifiedConfig = stringifiedConfig.replace('""', physicalSizeY); + } } stringifiedConfig = stringifiedConfig.replace('', selectedDataset["filename"]); stringifiedConfig = stringifiedConfig.replace('', imageUrlResponse.data); From 99a9cdb9e558718fb8899f52255019edc388e290 Mon Sep 17 00:00:00 2001 From: HaneenT Date: Mon, 9 Sep 2024 08:50:04 -0400 Subject: [PATCH 3/4] update npm run test script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c2eafcce..a8f01e82 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,7 @@ "scripts": { "start": "npm-run-all -p start-js --max_old_space_size=8192", "build": "npm-run-all build-css build-js", - "test": "react-scripts test", + "test": "react-scripts test --transformIgnorePatterns 'node_modules/(?!vitessce|@devexpress|@elastic|react-ga4|@hms-dbmi|@deck.gl|@vivjs)'", "eject": "react-scripts eject", "start-js": "craco --max_old_space_size=8192 start", "build-js": "craco --max_old_space_size=8192 build", From a31b25c78c65a1b3d5cafc6e6e1759aad7e1697d Mon Sep 17 00:00:00 2001 From: HaneenT Date: Mon, 9 Sep 2024 08:51:01 -0400 Subject: [PATCH 4/4] update package.json --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index a8f01e82..85b4842d 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,6 @@ }, "jest": { "transformIgnorePatterns": [ - "node_modules/(?!vitessce|@devexpress|@elastic|react-ga4|@hms-dbmi|@deck.gl|@vivjs|quick-lru)", "node_modules/(?!(@ui5|lit-html)).*\\.js$" ] },