Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get/set_cell_id no longer available #1109

Open
rbutleriii opened this issue Feb 28, 2025 · 3 comments
Open

get/set_cell_id no longer available #1109

rbutleriii opened this issue Feb 28, 2025 · 3 comments

Comments

@rbutleriii
Copy link

I was trying to update the cell_IDs in my object to correspond to another dataset, but the get_cell_id and set_cell_id don't seem to be in GiottoClass anymore.

How would one go about changing say the slide number in the cell_ID from c_1_x_x -> c_4_x_x? I tried it manually, but I still must be missing something, because:

instrs = createGiottoInstructions(
  save_dir = out_path, 
  save_plot = TRUE,
  show_plot = FALSE, 
  return_plot = FALSE,
  python_path = python_path
)

# create giotto cosmx object
gobj = createGiottoCosMxObject(
  cosmx_dir = data_path,
  version = 'legacy',
  load_cellmeta = TRUE,
  FOVs = as.numeric(unlist(strsplit(fovs, ","))),
  instructions=instrs,
  verbose = TRUE
)

# re-numbering slides to match SO slide_num
if (slide_num != 1) {
  # Quick gsub in-place
  q_rep <- function(i) gsub("^c_1", paste0("c_", slide_num), i)
  print(sprintf("Renaming cell_ID slide number: c_1_x_x -> c_%s_x_x ", slide_num))
  gobj@cell_ID$cell <- q_rep(gobj@cell_ID$cell)
  gobj@cell_metadata$cell$rna$cell_ID <- q_rep(gobj@cell_metadata$cell$rna$cell_ID)
  gobj@cell_metadata$cell$negprobes$cell_ID <- q_rep(gobj@cell_metadata$cell$negprobes$cell_ID)
  gobj@spatial_locs$cell$raw$cell_ID <- q_rep(gobj@spatial_locs$cell$raw$cell_ID)
  gobj@spatial_info$cell$poly_ID <- q_rep(gobj@spatial_info$cell$poly_ID)
}

Did not catch every location of the cell IDs from a fresh gobj with no expression data. I still get:

For Feature info:  rna 

An object of class giottoPoints
feat_type : "rna"
Feature Information:
 class       : SpatVector 
 geometry    : points 
 dimensions  : 10036490, 5  (geometries, attributes)
 extent      : -485706, -444750.8, 4011.324, 29619.7  (xmin, xmax, ymin, ymax)
 coord. ref. :  
 names       : feat_ID   fov     z CellComp feat_ID_uniq
 type        :   <chr> <int> <int>    <chr>        <int>
 values      : Ndufa13    41    -1     None            1
                Il1rap    41    -1     None            2
                 Ntrk1    41    -1     None            3

-----------------------------
 
For Feature info:  negprobes 

An object of class giottoPoints
feat_type : "negprobes"
Feature Information:
 class       : SpatVector 
 geometry    : none 
 dimensions  : 0, 5  (geometries, attributes)
 extent      : 0, 0, 0, 0  (xmin, xmax, ymin, ymax)
 coord. ref. :  
 names       : feat_ID   fov     z CellComp feat_ID_uniq
 type        :   <chr> <int> <int>    <chr>        <int>
 values      :      NA    NA    NA       NA           NA

-----------------------------
 
For Spatial info:  cell 

An object of class giottoPolygon
spat_unit : "cell"
Spatial Information:
 class       : SpatVector 
 geometry    : polygons 
 dimensions  : 8499, 1  (geometries, attributes)
 extent      : -485702.1, -444778.3, 4000.564, 29628.48  (xmin, xmax, ymin, ymax)
 coord. ref. :  
 names       :  poly_ID
 type        :    <chr>
 values      : c_4_41_1
               c_4_41_2
               c_4_41_3
 centroids   : calculated
 overlaps    : NULL
-----------------------------
 
1. convert polygon to raster
2. overlap raster and points
3. add polygon information
4. add points information
5. create overlap polygon
 information
Error: giotto initialize
 cell_IDs between spatial and expression information
 are not the same for:
 spatial unit: cell and coordinates: raw
Execution halted
@jiajic
Copy link
Member

jiajic commented Feb 28, 2025

There currently is not a way to directly manipulate the IDs in a giotto object. When it gets added in the future it will probably be via the spatIDs<-() replacement function.

For this specific problem, there is a slide param in createGiottoCosMxObject() that you can set to 4 that passes through ... to the lower level importer. This is being made more prominent in the next update #1103.

I'll need to take a closer look at this to figure out why it's complaining about expression when it doesn't exist yet.

@jiajic
Copy link
Member

jiajic commented Feb 28, 2025

Also, there can be issues when geometries are completely empty like the 'negprobes' feature is.
We might change the giotto object behavior to automatically toss out empty objects to get around it. For now they can be manually removed by using

sliceGiotto(feat_type = "negprobes", negate = TRUE)

@rbutleriii
Copy link
Author

Was #1103 pushed to R4.1.0? I saw that and tried it first, but for some reason it didn't apply my slide option.

That sliceGiotto is much easier than my workaround from #946

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants