Open rbutleriii opened 2 months ago
Apparently that upsets Giotto quite a bit, if you attempt to remove just the feature_info:
setFeatureInfo(gobj, NULL, feat_type = "neg_probe")
NULL passed to gpoints.
Removing specified feature information.
Error in .check_feat_metadata(gobject = .Object) :
No expression or polygon information discovered for feat_type: neg_probe
Please add expression or polygon information for this feature type first
Calls: setFeatureInfo ... set_feature_info -> initialize -> initialize -> .check_feat_metadata
Execution halted
Or if you try to remove the feature_metadata first:
# Drop neg_probe as it is sometimes missing
setFeatureMetadata(gobj, NULL, feat_type = "neg_probe")
setFeatureInfo(gobj, NULL, feat_type = "neg_probe")
NULL passed to metadata.
Removing specified metadata.
Error in `*tmp*`[[spat_unit]] :
attempt to select less than one element in get1index
Calls: setFeatureMetadata -> set_feature_metadata
Execution halted
Is there a way to tell createGiottoCosMxObject
to not read the neg_probes in the first place? Might be easier than trying to hunt down all the places in the gobj it hides.
Update, for some of the setters, i.e. setFeatureMetadata
, you can avoid the second error by specifying the spat_unit = "cell"
as they are structured with features under the spat. However, that still produces the Error in .check_feat_metadata
, as it still has an incomplete feat_type
. So most of the setters won't allow you to remove the info either! There is probably a right order of getter/setter operations for this to work, but the hacky workaround is just to start ripping things out piecemeal:
# Drop neg_probe as it is sometimes missing
# gobj <- setFeatureInfo(gobj, NULL, feat_type = "neg_probe")
gobj@feat_info$neg_probe = NULL
gobj@feat_ID$neg_probe = NULL
gobj@feat_metadata$cell$neg_probe = NULL
gobj@cell_metadata$cell$neg_probe = NULL
gobj@expression$cell$neg_probe = NULL
gobj@expression_feat = gobj@expression_feat[gobj@expression_feat != "neg_probe"]
Since it is a created object from subcellular
, the expression data doesn't exist yet, but just in case I added those lines. This also doesn't store a record of steps in gobj@parameters, but...I have a functional object.
Yeah Giotto is particularly touchy about raw data (polys and points) and expression information. Giotto's initialize()
method immediately grabs the IDs information and sets up the ID and metadata slots. This behavior allows data to be added to the Giotto object outside of the createGiottoObject()
framework, but removal is a lot harder, as you have noticed, and there currently is not a better way than your approach.
The way that createGiottoCosMxObject()
reads the transcripts and splits it into RNA and neg_probe is hardcoded, unfortunately. But on the dev @modular_readers branch, it is now possible to have finer control over how transcript data is split and which items are then included in the Giotto object.
An actual fix to the empty objects issue should probably be something like having the Giotto object send a warning and toss out any nrow == 0 objects and dim of c(1, 1) NA matrices
How to deal with the setter fighting initialize()
is probably going to be a bit more difficult. Possible solutions are:
initialize()
to automatically drop hierarchically dependent data (such as automatically removing metadata info if it is no longer supported by a piece of expression information, or raw spatial data e.g. polys/points) -- which may be an unexpected effect in itself.sliceGiotto()
function that allows specific spat_units
and feat_types
to be extracted as a new giotto
object.
Noting this here for the future, I am getting errors with a newer set of CosMx slides that had missing
neg_probe
information. And I think that is leading to the following innocuous error when you write the object to file:The feature_info:
The problem I think is with those feature dims at
0,1
, when you try to open it again, you will get an issue with the SpatVector dimensions for the rna features? or the message to the terminal just comes after the neg_probe_feature_spatVector is attempted to be read:Trying to remove the neg_probe feature from the object to see if it helps with
setFeatureInfo(gobj, NULL, feat_type = "neg_probe")