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

Error when making a class inheriting from SingleClassExperiment #69

Open
HarkiratSohi opened this issue Jun 1, 2023 · 8 comments
Open

Comments

@HarkiratSohi
Copy link

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.

@LTLA
Copy link
Collaborator

LTLA commented Jun 1, 2023

hard to say. can you give a MRE?

@HarkiratSohi
Copy link
Author

HarkiratSohi commented Jun 1, 2023

Thanks for looking into this. Here is a MRE:

The following gives no errors:

setClass("testClass1",
contains = "SingleCellExperiment"
)
tc1 = new("testClass1")

Simple test: adding a slot

The following gives the noted error

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!

@HarkiratSohi
Copy link
Author

To follow up, switching to contains = "SummarizedExperiment" doesn't give the error.

No error here:

setClass("testClass5",
slots = c(coordinates="numeric"),
contains = "SummarizedExperiment"
)
tc5 = new("testClass5",coordinates = 3)

@HarkiratSohi
Copy link
Author

@LTLA Could someone from the SingleCellExperiment team provide some guidance on this issue? Thank you!

@LTLA
Copy link
Collaborator

LTLA commented Jun 6, 2023

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)

@HarkiratSohi
Copy link
Author

Thanks @LTLA , that's helpful to know. I basically want to extend the functionality of an existing class.

@LTLA
Copy link
Collaborator

LTLA commented Jun 8, 2023

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.

@HarkiratSohi
Copy link
Author

Thanks!

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