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"
)
A Giotto object
name of polygon selections
spatial unit
name of spatial locations to use
feature name where metadata will be added
polygon names to plot (e.g. 'polygon_1'). If NULL, plots all available polygons
polygon label for cells located outside of polygons area. Default = "no_polygon"
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
## 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
#> 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 : '/usr/bin/python3'
#> python version : 3.10
#> checking default envname 'giotto_env'
#> a system default python environment was found
#> Using python path:
#> "/usr/bin/python3"
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