Skip to content

Commit

Permalink
Merge pull request #75 from dominikl/add_ns
Browse files Browse the repository at this point in the history
Set namespace of attached dataframe
  • Loading branch information
jburel authored Jan 16, 2020
2 parents babf551 + 4018f14 commit 6276b8d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
11 changes: 8 additions & 3 deletions R/OMERO.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ setGeneric(
#' @param omero The OME object
#' @param df The dataframe
#' @param name An optional name
#' @param ns An optional namespace for the file annotation
#' @return The OME object
#' @export attachDataframe
#' @exportMethod attachDataframe
Expand All @@ -116,7 +117,7 @@ setGeneric(
#' }
setGeneric(
name = "attachDataframe",
def = function(omero, df, name="R Dataframe")
def = function(omero, df, name="R Dataframe", ns=NA)
{
standardGeneric("attachDataframe")
}
Expand Down Expand Up @@ -340,13 +341,14 @@ setMethod(
#' @param omero The OME object
#' @param df The dataframe
#' @param name An optional name
#' @param ns An optional namespace for the file annotation
#' @return The OME object
#' @export attachDataframe
#' @exportMethod attachDataframe
setMethod(
f = "attachDataframe",
signature = "OMERO",
definition = function(omero, df, name)
definition = function(omero, df, name, ns=NA)
{
if(!is.data.frame(df)) {
return(FALSE)
Expand Down Expand Up @@ -402,7 +404,10 @@ setMethod(
ctx <- getContext(server)
fac <- gateway$getFacility(TablesFacility$class)

tabledata <- fac$addTable(ctx, omero@dataobject, name, table)
if (!is.na(ns))
tabledata <- fac$addTable(ctx, omero@dataobject, name, as.character(ns), table)
else
tabledata <- fac$addTable(ctx, omero@dataobject, name, table)

return(omero)
}
Expand Down
41 changes: 41 additions & 0 deletions examples/AddTable.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
###
# Add a dataframe which is accessible to the OMERO.web client.
#
# This example uses the attachDataframe method again (like the AddData.R example),
# but this time an 'Image' column with the image Ids is added and the dataframe
# gets attached to a dataset with the particular namespace
# 'openmicroscopy.org/omero/bulk_annotations'. This way the entries in the dataframe
# will be picked up by the OMERO.web client and shown on the 'Tables' tab of the
# images.
###

library(romero.gateway)

# Connect to server
server <- OMEROServer(host = "localhost", username = "xx", password = "xx", port = as.integer(4064))server <- connect(server)
server <- connect(server)

# Load a dataset
datasetId <- 1
dataset <- loadObject(server, "DatasetData", datasetId)

# Create a dataframe with one row per image, like:
# Image, SomeValue, AnotherValue
# 1, 'Some value', 'Another Value'
# ...
imgIds <- c()
values1 <- c()
values2 <- c()
for (img in getImages(dataset)) {
imgIds <- c(imgIds, getOMEROID(img))
values1 <- c(values1, paste("Some value for image",img@dataobject$getName()))
values2 <- c(values2, paste("Another value for image",img@dataobject$getName()))
}

# Attach it as dataframe with namespace 'openmicroscopy.org/omero/bulk_annotations'
# to make it available to OMERO.web
df <- data.frame(Image = imgIds, SomeValue = values1, AnotherValue = values2)
attachDataframe(dataset, df, "Example data", ns = "openmicroscopy.org/omero/bulk_annotations")

# Go to OMERO.web client, select an image and you should see its values
# in the 'Tables' tab.
5 changes: 4 additions & 1 deletion man/attachDataframe-OMERO-method.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/attachDataframe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6276b8d

Please sign in to comment.