Accessor functions to work with MoleculeExperiment objects
Usage
# S4 method for MoleculeExperiment
molecules(object, assayName = NULL, flatten = FALSE)
# S4 method for MoleculeExperiment
boundaries(object, assayName = NULL, flatten = FALSE)
# S4 method for MoleculeExperiment
features(object, assayName = NULL)
# S4 method for MoleculeExperiment
segmentIDs(object, assayName = NULL)
# S4 method for MoleculeExperiment
molecules(object, assayName = NULL) <- value
# S4 method for MoleculeExperiment
boundaries(object, assayName = NULL) <- value
Arguments
- object
The MoleculeExperiment to access.
- assayName
Character string specifying the name of the assay from which to retrieve or set information in the slot of interest.
- flatten
Logical value specifying whether to flatten the ME list into a data.frame or not. Defaults to FALSE.
- value
New value to be added to the slot and assay of interest.
getters
Accessor functions to get data from the MoleculeExperiment object. These include:
molecules() to retrieve information from the molecules slot.
boundaries() to retrieve information from the boundaries slot.
features() to retrieve feature names from the molecules slot.
segmentIDs() to retrieve segment ids from the boundaries slot.
setters
The molecules<-
setter accesses the molecules slot, whereas the boundaries
slot can be accessed with boundaries<-
.
Examples
# get example data
repoDir <- system.file("extdata", package = "MoleculeExperiment")
repoDir <- paste0(repoDir, "/xenium_V1_FF_Mouse_Brain")
me <- readXenium(repoDir,
keepCols = "essential",
addBoundaries = "cell"
)
# get insight into MoleculeExperiment object (e.g., see assay names)
me
#> MoleculeExperiment class
#>
#> molecules slot (1): detected
#> - detected:
#> samples (2): sample1 sample2
#> -- sample1:
#> ---- features (137): 2010300C02Rik Acsbg1 ... Zfp536 Zfpm2
#> ---- molecules (962)
#> ---- location range: [4900,4919.98] x [6400.02,6420]
#> -- sample2:
#> ---- features (143): 2010300C02Rik Acsbg1 ... Zfp536 Zfpm2
#> ---- molecules (777)
#> ---- location range: [4900.01,4919.98] x [6400.16,6419.97]
#>
#>
#> boundaries slot (1): cell
#> - cell:
#> samples (2): sample1 sample2
#> -- sample1:
#> ---- segments (5): 67500 67512 67515 67521 67527
#> -- sample2:
#> ---- segments (9): 65043 65044 ... 65070 65071
# get insight into molecules slot (e.g., see the assay names)
showMolecules(me)
#> List of 1
#> $ detected:List of 2
#> ..$ sample1:List of 137
#> .. ..$ 2010300C02Rik : tibble [11 × 2] (S3: tbl_df/tbl/data.frame)
#> .. ..$ Acsbg1 : tibble [6 × 2] (S3: tbl_df/tbl/data.frame)
#> .. .. [list output truncated]
#> ..$ sample2:List of 143
#> .. ..$ 2010300C02Rik: tibble [9 × 2] (S3: tbl_df/tbl/data.frame)
#> .. ..$ Acsbg1 : tibble [10 × 2] (S3: tbl_df/tbl/data.frame)
#> .. .. [list output truncated]
# for developers, use molecules() getter
# expect a large output from call below
# molecules(me, assayName = "detected")
# alternatively, return rectangular data structure with flatten = TRUE
molecules(me, assayName = "detected", flatten = TRUE)
#> # A tibble: 1,739 × 4
#> x_location y_location feature_id sample_id
#> * <dbl> <dbl> <chr> <chr>
#> 1 4918. 6411. 2010300C02Rik sample1
#> 2 4901. 6417. 2010300C02Rik sample1
#> 3 4901. 6417. 2010300C02Rik sample1
#> 4 4910. 6417. 2010300C02Rik sample1
#> 5 4908. 6413. 2010300C02Rik sample1
#> 6 4911. 6407. 2010300C02Rik sample1
#> 7 4915. 6411. 2010300C02Rik sample1
#> 8 4916. 6412. 2010300C02Rik sample1
#> 9 4901. 6415. 2010300C02Rik sample1
#> 10 4906. 6417. 2010300C02Rik sample1
#> # ℹ 1,729 more rows
# get insight into boundaries slot (e.g., see the assay names)
showBoundaries(me)
#> List of 1
#> $ cell:List of 2
#> ..$ sample1:List of 5
#> .. ..$ 67500: tibble [13 × 2] (S3: tbl_df/tbl/data.frame)
#> .. ..$ 67512: tibble [13 × 2] (S3: tbl_df/tbl/data.frame)
#> .. .. [list output truncated]
#> ..$ sample2:List of 9
#> .. ..$ 65043: tibble [13 × 2] (S3: tbl_df/tbl/data.frame)
#> .. ..$ 65044: tibble [13 × 2] (S3: tbl_df/tbl/data.frame)
#> .. .. [list output truncated]
# for developers, use boundaries() getter
# expect a large output from call below
# boundaries(me, assayName = "cell")
# alternatively, return rectangular data structure with flatten = TRUE
boundaries(me, assayName = "cell", flatten = TRUE)
#> # A tibble: 182 × 4
#> x_location y_location segment_id sample_id
#> * <dbl> <dbl> <chr> <chr>
#> 1 4905. 6400. 67500 sample1
#> 2 4899. 6401. 67500 sample1
#> 3 4894. 6408. 67500 sample1
#> 4 4890. 6418. 67500 sample1
#> 5 4887. 6423. 67500 sample1
#> 6 4887. 6425. 67500 sample1
#> 7 4890. 6427. 67500 sample1
#> 8 4891. 6427. 67500 sample1
#> 9 4894. 6426. 67500 sample1
#> 10 4908. 6421. 67500 sample1
#> # ℹ 172 more rows
# features() getter
features(me, assayName = "detected")
#> $sample1
#> [1] "2010300C02Rik" "Acsbg1" "Adamts2"
#> [4] "Adamtsl1" "Angpt1" "Aqp4"
#> [7] "Arc" "Arhgap12" "Arhgef28"
#> [10] "BLANK_0022" "BLANK_0414" "BLANK_0424"
#> [13] "Bdnf" "Bhlhe40" "Btbd11"
#> [16] "Cabp7" "Calb1" "Calb2"
#> [19] "Car4" "Cbln4" "Ccn2"
#> [22] "Cdh20" "Cdh4" "Cdh6"
#> [25] "Cdh9" "Chrm2" "Clmn"
#> [28] "Cntn6" "Cntnap5b" "Cplx3"
#> [31] "Cpne4" "Cpne6" "Crh"
#> [34] "Cux2" "Dkk3" "Dner"
#> [37] "Dpy19l1" "Epha4" "Fhod3"
#> [40] "Fos" "Gad1" "Galnt14"
#> [43] "Garnl3" "Gfra2" "Gjc3"
#> [46] "Gli3" "Gng12" "Gsg1l"
#> [49] "Gucy1a1" "Hat1" "Hpcal1"
#> [52] "Id2" "Igf2" "Igfbp4"
#> [55] "Igfbp5" "Igfbp6" "Igsf21"
#> [58] "Inpp4b" "Kcnh5" "Kctd12"
#> [61] "Lamp5" "Lypd6" "Lyz2"
#> [64] "Mapk4" "Meis2" "Myl4"
#> [67] "Myo16" "Ndst3" "Necab1"
#> [70] "NegControlProbe_00031" "NegControlProbe_00062" "Nell1"
#> [73] "Neto2" "Neurod6" "Npnt"
#> [76] "Nrep" "Nrn1" "Nrp2"
#> [79] "Ntsr2" "Nwd2" "Opalin"
#> [82] "Orai2" "Pde11a" "Pde7b"
#> [85] "Pdzd2" "Pdzrn3" "Penk"
#> [88] "Pip5k1b" "Plch1" "Plcxd2"
#> [91] "Plekha2" "Pou3f1" "Ppp1r1b"
#> [94] "Prdm8" "Prox1" "Prr16"
#> [97] "Pvalb" "Rasgrf2" "Rasl10a"
#> [100] "Rbp4" "Rfx4" "Rims3"
#> [103] "Rmst" "Ror1" "Rorb"
#> [106] "Rprm" "Rspo1" "Satb2"
#> [109] "Sema3a" "Sema6a" "Shisa6"
#> [112] "Sipa1l3" "Slc17a6" "Slc17a7"
#> [115] "Slc39a12" "Slit2" "Sncg"
#> [118] "Sorcs3" "Sox10" "Sox11"
#> [121] "Spi1" "Strip2" "Syndig1"
#> [124] "Syt2" "Tanc1" "Thsd7a"
#> [127] "Tle4" "Tmem132d" "Tox"
#> [130] "Trpc4" "Unc13c" "Vat1l"
#> [133] "Vip" "Vwc2l" "Wfs1"
#> [136] "Zfp536" "Zfpm2"
#>
#> $sample2
#> [1] "2010300C02Rik" "Acsbg1" "Adgrl4" "Aldh1a2"
#> [5] "Angpt1" "Aqp4" "Arc" "Arhgap12"
#> [9] "Arhgef28" "BLANK_0077" "BLANK_0120" "BLANK_0129"
#> [13] "BLANK_0471" "Bdnf" "Bhlhe22" "Bhlhe40"
#> [17] "Btbd11" "Calb1" "Car4" "Cbln4"
#> [21] "Cd24a" "Cd93" "Cdh4" "Cdh6"
#> [25] "Chrm2" "Clmn" "Cntnap5b" "Cobll1"
#> [29] "Col6a1" "Cort" "Cplx3" "Cpne4"
#> [33] "Cpne6" "Cpne8" "Cux2" "Dkk3"
#> [37] "Dner" "Dpy19l1" "Ebf3" "Epha4"
#> [41] "Eya4" "Fgd5" "Fhod3" "Fibcd1"
#> [45] "Fn1" "Fos" "Gadd45a" "Galnt14"
#> [49] "Gfra2" "Gjc3" "Gli3" "Gm19410"
#> [53] "Gng12" "Gsg1l" "Gucy1a1" "Hapln1"
#> [57] "Hat1" "Hpcal1" "Htr1f" "Id2"
#> [61] "Igf2" "Igfbp4" "Igfbp5" "Igfbp6"
#> [65] "Igsf21" "Inpp4b" "Kcnh5" "Kctd12"
#> [69] "Lamp5" "Ly6a" "Lyz2" "Mapk4"
#> [73] "Mdga1" "Meis2" "Myo16" "Ndst3"
#> [77] "Necab1" "Nell1" "Neurod6" "Npnt"
#> [81] "Npy2r" "Nrep" "Nrn1" "Nrp2"
#> [85] "Ntsr2" "Nwd2" "Nxph3" "Opalin"
#> [89] "Opn3" "Orai2" "Parm1" "Pde7b"
#> [93] "Pdgfra" "Pdzd2" "Pdzrn3" "Pecam1"
#> [97] "Penk" "Pglyrp1" "Pip5k1b" "Plcxd2"
#> [101] "Plcxd3" "Plekha2" "Pou3f1" "Ppp1r1b"
#> [105] "Prox1" "Pthlh" "Rasgrf2" "Rasl10a"
#> [109] "Rbp4" "Rfx4" "Rims3" "Rmst"
#> [113] "Rorb" "Rprm" "Rspo1" "Satb2"
#> [117] "Sema3a" "Sema3e" "Sema6a" "Sipa1l3"
#> [121] "Slc17a7" "Slc39a12" "Slit2" "Sorcs3"
#> [125] "Sox11" "Sox17" "Spp1" "Strip2"
#> [129] "Syndig1" "Syt17" "Syt6" "Tanc1"
#> [133] "Tle4" "Tmem132d" "Tmem255a" "Tox"
#> [137] "Trem2" "Trp73" "Trpc4" "Vat1l"
#> [141] "Wfs1" "Zfp536" "Zfpm2"
#>
# segmentIDs() getter
segmentIDs(me, assayName = "cell")
#> $sample1
#> [1] "67500" "67512" "67515" "67521" "67527"
#>
#> $sample2
#> [1] "65043" "65044" "65051" "65055" "65063" "65064" "65067" "65070" "65071"
#>
# setter example
# read in and standardise nucleus boundaries too
nucleiMEList <- readBoundaries(
dataDir = repoDir,
pattern = "nucleus_boundaries.csv",
segmentIDCol = "cell_id",
xCol = "vertex_x",
yCol = "vertex_y",
keepCols = "essential",
boundariesAssay = "nucleus",
scaleFactorVector = 1
)
# use `boundaries<-` setter to add nucleus boundaries to the boundaries slot
boundaries(me, assayName = "nucleus") <- nucleiMEList
me
#> MoleculeExperiment class
#>
#> molecules slot (1): detected
#> - detected:
#> samples (2): sample1 sample2
#> -- sample1:
#> ---- features (137): 2010300C02Rik Acsbg1 ... Zfp536 Zfpm2
#> ---- molecules (962)
#> ---- location range: [4900,4919.98] x [6400.02,6420]
#> -- sample2:
#> ---- features (143): 2010300C02Rik Acsbg1 ... Zfp536 Zfpm2
#> ---- molecules (777)
#> ---- location range: [4900.01,4919.98] x [6400.16,6419.97]
#>
#>
#> boundaries slot (2): cell nucleus
#> - cell:
#> samples (2): sample1 sample2
#> -- sample1:
#> ---- segments (5): 67500 67512 67515 67521 67527
#> -- sample2:
#> ---- segments (9): 65043 65044 ... 65070 65071
#> - nucleus:
#> samples (2): sample1 sample2
#> -- sample1:
#> ---- segments (5): 67500 67512 67515 67521 67527
#> -- sample2:
#> ---- segments (5): 65044 65051 65055 65063 65064