Skip to content

Commit

Permalink
Fix getWellSamples/getPlateAcquisitions
Browse files Browse the repository at this point in the history
  • Loading branch information
ppouchin committed Oct 25, 2023
1 parent ea00830 commit 567c052
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 36 deletions.
4 changes: 2 additions & 2 deletions .omeroci/test-data
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/fr/igred/omero/repository/ImageWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ public List<WellSampleWrapper> getWellSamples() {
*/
public List<WellSampleWrapper> getWellSamples(Client client)
throws AccessException, ServiceException, ExecutionException {
reload(client);
List<WellSampleWrapper> samples = getWellSamples();
for (WellSampleWrapper sample : samples) {
sample.reload(client);
Expand All @@ -345,17 +346,12 @@ public List<WellSampleWrapper> getWellSamples(Client client)
*/
public List<WellWrapper> getWells(Client client)
throws AccessException, ServiceException, ExecutionException {
List<WellSampleWrapper> wellSamples = getWellSamples();
List<WellSampleWrapper> wellSamples = getWellSamples(client);
Collection<WellWrapper> 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);
}


Expand All @@ -372,13 +368,13 @@ public List<WellWrapper> getWells(Client client)
*/
public List<PlateAcquisitionWrapper> getPlateAcquisitions(Client client)
throws AccessException, ServiceException, ExecutionException {
List<WellWrapper> wells = getWells(client);
List<WellSampleWrapper> wellSamples = getWellSamples(client);

Collection<List<PlateAcquisitionWrapper>> acqs = new ArrayList<>(wells.size());
for (WellWrapper w : wells) {
acqs.add(w.getPlateAcquisitions(client));
Collection<PlateAcquisitionWrapper> acqs = new ArrayList<>(wellSamples.size());
for (WellSampleWrapper ws : wellSamples) {
acqs.add(ws.getPlateAcquisition());
}
return flatten(acqs);
return distinct(acqs);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -215,6 +213,51 @@ public List<WellWrapper> getWells(Client client)
}


/**
* Retrieves the well samples for this plate acquisition.
*
* @return See above.
*/
public List<WellSampleWrapper> 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<WellSampleWrapper> getWellSamples(Browser browser)
throws AccessException, ServiceException, ExecutionException {
reload(browser);
return getWellSamples();
}


/**
* Retrieves the images contained in the well samples.
*
* @return See above
*/
public List<ImageWrapper> getImages() {
return getWellSamples().stream()
.map(WellSampleWrapper::getImage)
.collect(Collectors.toList());
}


/**
* Retrieves the images contained in the wells in the parent plate.
*
Expand All @@ -228,14 +271,9 @@ public List<WellWrapper> getWells(Client client)
*/
public List<ImageWrapper> 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());
}


Expand Down
11 changes: 11 additions & 0 deletions src/main/java/fr/igred/omero/repository/WellSampleWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,6 +100,16 @@ public List<PlateWrapper> 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.
*
Expand Down
12 changes: 8 additions & 4 deletions src/test/java/fr/igred/omero/repository/ImageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlateAcquisitionWrapper> acqs = image.getPlateAcquisitions(client);
assertEquals(1, acqs.size());
assertEquals(name, acqs.get(0).getName());
}


Expand All @@ -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();
Expand Down
14 changes: 12 additions & 2 deletions src/test/java/fr/igred/omero/repository/PlateAcquisitionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageWrapper> 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<ImageWrapper> images = acq.getImages();
assertEquals(18, images.size());
}


Expand Down
6 changes: 2 additions & 4 deletions src/test/java/fr/igred/omero/repository/PlateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlateAcquisitionWrapper> acquisitions = plate.getPlateAcquisitions();
assertEquals(1, acquisitions.size());
assertEquals(name, acquisitions.get(0).getName());
assertEquals(2, acquisitions.size());
assertEquals(1L, acquisitions.get(0).getId());
}


Expand Down
11 changes: 10 additions & 1 deletion src/test/java/fr/igred/omero/repository/WellSampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<PlateAcquisitionWrapper> acqs = sample.getPlateAcquisitions(client);
assertEquals(1, acqs.size());
assertEquals(2, acqs.size());
}


Expand Down

0 comments on commit 567c052

Please sign in to comment.