Skip to content

Commit

Permalink
Merge pull request #102 from dominikl/fix_object_loading
Browse files Browse the repository at this point in the history
Fix object loading
  • Loading branch information
dominikl authored Apr 10, 2023
2 parents 782f0a1 + 5a6487a commit 4d30c82
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 78 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
0.4.12 (April 2023)
-------------------
- fix IllegalAccessExceptions (PR #102)

0.4.11 (October 2021)
---------------------
- fix variable exports (PRs #95, #96)

0.4.10 (October 2020)
---------------------

Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: romero.gateway
Type: Package
Version: 0.4.11-999
Date: 2023-04-07
Version: 0.4.12
Date: 2023-04-10
Title: OMERO R Gateway
Description: R Wrapper around the OMERO Java Gateway, which
enables access to an OMERO server within R.
Expand Down
5 changes: 2 additions & 3 deletions R/Dataset.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ setMethod(

jimgs <- fac$getImagesForDatasets(ctx, jlist)
result <- c()
it <- jimgs$iterator()
while(it$hasNext()) {
jimg <- .jrcall(it, method = "next")
jimgslist <- as.list(jimgs)
for (jimg in jimgslist) {
img <- Image(server=server, dataobject=jimg)
result <- c(result, img)
}
Expand Down
20 changes: 8 additions & 12 deletions R/Image.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ setMethod(
iid <- image@dataobject$getId()
jchannels <- fac$getChannelData(ctx, .jlong(iid))
channels <- c()
it <- jchannels$iterator()
while(it$hasNext()) {
jchannel <- .jrcall(it, method = "next")
jchannelslist <- as.list(jchannels)
for (jchannel in jchannelslist) {
channels <- c(channels, jchannel$getName())
}
return(channels)
Expand Down Expand Up @@ -233,17 +232,14 @@ setMethod(

roiresults <- fac$loadROIsByPlane(ctx, iid, z, t)
rois <- data.frame(x = c(0), y = c(0), rx = c(0), ry = c(0), w = c(0), h = c(0), theta = c(0), text = c('remove'), stringsAsFactors = FALSE)
it <- roiresults$iterator()
while (it$hasNext()) {
roiresult <- .jrcall(it, method = "next")
roiresultslist <- as.list(roiresults)
for (roiresult in roiresultslist) {
roidatas <- roiresult$getROIs()
it2 <- roidatas$iterator()
while (it2$hasNext()) {
roidata <- .jrcall(it2, method = "next")
roidataslist <- as.list(roidatas)
for (roidata in roidataslist) {
shapes <- roidata$getShapes(z, t)
it3 <- shapes$iterator()
while (it3$hasNext()) {
shape <- .jrcall(it3, method = "next")
shapeslist <- as.list(shapes)
for (shape in shapeslist) {
shape <- .jcast(shape, new.class = "omero.gateway.model.ShapeData")
trans <- shape$getTransform()
th <- NA
Expand Down
10 changes: 4 additions & 6 deletions R/OMERO.R
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,8 @@ setMethod(
Name <- c()
ID <- c()
AnnotationID <- c()
it <- files$iterator()
while(it$hasNext()) {
file <- .jrcall(it, method = "next")
filelist <- as.list(files)
for (file in filelist) {
Name <- c(Name, file$getFileName())
ID <- c(ID, file$getFileID())
AnnotationID <- c(AnnotationID, file$getId())
Expand Down Expand Up @@ -644,9 +643,8 @@ setMethod(f="getAnnotations",

result <- data.frame(Type = character(), Namespace = character(), Name = character(), Content = character(), ID = numeric(), FileID = numeric())

it <- jannos$iterator()
while(it$hasNext()) {
anno <- .jrcall(it, method = "next")
jannoslist <- as.list(jannos)
for (anno in jannoslist) {
javclass <- anno$getClass()
annotype <- javclass$getName()
annotype <- gsub("omero\\.gateway\\.model\\.", "", annotype)
Expand Down
60 changes: 24 additions & 36 deletions R/OMEROServer.R
Original file line number Diff line number Diff line change
Expand Up @@ -608,31 +608,24 @@ setMethod(f="loadObject",
{
gateway <- getGateway(server)
ctx <- getContext(server)
browse <- gateway$getFacility(J("omero.gateway.facility.BrowseFacility")$class)
lf <- gateway$getFacility(J("omero.gateway.facility.LoadFacility")$class)
if (type == 'ImageData') {
object <- browse$getImage(ctx, .jlong(id))
object <- lf$getImage(ctx, .jlong(id))
}
else if (type == 'ProjectData') {
object <- lf$getProject(ctx, .jlong(id))
}
else if (type == 'ScreenData') {
object <- lf$getScreen(ctx, .jlong(id))
}
else if (type == 'DatasetData') {
object <- lf$getDataset(ctx, .jlong(id))
}
else if (type == 'ProjectData' || type == 'DatasetData' || type == 'PlateData' || type == 'ScreenData') {
ids <- new (J("java.util.ArrayList"))
ids$add(new (J("java.lang.Long"), .jlong(id)))
if (type == 'ProjectData')
clazz <- J("omero.gateway.model.ProjectData")$class
if (type == 'DatasetData')
clazz <- J("omero.gateway.model.DatasetData")$class
if (type == 'ScreenData')
clazz <- J("omero.gateway.model.ScreenData")$class
if (type == 'PlateData')
clazz <- J("omero.gateway.model.PlateData")$class
tmp <- browse$getHierarchy(ctx, clazz, ids, .jnull(class = 'omero/sys/Parameters'))
it <- tmp$iterator()
object <- .jrcall(it, method = "next")
else if (type == 'PlateData') {
object <- lf$getPlate(ctx, .jlong(id))
}
else if(type == 'WellData') {
ids <- new (J("java.util.ArrayList"))
ids$add(new (J("java.lang.Long"), .jlong(id)))
tmp <- browse$getWells(ctx, ids)
it <- tmp$iterator()
object <- .jrcall(it, method = "next")
object <- lf$getWell(ctx, .jlong(id))
}
else {
object <- browse$findObject(ctx, type, .jlong(id))
Expand Down Expand Up @@ -768,9 +761,8 @@ setMethod(f="searchFor",
jlist <- src$getDataObjects(as.integer(-1), .jnull(class = 'java/lang/Class'))

result <- c()
it <- jlist$iterator()
while(it$hasNext()) {
dataobj <- .jrcall(it, method = "next")
jlistlist <- as.list(jlist)
for (dataobj in jlistlist) {
obj <- OMERO(server=server, dataobject=dataobj)
result <- c(result, cast(obj))
}
Expand All @@ -797,9 +789,8 @@ setMethod(f="getScreens",
jscreens <- browse$getHierarchy(ctx, J("omero.gateway.model.ScreenData")$class, .jlong(-1))

screens <- c()
it <- jscreens$iterator()
while(it$hasNext()) {
jscreen <- .jrcall(it, method = "next")
jscreenslist <- as.list(jscreens)
for (jscreen in jscreenslist) {
if(.jinstanceof(jscreen, J("omero.gateway.model.ScreenData"))) {
screen <- Screen(server=server, dataobject=jscreen)
screens <- c(screens, screen)
Expand Down Expand Up @@ -827,9 +818,8 @@ setMethod(f="getPlates",
jplates <- browse$getHierarchy(ctx, J("omero.gateway.model.PlateData")$class, .jlong(-1))

plates <- c()
it <- jplates$iterator()
while(it$hasNext()) {
jplate <- .jrcall(it, method = "next")
jplateslist <- as.list(jplates)
for (jplate in jplateslist) {
if(.jinstanceof(jplate, J("omero.gateway.model.PlateData"))) {
jscreens <- jplate$getScreens()
if (is.jnull(jscreens)) {
Expand Down Expand Up @@ -861,9 +851,8 @@ setMethod(f="getProjects",
jprojects <- browse$getHierarchy(ctx, J("omero.gateway.model.ProjectData")$class, .jlong(-1))

projects <- c()
it <- jprojects$iterator()
while(it$hasNext()) {
jproject <- .jrcall(it, method = "next")
jprojectslist <- as.list(jprojects)
for (jproject in jprojectslist) {
if(.jinstanceof(jproject, J("omero.gateway.model.ProjectData"))) {
project <- Project(server=server, dataobject=jproject)
projects <- c(projects, project)
Expand Down Expand Up @@ -892,9 +881,8 @@ setMethod(f="getDatasets",
jdatasets <- browse$getHierarchy(ctx, J("omero.gateway.model.DatasetData")$class, .jlong(-1))

datasets <- c()
it <- jdatasets$iterator()
while(it$hasNext()) {
jdataset <- .jrcall(it, method = "next")
jdatasetslist <- as.list(jdatasets)
for (jdataset in jdatasetslist) {
if(.jinstanceof(jdataset, J("omero.gateway.model.DatasetData"))) {
dataset <- Dataset(server=object, dataobject=jdataset)
datasets <- c(datasets, dataset)
Expand Down
5 changes: 2 additions & 3 deletions R/Plate.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ setMethod(
jwells <- browse$getWells(ctx, .jlong(getOMEROID(plate)))

wells <- c()
it <- jwells$iterator()
while(it$hasNext()) {
jwell <- .jrcall(it, method = "next")
jwellslist <- as.list(jwells)
for (jwell in jwellslist) {
if (jwell$asWell()$sizeOfWellSamples() > 0) {
well <- Well(server=server, dataobject=jwell)
wells <- c(wells, well)
Expand Down
14 changes: 6 additions & 8 deletions R/Project.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ setMethod(

jimgs <- fac$getImagesForProjects(ctx, jlist)
result <- c()
it <- jimgs$iterator()
while(it$hasNext()) {
jimg <- .jrcall(it, method = "next")
jimgslist <- as.list(jimgs)
for (jimg in jimgslist) {
img <- Image(server=server, dataobject=jimg)
result <- c(result, img)
}
Expand Down Expand Up @@ -89,12 +88,11 @@ setMethod(f="getDatasets",
jlist <- J("java.util.Collections")$singletonList(id)
jprojects <- fac$getHierarchy(ctx, J("omero.gateway.model.ProjectData")$class, jlist, .jnull())

it <- jprojects$iterator()
jproject <- .jrcall(it, method = "next")
tmplist <- as.list(jprojects)
jproject <- tmplist[[1]]
datasets <- c()
it <- jproject$getDatasets()$iterator()
while(it$hasNext()) {
jdataset <- .jrcall(it, method = "next")
jdatasetlist <- as.list(jproject$getDatasets())
for (jdataset in jdatasetlist) {
if(.jinstanceof(jdataset, J("omero.gateway.model.DatasetData"))) {
dataset <- Dataset(server=object@server, dataobject=jdataset)
datasets <- c(datasets, dataset)
Expand Down
9 changes: 4 additions & 5 deletions R/Screen.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,16 @@ setMethod(
jlist$add(new(J("java.lang.Long"), .jlong(obj$getId())))
set <- browse$loadHierarchy(ctx, J("omero.gateway.model.ScreenData")$class,
jlist, .jnull())
it <- set$iterator()
loaded <- .jrcall(it, method = "next")
tmplist <- as.list(set)
loaded <- tmplist[[1]]
}
else
loaded <- obj

plates <- c()
jplates <- loaded$getPlates()
it <- jplates$iterator()
while(it$hasNext()) {
jplate <- .jrcall(it, method = "next")
jplateslist <- as.list(jplates)
for (jplate in jplateslist) {
plate <- Plate(server = server, dataobject = jplate)
plates <- c(plates, plate)
}
Expand Down
5 changes: 2 additions & 3 deletions R/Well.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ setMethod(
if (missing(fieldIndex)) {
size <- as.integer(jfields$size())
fields <- list(size)
it <- jfields$iterator()
jfieldslist = as.list(jfields)
i <- 1
while(it$hasNext()) {
jfield <- .jrcall(it, method = "next")
for (jfield in jfieldslist) {
jimg <- jfield$getImage()
img <- Image(server=server, dataobject=jimg)
fields[[i]] <-img
Expand Down

0 comments on commit 4d30c82

Please sign in to comment.