[Bioc-devel] How to set dimnames inside constructor function?

Hervé Pagès hp@ge@ @end|ng |rom |redhutch@org
Thu Jun 25 21:42:37 CEST 2020


Hi Muad,

I'm not able to reproduce this. With a naked 'count' matrix:

   library(SummarizedExperiment)
   count <- matrix(1:15, ncol=3)
   row_data <- DataFrame(stuff=runif(5))

   se1 <- SummarizedExperiment(list(count=count), rowData=row_data)
   dimnames(se1) <- list(sprintf("Gene%04d", 1:5), sprintf("ID%03d", 1:3))
   dimnames(se1)
   # [[1]]
   # [1] "Gene0001" "Gene0002" "Gene0003" "Gene0004" "Gene0005"
   #
   # [[2]]
   # [1] "ID001" "ID002" "ID003"

With dimnames on the 'count' matrix:

   dimnames(count) <- list(LETTERS[1:5], LETTERS[1:3])
   se2 <- SummarizedExperiment(list(count=count), rowData=row_data)
   dimnames(se2) <- list(sprintf("Gene%04d", 1:5), sprintf("ID%03d", 1:3))
   dimnames(se2)
   # [[1]]
   # [1] "Gene0001" "Gene0002" "Gene0003" "Gene0004" "Gene0005"
   #
   # [[2]]
   # [1] "ID001" "ID002" "ID003"

So I don't know how/when you get the error you reported. If the error 
occurs in your .CalciumExperiment() internal function I would need to 
have access to it in order to understand why it fails. Note that if the 
function calls the assay() or assays() setter at some point then it 
probably needs to use 'withDimnames=FALSE', as indicated by the error 
message.

Thanks,
H.

 > sessionInfo()
R version 4.0.0 Patched (2020-04-27 r78316)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.6 LTS

Matrix products: default
BLAS:   /home/hpages/R/R-4.0.r78316/lib/libRblas.so
LAPACK: /home/hpages/R/R-4.0.r78316/lib/libRlapack.so

locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] parallel  stats4    stats     graphics  grDevices utils     datasets
[8] methods   base

other attached packages:
  [1] SummarizedExperiment_1.19.5 DelayedArray_0.15.5
  [3] matrixStats_0.56.0          Matrix_1.2-18
  [5] Biobase_2.49.0              GenomicRanges_1.41.5
  [7] GenomeInfoDb_1.25.4         IRanges_2.23.10
  [9] S4Vectors_0.27.12           BiocGenerics_0.35.4

loaded via a namespace (and not attached):
[1] lattice_0.20-41        bitops_1.0-6           grid_4.0.0
[4] zlibbioc_1.35.0        XVector_0.29.3         tools_4.0.0
[7] RCurl_1.98-1.2         compiler_4.0.0         GenomeInfoDbData_1.2.3


On 6/18/20 02:17, Muad Abd El Hay wrote:
> Hello everyone,
> 
> This is my first attempt at writing a package (wrote it in S3 and nowHi 
> porting it to S4). So it might be a trivial question.
> 
> I am trying to extend the SummarizedExperiment object for calcium
> imaging data (no gene names as features). Features/rownames are the
> number of the frames and colnames are the cells/ROIs.
> 
> Inside the constructor function, I wanted to set the rownames and
> colnames as below:
> 
> ```R
>     se <- SummarizedExperiment(list(raw=raw),
>                                rowData = DataFrame(time = time),
>                                ...)
>     dimnames(se) <- list(paste("f", 1:nrow(se), sep=""),
>                          paste("name", 1:ncol(se), sep="_"))
>     .CalciumExperiment(se)
> ```
> 
> But I keep getting the following error:
> 
> ```R
> Error in `assays<-`(`*tmp*`, withDimnames = withDimnames, ..., value =
> `*vtmp*`) :
>     please use 'assay(x, withDimnames=FALSE)) <- value' or 'assays(x,
>     withDimnames=FALSE)) <- value' when the dimnames on the supplied
>     assay(s) are not identical to the dimnames on CalciumExperiment
> object
>     'x'
> ```
> 
> I also tried using `rownames(se)`and `colnames(se)`with the same error.
> Setting the `dimnames`, `colnames`, or `rownames` on the `raw` matrix
> beforehand also did not work.
> 
> Am I missing something fundamental here?
> 
> Thank you in advance!
> Best wishes,
> Muad Abd El Hay
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> Bioc-devel using r-project.org mailing list
> https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_bioc-2Ddevel&d=DwICAg&c=eRAMFD45gAfqt84VtBcfhQ&r=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA&m=FNTL6nWceeRQEmN0D59W-TTsONVBwTUFGHIAnpeD31U&s=kxDXq2jEie3hJB-VfrLFyIhhjHx9VyV27-HvJQ7i1VU&e=
> 

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages using fredhutch.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the Bioc-devel mailing list