Skip to contents

Subset a giotto object with [[ to disassemble it into a list of Giotto S4 subobjects. If drop is FALSE, the selected subobjects will be reassembled into a new giotto object. Note that indexing within the [[ filters for only those subobjects that have those attributes. This may remove some unexpected information. For specifically splitting the giotto object by spatial unit and/or feature type while keeping all expected information, use sliceGiotto()

Usage

# S4 method for class 'giotto,missing,missing'
x[[spat_unit = NULL, feat_type = NULL, drop = TRUE, ...]]

# S4 method for class 'giotto,character,missing'
x[[i, spat_unit = NULL, feat_type = NULL, drop = TRUE, ...]]

# S4 method for class 'giotto,missing,character'
x[[j, spat_unit = NULL, feat_type = NULL, drop = TRUE, ...]]

# S4 method for class 'giotto,character,character'
x[[i, j, spat_unit = NULL, feat_type = NULL, drop = TRUE, ...]]

Arguments

x

giotto object

spat_unit

spatial unit (e.g. "cell")

feat_type

feature type to use (e.g. "rna", "protein")

drop

logical. Default = TRUE

...

additional arguments

i

character. Indicates the slot name

j

character. Indicates the subobject name

Value

giotto subobject

Examples

g <- GiottoData::loadGiottoMini("vizgen")
#> 1. read Giotto object
#> 2. read Giotto feature information
#> 3. read Giotto spatial information
#> 3.1 read Giotto spatial shape information
#> 3.2 read Giotto spatial centroid information
#> 3.3 read Giotto spatial overlap information
#> 4. read Giotto image information
#> python already initialized in this session
#>  active environment : 'giotto_env'
#>  python version : 3.10
#> checking default envname 'giotto_env'
#> a system default python environment was found
#> Using python path:
#>  "/usr/share/miniconda/envs/giotto_env/bin/python"
force(g)
#> An object of class giotto 
#> >Active spat_unit:  z0 
#> >Active feat_type:  rna 
#> dimensions    : 337, 498 (features, cells)
#> [SUBCELLULAR INFO]
#> polygons      : z0 z1 aggregate 
#> features      : rna 
#> [AGGREGATE INFO]
#> expression -----------------------
#>   [z0][rna] raw
#>   [z1][rna] raw
#>   [aggregate][rna] raw normalized scaled pearson
#> spatial locations ----------------
#>   [z0] raw
#>   [z1] raw
#>   [aggregate] raw
#> spatial networks -----------------
#>   [aggregate] Delaunay_network kNN_network
#> spatial enrichments --------------
#>   [aggregate][rna] cluster_metagene
#> dim reduction --------------------
#>   [aggregate][rna] pca umap tsne
#> nearest neighbor networks --------
#>   [aggregate][rna] sNN.pca
#> attached images ------------------
#> images      : 4 items...
#> 
#> 
#> Use objHistory() to see steps and params used

# return as lists of subobjects with drop = TRUE (default)
g[[, "raw"]]
#> [[1]]
#> An object of class spatLocsObj : "raw"
#> spat_unit : "z0"
#> provenance: z0 
#> dimensions: 498 3 
#> preview   :
#>       sdimx     sdimy                                 cell_ID
#>       <num>     <num>                                  <char>
#> 1: 6405.067 -4780.499  40951783403982682273285375368232495429
#> 2: 6426.020 -4972.519 240649020551054330404932383065726870513
#> 3: 6428.456 -4799.158 274176126496863898679934791272921588227
#> 
#> ranges:
#>         sdimx     sdimy
#> [1,] 6402.438 -5146.726
#> [2,] 6899.203 -4700.157
#> 
#> 
#> [[2]]
#> An object of class spatLocsObj : "raw"
#> spat_unit : "z1"
#> provenance: z1 
#> dimensions: 504 3 
#> preview   :
#>       sdimx     sdimy                                 cell_ID
#>       <num>     <num>                                  <char>
#> 1: 6404.014 -4779.625  40951783403982682273285375368232495429
#> 2: 6408.296 -4970.794  17685062374745280598492217386845129350
#> 3: 6401.148 -4991.061 223553142498364321238189328942498473503
#> 
#> ranges:
#>         sdimx     sdimy
#> [1,] 6401.148 -5147.193
#> [2,] 6899.323 -4700.410
#> 
#> 
#> [[3]]
#> An object of class spatLocsObj : "raw"
#> spat_unit : "aggregate"
#> provenance: z0 z1 
#> dimensions: 462 3 
#> preview   :
#>       sdimx     sdimy                                 cell_ID
#>       <num>     <num>                                  <char>
#> 1: 6637.881 -5140.465 100210519278873141813371229408401071444
#> 2: 6471.978 -4883.541 101161259912191124732236989250178928032
#> 3: 6801.610 -4968.685 101488859781016188084173008420811094152
#> 
#> ranges:
#>         sdimx     sdimy
#> [1,] 6401.412 -5146.747
#> [2,] 6899.108 -4700.326
#> 
#> 
#> [[4]]
#> An object of class exprObj : "raw"
#> spat_unit : "z0"
#> feat_type : "rna"
#> provenance: z0 
#> 
#> contains:
#> 337 x 498 sparse Matrix of class "dgCMatrix"
#>                                         
#> Mlc1   . . . . . . . .  . . . . . ......
#> Gprc5b . . 1 . 1 . . .  1 . 2 . . ......
#> Gfap   . . . 1 1 . . . 27 . . . . ......
#> 
#>  ........suppressing 485 columns and 331 rows in show(); maybe adjust options(max.print=, width=)
#>                                           
#> Adgrf4    . . . . . . . . . . . . . ......
#> Epha2     . . . . . . . . . . . . . ......
#> Blank-139 . . . . . . . . . . . . . ......
#> 
#>  First four colnames:
#>  40951783403982682273285375368232495429
#>  240649020551054330404932383065726870513
#>  274176126496863898679934791272921588227
#>  323754550002953984063006506310071917306 
#> 
#> [[5]]
#> An object of class exprObj : "raw"
#> spat_unit : "z1"
#> feat_type : "rna"
#> provenance: z1 
#> 
#> contains:
#> 337 x 504 sparse Matrix of class "dgCMatrix"
#>                                         
#> Mlc1   . . . . . . . . . . .  1 . ......
#> Gprc5b . . . . . . . 2 . . .  1 . ......
#> Gfap   . 3 . 2 . 1 4 . . . . 18 . ......
#> 
#>  ........suppressing 491 columns and 331 rows in show(); maybe adjust options(max.print=, width=)
#>                                           
#> Adgrf4    . . . . . . . . . . . . . ......
#> Epha2     . . . . . . . . . . . . . ......
#> Blank-139 . . . . . . . . . . . . . ......
#> 
#>  First four colnames:
#>  40951783403982682273285375368232495429
#>  17685062374745280598492217386845129350
#>  223553142498364321238189328942498473503
#>  240649020551054330404932383065726870513 
#> 
#> [[6]]
#> An object of class exprObj : "raw"
#> spat_unit : "aggregate"
#> feat_type : "rna"
#> provenance: z0 z1 
#> 
#> contains:
#> 337 x 462 sparse Matrix of class "dgCMatrix"
#>                                         
#> Mlc1   . . . . . .  1 . . 1 . . . ......
#> Gprc5b . 1 . 3 . .  2 . 4 2 . 1 . ......
#> Gfap   2 . 2 1 . . 45 . 1 1 . . . ......
#> 
#>  ........suppressing 449 columns and 331 rows in show(); maybe adjust options(max.print=, width=)
#>                                           
#> Adgrf4    . . . . . . . . . . . . . ......
#> Epha2     . . . . . . . . . . . . . ......
#> Blank-139 . . . . . . . . . . . . . ......
#> 
#>  First four colnames:
#>  240649020551054330404932383065726870513
#>  274176126496863898679934791272921588227
#>  323754550002953984063006506310071917306
#>  87260224659312905497866017323180367450 
#> 
g[["expression", spat_unit = "aggregate"]]
#> [[1]]
#> An object of class exprObj : "raw"
#> spat_unit : "aggregate"
#> feat_type : "rna"
#> provenance: z0 z1 
#> 
#> contains:
#> 337 x 462 sparse Matrix of class "dgCMatrix"
#>                                         
#> Mlc1   . . . . . .  1 . . 1 . . . ......
#> Gprc5b . 1 . 3 . .  2 . 4 2 . 1 . ......
#> Gfap   2 . 2 1 . . 45 . 1 1 . . . ......
#> 
#>  ........suppressing 449 columns and 331 rows in show(); maybe adjust options(max.print=, width=)
#>                                           
#> Adgrf4    . . . . . . . . . . . . . ......
#> Epha2     . . . . . . . . . . . . . ......
#> Blank-139 . . . . . . . . . . . . . ......
#> 
#>  First four colnames:
#>  240649020551054330404932383065726870513
#>  274176126496863898679934791272921588227
#>  323754550002953984063006506310071917306
#>  87260224659312905497866017323180367450 
#> 
#> [[2]]
#> An object of class exprObj : "normalized"
#> spat_unit : "aggregate"
#> feat_type : "rna"
#> provenance: z0 z1 
#> 
#> contains:
#> 337 x 462 sparse Matrix of class "dgCMatrix"
#>                                                                                          
#> Mlc1    .       .        .        .        . .  5.291601 . .        5.821597 . .        .
#> Gprc5b  .       6.398031 .        7.454658 . .  6.273066 . 7.680054 6.808785 . 5.082989 .
#> Gfap   10.48137 .        7.901442 5.886051 . . 10.746982 . 5.701006 5.821597 . .        .
#>              
#> Mlc1   ......
#> Gprc5b ......
#> Gfap   ......
#> 
#>  ........suppressing 449 columns and 331 rows in show(); maybe adjust options(max.print=, width=)
#>                                           
#> Adgrf4    . . . . . . . . . . . . . ......
#> Epha2     . . . . . . . . . . . . . ......
#> Blank-139 . . . . . . . . . . . . . ......
#> 
#>  First four colnames:
#>  240649020551054330404932383065726870513
#>  274176126496863898679934791272921588227
#>  323754550002953984063006506310071917306
#>  87260224659312905497866017323180367450 
#> 
#> [[3]]
#> An object of class exprObj : "scaled"
#> spat_unit : "aggregate"
#> feat_type : "rna"
#> provenance: z0 z1 
#> 
#> contains:
#>   Provenance: z0 z1
#> 337 x 462 dense matrix of class "dgeMatrix"
#> 
#>                  [,1]       [,2]       [,3]       [,4]       [,5]       [,6]
#> Mlc1      -0.51096453 -0.4718074 -0.3859440 -0.4383384 -0.3827836 -0.3152653
#> Gprc5b    -0.97549417  1.6804631 -0.5746594  1.2850731 -0.5794505 -0.4583322
#> Gfap       5.46807822 -0.7367558  1.3902670  0.5804327 -0.6152080 -0.4843442
#> Ednrb      9.34063752  3.7384966  2.5412669  1.5736461  2.8570134 -0.2823656
#> Sox9      -0.59906517 -0.5143258  2.4318798 -0.4671338 -0.4200826 -0.3423988
#> Aqp4      -0.64987710 -0.5388482  2.0705344  1.0223253  1.9919249 -0.3580479
#> Gjc3       0.02982685  5.0161718 -0.1662473 -0.2615829 -0.1538300 -0.1487112
#> Sox8      -0.47826316  3.5325216  2.5366322 -0.4276501 -0.3689389 -0.3051939
#> Ntsr2      6.06580557  2.6068464  1.7367543  1.1330202 -0.6019376 -0.4746906
#> Adcyap1r1 -2.17060870  0.8282834  0.8492637 -0.9807865 -1.0854235 -0.8264062
#>                [,7]       [,8]       [,9]      [,10]
#> Mlc1       1.546533 -0.3614888 -0.5076115  2.5761153
#> Gprc5b     1.235844 -0.5485629  1.6600474  2.0842933
#> Gfap       1.944454 -0.5825762  0.6870865  1.1388811
#> Ednrb      1.705886 -0.3184691 -0.4650954  3.3799076
#> Sox9       1.888188 -0.3969684 -0.5426758  2.2576086
#> Aqp4       2.116905 -0.4174313  1.7014365  2.5684989
#> Gjc3       4.531175 -0.1437027 -0.2923745 -0.2723587
#> Sox8       1.695510 -0.3483194 -0.4945962  2.8035269
#> Ntsr2      1.406620 -0.5699532  1.7102932  2.7162251
#> Adcyap1r1 -1.160557 -1.0298563  0.3757894  0.7075043
#> 
#>  First four colnames:
#>  240649020551054330404932383065726870513
#>  274176126496863898679934791272921588227
#>  323754550002953984063006506310071917306
#>  87260224659312905497866017323180367450 
#> 
#> [[4]]
#> An object of class exprObj : "pearson"
#> spat_unit : "aggregate"
#> feat_type : "rna"
#> provenance: z0 z1 
#> 
#> contains:
#>   Provenance: z0 z1
#> 337 x 462 dense matrix of class "dgeMatrix"
#> 
#>                 [,1]       [,2]       [,3]       [,4]       [,5]       [,6]
#> Mlc1      -0.1671233 -0.4887705 -0.4090814 -0.5848627 -0.3515289 -0.3681237
#> Gprc5b    -0.2390668  0.7264405 -0.5847568  2.7313611 -0.5026041 -0.5262978
#> Gfap       4.1820021 -1.2576333  0.8204327 -0.8491028 -0.9074561 -0.9499730
#> Ednrb      6.2681837  8.3133382  2.2399348  1.2854419  2.7238921 -0.3428383
#> Sox9      -0.1862585 -0.5445941  3.9225159 -0.6515799 -0.3917326 -0.4102193
#> Aqp4      -0.2836816 -0.8280158  2.1766489  0.0105117  1.0752709 -0.6242357
#> Gjc3      -0.1409193  4.4308083 -0.3450090 -0.4933833 -0.2964520 -0.3104520
#> Sox8      -0.1577216  6.0278079  2.2000617 -0.5520553 -0.3317706 -0.3474348
#> Ntsr2      5.2211595 12.2321831  2.5314771  1.9147811 -0.7517658 -0.7870865
#> Adcyap1r1 -0.3682081 -0.1508472  0.2046257 -1.2808439 -0.7730688 -0.8093776
#>                 [,7]       [,8]       [,9]      [,10]
#> Mlc1       0.6581840 -0.4139145 -0.6241861  1.0672640
#> Gprc5b     0.8940330 -0.5916531  3.5614736  1.4696046
#> Gfap      21.4941853 -1.0670577 -0.9900047 -0.8977729
#> Ednrb      0.8099276 -0.3854930 -0.5814107  3.0206482
#> Sox9       2.9072540 -0.4612263 -0.6953491  0.8272268
#> Aqp4       6.8660546 -0.7016483  1.7534888  1.9205849
#> Gjc3      12.4888269 -0.3490872 -0.5265923 -0.5046983
#> Sox8       0.7812349 -0.3906598 -0.5891883  1.2004721
#> Ntsr2      2.2943725 -0.8844258  6.0655865  8.7636477
#> Adcyap1r1 -1.5740789 -0.9094310 -0.6471715 -0.5594111
#> 
#>  First four colnames:
#>  240649020551054330404932383065726870513
#>  274176126496863898679934791272921588227
#>  323754550002953984063006506310071917306
#>  87260224659312905497866017323180367450 
#> 

# return as a subset giotto object with drop = FALSE
g[[, "raw", drop = FALSE]]
#> An object of class giotto 
#> >Active spat_unit:  z0 
#> >Active feat_type:  rna 
#> dimensions    : 337, 498 (features, cells)
#> [SUBCELLULAR INFO]
#> [AGGREGATE INFO]
#> expression -----------------------
#>   [z0][rna] raw
#>   [z1][rna] raw
#>   [aggregate][rna] raw
#> spatial locations ----------------
#>   [z0] raw
#>   [z1] raw
#>   [aggregate] raw
#> 
#> 
#> Use objHistory() to see steps and params used
g[[spat_unit = "aggregate", drop = FALSE]]
#> An object of class giotto 
#> >Active spat_unit:  aggregate 
#> >Active feat_type:  rna 
#> dimensions    : 337, 462 (features, cells)
#> [SUBCELLULAR INFO]
#> polygons      : aggregate 
#> [AGGREGATE INFO]
#> expression -----------------------
#>   [aggregate][rna] raw normalized scaled pearson
#> spatial locations ----------------
#>   [aggregate] raw
#> spatial networks -----------------
#>   [aggregate] Delaunay_network kNN_network
#> spatial enrichments --------------
#>   [aggregate][rna] cluster_metagene
#> dim reduction --------------------
#>   [aggregate][rna] pca umap tsne
#> nearest neighbor networks --------
#>   [aggregate][rna] sNN.pca
#> 
#> 
#> Use objHistory() to see steps and params used