estellad / SpatialExperimentIO

Read in Xenium, CosMx, Vizgen, STARmap PLUS, seqFISH data as Spatial or SingleCell Experiment object.
6 stars 1 forks source link

optionally separating negative probes & false codes in readCosmxSXE() #4

Open HelenaLC opened 2 months ago

HelenaLC commented 2 months ago

Could we provide an option to pull out non-RNA data? Not too familiar with how exactly data from different vendors arrives, but something similar might be applicable to other readers as well. The following is mock code (i.e., no guarantees & need a couple intermediate validity checks), but I currently do something like...

readCosmxSXE <- function(..., altExps=c(
  negprobe="^Negative[0-9]+$",         # negative probes
  falsecode="^SystemControl[0-9]+$")) { # false codes
  ...
  if (!is.null(altExps)) {
    # get features matching input pattern(s)
    idx <- lapply(altExps, grep, rownames(counts_))
    # split into separate objects & exclude from main assay
    alt <- lapply(idx, \(.) xExperiment(as(counts_[., ], "dgCMatrix"), ...))
    counts_ <- counts_[-unlist(idx), ]
  } else alt <- NULL
  ...
  sxe <- xExperiment(..., altExps=alt)
}
HelenaLC commented 2 months ago

On a related note- CosMx data typically come with a fov_positions_file.csv.gz containing global FOV placement coordinates in px and mm. It'd be nice to not lose these, but stash them in the metadata() or similar. It's just a 5-column data.frame, really, so nothing major, but relevant to some QC strategies being developed as well as basic visualization.