Add corresponding polygon IDs to cell metadata

addPolygonCells(
  gobject,
  polygon_name = "selections",
  spat_unit = "cell",
  spat_loc_name = "raw",
  feat_type = "rna",
  polygons = NULL,
  na.label = "no_polygon"
)

Arguments

gobject

A Giotto object

polygon_name

name of polygon selections

spat_unit

spatial unit

spat_loc_name

name of spatial locations to use

feat_type

feature name where metadata will be added

polygons

polygon names to plot (e.g. 'polygon_1'). If NULL, plots all available polygons

na.label

polygon label for cells located outside of polygons area. Default = "no_polygon"

Value

A Giotto object with a modified cell_metadata slot that includes the polygon name where each cell is located or no_polygon label if the cell is not located within a polygon area

Examples

## Plot interactive polygons
g <- GiottoData::loadGiottoMini("visium")
#> 1. read Giotto object
#> 2. read Giotto feature information
#> 3. read Giotto spatial information
#> 3.1 read Giotto spatial shape information
#> cell_spatInfo_spatVector.shp
#> cell
#> 
#> 3.2 read Giotto spatial centroid information
#> cell
#> 
#> 3.3 read Giotto spatial overlap information
#> No overlaps were found, overlap loading will be
#>  skipped
#> 
#> 4. read Giotto image information
#> a giotto python environment was found
#> Using python path:
#>  "/Users/yuanlab/Library/r-miniconda/envs/giotto_env/bin/pythonw"
my_polygon_coords <- data.frame(
    poly_ID = rep("polygon1", 3),
    sdimx = c(5477, 5959, 4720),
    sdimy = c(-4125, -2808, -5202)
)

## Add polygon coordinates to Giotto object
my_giotto_polygons <- createGiottoPolygon(
    my_polygon_coords,
    name = "selections"
)
#>   Selecting col "poly_ID" as poly_ID column
#>   Selecting cols "sdimx" and "sdimy" as x and y respectively

g <- addGiottoPolygons(
    gobject = g,
    gpolygons = list(my_giotto_polygons)
)

## Add polygon IDs to cell metadata
g <- addPolygonCells(g)
#> 
#> These column names were already used: in_tissue nr_feats perc_feats total_expr
#>  leiden_clus custom_leiden
#>  and will be overwritten
pDataDT(g)
#>                 cell_ID in_tissue nr_feats perc_feats total_expr leiden_clus
#>                  <char>     <int>    <int>      <num>      <num>       <num>
#>   1: AACTCGATGGCGCAGT-1         1      265   41.79811  1057.9308           2
#>   2: GGCTGGCTAGCTTAAA-1         1      279   44.00631  1064.7493           5
#>   3: GACGCCTGTTGCAGGG-1         1      219   34.54259   964.9294           2
#>   4: GAGGGCATCGCGTATC-1         1      294   46.37224  1142.7664           2
#>   5: TCAACACATTGGGTAA-1         1      261   41.16719  1063.3517           2
#>  ---                                                                        
#> 620: GGTAGTGCTCGCACCA-1         1      179   28.23344   768.4749           5
#> 621: AAGCTCGTGCCAAGTC-1         1      195   30.75710   756.0675           5
#> 622: TATTCAATTCTAATCC-1         1      247   38.95899   921.8264           5
#> 623: TTCAAAGTCTCTAGCC-1         1      384   60.56782   916.5929           6
#> 624: TTGAATATGGACTTTC-1         1      380   59.93691   912.3051           6
#>      custom_leiden selections
#>              <num>     <char>
#>   1:             4 no_polygon
#>   2:             3 no_polygon
#>   3:             3 no_polygon
#>   4:             3 no_polygon
#>   5:             3 no_polygon
#>  ---                         
#> 620:             4 no_polygon
#> 621:             4 no_polygon
#> 622:             4 no_polygon
#> 623:             7 no_polygon
#> 624:             4 no_polygon