Open HarkiratSohi opened 1 year ago
hard to say. can you give a MRE?
Thanks for looking into this. Here is a MRE:
setClass("testClass1", contains = "SingleCellExperiment" ) tc1 = new("testClass1")
setClass("testClass4", slots = c(coordinates="numeric"), contains = "SingleCellExperiment" ) tc4 = new("testClass4",coordinates = 3)
Error in checkSlotAssignment(object, name, value) : assignment of an object of class "S4" is not valid for slot 'int_elementMetadata' in an object of class "SingleCellExperiment"; is(value, "DataFrame") is not TRUE
I was able to trace back and find that this error is reported when possibleExtends("S4", "DataFrame", ClassDef2 = getClassDef("DataFrame", where = .classEnv(DataFrame))) is false.
Thank you for your help!
To follow up, switching to contains = "SummarizedExperiment" doesn't give the error.
setClass("testClass5", slots = c(coordinates="numeric"), contains = "SummarizedExperiment" ) tc5 = new("testClass5",coordinates = 3)
@LTLA Could someone from the SingleCellExperiment team provide some guidance on this issue? Thank you!
Probably because there's no prototype set up for the SCE class. In theory, we should add a prototype, but in practice, it doesn't matter, because very few people should be constructing an empty SCE with new
anyway. In your case, I suspect that you already have an SCE that you want to convert to your custom class, in which case you can just do:
tc4 = new("testClass4", sce, coordinates=3)
Or, if you really do want an empty instance of your new class:
tc4 = new("testClass4", SingleCellExperiment(), coordinates=3)
Thanks @LTLA , that's helpful to know. I basically want to extend the functionality of an existing class.
Sure, and that's fine, but it seems highly unlikely that anyone will be calling new
to construct an instance of your class. If an instance is to be constructed, it should be done using the calls containing sce
as shown above.
Check out the SpatialExperiment package for an example of an extended SCE.
Thanks!
I get the following error when I use setClass to define a class , with contains = SingleCellExperiment and when I specify a new attribute in "slot ="
Error in checkSlotAssignment(object, name, value) : assignment of an object of class "S4" is not valid for slot 'int_elementMetadata' in an object of class "SingleCellExperiment"; is(value, "DataFrame") is not TRUE
I don't get this error if I make a new class using setClass, inheriting from SummarizedExperiment. I've searched a lot on the internet but have not been able to resolve this issue. Is this an issue specific to SingleCellExperiment? I can't quite tell. Any help would be appreciated.