Skip to content

[Bioc-devel] New SE or new assay in SE?

3 messages · Laurent Gatto, Hervé Pagès

#
Dear all,

Assume we have a SummarizedExperiment object `se` that contains raw count data, and a method `doProcess` that processes the data to produce a matrix of identical dimensions (for example log-transformation, normalisation, imputation, ...). What are the opinions in favour or against the following two options

- `doProcess(se)` returns a new SE object 
- `doProcess(se)` adds a new assay to se

If you are interested about the broader context about this question, see https://github.com/waldronlab/MultiAssayExperiment/issues/266

Thank you in advance for your input.

Laurent
1 day later
#
On 1/28/20 01:37, Laurent Gatto wrote:
Aren't these are the same?

SE objects are not reference objects i.e. they follow R standard 
copy-on-change semantic. This means that they never get modified **in 
place** (aka they're not "mutable"). So 'doProcess(se)' will always 
return a new object, whatever you do inside the function, that is, even 
if the function modifies 'se' internally e.g. with something like:

   assay(se, "new_assay") <- new_assay

Note that the assay() setter itself like all setters also produces a new 
object. The parser actually replaces the following code

   assay(se, "new_assay") <- new_assay

with

   se <- `assay<-`(se, "new_assay", value=new_assay)

As you can see the previous `se` is replaced with the new one which 
gives the **illusion** of in-place replacement but it's not.

Hope this helps,
H.

  
    
#
Just after I pressed the "Send" button I realized that by returning a 
new SE object you probably meant returning an SE object with only the 
new assay in it. I would favor the other option i.e. 'doProcess(se)' 
adds a new assay to 'se'. I think that's what most workflows based on SE 
objects do.

This doesn't mean that you can't provide a lower-level function that 
returns the transformed data in a "naked" matrix (i.e. not wrapped 
inside an SE). This let's the (more advanced) user decide what they want 
to do with it e.g. they can add it to the original SE:

     assay(se, "normalized") <- normalized_data

or wrap it in its own new SE:

     normalized <- SummarizedExperiment(list(normalized=normalized_data))

H.
On 1/29/20 08:29, Pages, Herve wrote: