From 567c0525316cf9186d2b2c7c636e58e45934174e Mon Sep 17 00:00:00 2001 From: Pierre Pouchin Date: Tue, 24 Oct 2023 12:56:34 +0200 Subject: [PATCH] Fix getWellSamples/getPlateAcquisitions --- .omeroci/test-data | 4 +- .../igred/omero/repository/ImageWrapper.java | 20 +++---- .../repository/PlateAcquisitionWrapper.java | 60 +++++++++++++++---- .../omero/repository/WellSampleWrapper.java | 11 ++++ .../fr/igred/omero/repository/ImageTest.java | 12 ++-- .../repository/PlateAcquisitionTest.java | 14 ++++- .../fr/igred/omero/repository/PlateTest.java | 6 +- .../omero/repository/WellSampleTest.java | 11 +++- 8 files changed, 102 insertions(+), 36 deletions(-) diff --git a/.omeroci/test-data b/.omeroci/test-data index c61cf720..1a0ce5fd 100755 --- a/.omeroci/test-data +++ b/.omeroci/test-data @@ -54,10 +54,10 @@ touch "$WORKDIR/screen1.fake" { echo "screens=1" echo "plates=1" - echo "plateAcqs=1" + echo "plateAcqs=2" echo "plateRows=3" echo "plateCols=3" - echo "fields=4" + echo "fields=2" } > "$WORKDIR/screen1.fake.ini" touch "$WORKDIR/screen2.fake" diff --git a/src/main/java/fr/igred/omero/repository/ImageWrapper.java b/src/main/java/fr/igred/omero/repository/ImageWrapper.java index b9642a13..1ce0dd59 100644 --- a/src/main/java/fr/igred/omero/repository/ImageWrapper.java +++ b/src/main/java/fr/igred/omero/repository/ImageWrapper.java @@ -324,6 +324,7 @@ public List getWellSamples() { */ public List getWellSamples(Client client) throws AccessException, ServiceException, ExecutionException { + reload(client); List samples = getWellSamples(); for (WellSampleWrapper sample : samples) { sample.reload(client); @@ -345,17 +346,12 @@ public List getWellSamples(Client client) */ public List getWells(Client client) throws AccessException, ServiceException, ExecutionException { - List wellSamples = getWellSamples(); + List wellSamples = getWellSamples(client); Collection wells = new ArrayList<>(wellSamples.size()); for (WellSampleWrapper ws : wellSamples) { wells.add(ws.getWell(client)); } - Long[] ids = wells.stream() - .map(WellWrapper::getId) - .sorted() - .distinct() - .toArray(Long[]::new); - return client.getWells(ids); + return distinct(wells); } @@ -372,13 +368,13 @@ public List getWells(Client client) */ public List getPlateAcquisitions(Client client) throws AccessException, ServiceException, ExecutionException { - List wells = getWells(client); + List wellSamples = getWellSamples(client); - Collection> acqs = new ArrayList<>(wells.size()); - for (WellWrapper w : wells) { - acqs.add(w.getPlateAcquisitions(client)); + Collection acqs = new ArrayList<>(wellSamples.size()); + for (WellSampleWrapper ws : wellSamples) { + acqs.add(ws.getPlateAcquisition()); } - return flatten(acqs); + return distinct(acqs); } diff --git a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java index 0e002d36..d67377c1 100644 --- a/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java +++ b/src/main/java/fr/igred/omero/repository/PlateAcquisitionWrapper.java @@ -20,21 +20,19 @@ import fr.igred.omero.Browser; import fr.igred.omero.Client; -import fr.igred.omero.GenericObjectWrapper; import fr.igred.omero.exception.AccessException; import fr.igred.omero.exception.ExceptionHandler; import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import omero.gateway.model.AnnotationData; import omero.gateway.model.PlateAcquisitionData; +import omero.gateway.model.WellSampleData; import omero.model.IObject; import omero.model.PlateAcquisitionAnnotationLink; import omero.model.PlateAcquisitionAnnotationLinkI; import omero.model._PlateAcquisitionOperationsNC; import java.sql.Timestamp; -import java.util.Collection; -import java.util.Comparator; import java.util.List; import java.util.concurrent.ExecutionException; import java.util.stream.Collectors; @@ -215,6 +213,51 @@ public List getWells(Client client) } + /** + * Retrieves the well samples for this plate acquisition. + * + * @return See above. + */ + public List getWellSamples() { + _PlateAcquisitionOperationsNC pa = (_PlateAcquisitionOperationsNC) data.asIObject(); + return pa.copyWellSample() + .stream() + .map(WellSampleData::new) + .map(WellSampleWrapper::new) + .collect(Collectors.toList()); + } + + + /** + * Retrieves the well samples for this plate acquisition from OMERO and updates the object. + * + * @param browser The data browser. + * + * @return See above. + * + * @throws ServiceException Cannot connect to OMERO. + * @throws AccessException Cannot access data. + * @throws ExecutionException A Facility can't be retrieved or instantiated. + */ + public List getWellSamples(Browser browser) + throws AccessException, ServiceException, ExecutionException { + reload(browser); + return getWellSamples(); + } + + + /** + * Retrieves the images contained in the well samples. + * + * @return See above + */ + public List getImages() { + return getWellSamples().stream() + .map(WellSampleWrapper::getImage) + .collect(Collectors.toList()); + } + + /** * Retrieves the images contained in the wells in the parent plate. * @@ -228,14 +271,9 @@ public List getWells(Client client) */ public List getImages(Client client) throws ServiceException, AccessException, ExecutionException { - return getWells(client).stream() - .map(WellWrapper::getImages) - .flatMap(Collection::stream) - .collect(Collectors.toMap(GenericObjectWrapper::getId, i -> i, (i1, i2) -> i1)) - .values() - .stream() - .sorted(Comparator.comparing(GenericObjectWrapper::getId)) - .collect(Collectors.toList()); + return getWellSamples(client).stream() + .map(WellSampleWrapper::getImage) + .collect(Collectors.toList()); } diff --git a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java index 1742e782..5eadfd32 100644 --- a/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java +++ b/src/main/java/fr/igred/omero/repository/WellSampleWrapper.java @@ -26,6 +26,7 @@ import fr.igred.omero.exception.OMEROServerError; import fr.igred.omero.exception.ServiceException; import ome.model.units.BigResult; +import omero.gateway.model.PlateAcquisitionData; import omero.gateway.model.WellSampleData; import omero.model.IObject; import omero.model.Length; @@ -99,6 +100,16 @@ public List getPlates(Client client) } + /** + * Returns the plate acquisition containing this well sample. + * + * @return See above. + */ + public PlateAcquisitionWrapper getPlateAcquisition() { + return new PlateAcquisitionWrapper(new PlateAcquisitionData(data.asWellSample().getPlateAcquisition())); + } + + /** * Returns the plate acquisitions linked to the parent Well. * diff --git a/src/test/java/fr/igred/omero/repository/ImageTest.java b/src/test/java/fr/igred/omero/repository/ImageTest.java index 3d7b75fa..1bf4e778 100644 --- a/src/test/java/fr/igred/omero/repository/ImageTest.java +++ b/src/test/java/fr/igred/omero/repository/ImageTest.java @@ -91,9 +91,13 @@ void testGetPlates() throws Exception { @Test void testGetPlateAcquisitions() throws Exception { - final long id = 5L; - final String name = "PlateAcquisition Name 0"; - assertEquals(name, client.getImage(id).getPlateAcquisitions(client).get(0).getName()); + PlateAcquisitionWrapper pa = client.getPlate(PLATE1.id).getPlateAcquisitions().get(0); + + String name = pa.getName(); + ImageWrapper image = pa.getImages(client).get(0); + List acqs = image.getPlateAcquisitions(client); + assertEquals(1, acqs.size()); + assertEquals(name, acqs.get(0).getName()); } @@ -109,7 +113,7 @@ void testGetWells() throws Exception { @Test void testGetWellSamples() throws Exception { - final long wellId = 1L; + final long wellId = 1L; WellSampleWrapper sample = client.getWell(wellId).getWellSamples().get(0); ImageWrapper image = sample.getImage(); diff --git a/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java b/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java index c948a5d2..3d5206aa 100644 --- a/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java +++ b/src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java @@ -57,11 +57,21 @@ void testGetWells() throws Exception { @Test - void testGetImages() throws Exception { + void testGetImages1() throws Exception { PlateWrapper plate = client.getPlate(PLATE1.id); PlateAcquisitionWrapper acq = plate.getPlateAcquisitions().get(0); List images = acq.getImages(client); - assertEquals(36, images.size()); + assertEquals(18, images.size()); + } + + + @Test + void testGetImages2() throws Exception { + PlateWrapper plate = client.getPlate(PLATE1.id); + PlateAcquisitionWrapper acq = plate.getPlateAcquisitions().get(0); + acq.reload(client); + List images = acq.getImages(); + assertEquals(18, images.size()); } diff --git a/src/test/java/fr/igred/omero/repository/PlateTest.java b/src/test/java/fr/igred/omero/repository/PlateTest.java index 933eaad2..00382956 100644 --- a/src/test/java/fr/igred/omero/repository/PlateTest.java +++ b/src/test/java/fr/igred/omero/repository/PlateTest.java @@ -72,13 +72,11 @@ void testGetWellsFromPlate2() throws Exception { @Test void testGetPlateAcquisitionsFromPlate() throws Exception { - final String name = "PlateAcquisition Name 0"; - PlateWrapper plate = client.getPlate(PLATE1.id); List acquisitions = plate.getPlateAcquisitions(); - assertEquals(1, acquisitions.size()); - assertEquals(name, acquisitions.get(0).getName()); + assertEquals(2, acquisitions.size()); + assertEquals(1L, acquisitions.get(0).getId()); } diff --git a/src/test/java/fr/igred/omero/repository/WellSampleTest.java b/src/test/java/fr/igred/omero/repository/WellSampleTest.java index f4a32ca1..980fe691 100644 --- a/src/test/java/fr/igred/omero/repository/WellSampleTest.java +++ b/src/test/java/fr/igred/omero/repository/WellSampleTest.java @@ -50,12 +50,21 @@ void testGetPlates() throws Exception { } + @Test + void testGetPlateAcquisition() throws Exception { + PlateWrapper plate = client.getPlate(1L); + PlateAcquisitionWrapper acq = plate.getPlateAcquisitions().get(0); + WellSampleWrapper sample = acq.getWellSamples(client).get(0); + assertEquals(acq.getId(), sample.getPlateAcquisition().getId()); + } + + @Test void testGetPlateAcquisitions() throws Exception { WellWrapper well = client.getWell(1L); WellSampleWrapper sample = well.getWellSamples().get(0); List acqs = sample.getPlateAcquisitions(client); - assertEquals(1, acqs.size()); + assertEquals(2, acqs.size()); }