burtonrj / CytoPy

A data-centric flow/mass cytometry automated analysis framework
https://cytopy.readthedocs.io/en/latest/
Other
38 stars 9 forks source link

AssertionError: Invalid sample: <sample name> not associated with this experiment #17

Closed prubbens closed 3 years ago

prubbens commented 3 years ago

Hi,

I am getting an AssertionError when trying to load a datafile using the following code:


exp_name.add_new_sample(sample_id=<sample name>,
                          primary_path='path_to_sample.fcs',
                          compensate=False)
template = GatingStrategy(name="Template", verbose=True)
template.load_data(experiment=exp_name, sample_id=<sample name>)

I am getting the following error:

AssertionError: Invalid sample:<sample name> not associated with this experiment

Any idea how to fix this? The error comes from the get_sample() function.

burtonrj commented 3 years ago

Check that your Experiment contains the sample you're trying to load.

list(exp_name.list_samples()) should contain the sample you're trying to load into your GatingStrategy if it is valid i.e. it has been added to your Experiment correctly.

burtonrj commented 3 years ago

Apologies you keep running into problems @prubbens. An extensive tutorial with an example data will be published soon alongside our updated manuscript following peer-review.

I realise CytoPy has some problems that need ironing out so for the time being I would consider it an "immature" library under active development.

prubbens commented 3 years ago

It's empty indeed. Yet I got no error when running add_new_sample(). After running it, I get:


Creating new FileGroup...
Checking channel/marker mappings...

No error.

prubbens commented 3 years ago

No worries, trying it out for the moment (looking forward to have this functionality available in Python). I think the integration with MongoDB is/can be quite a hassle.

burtonrj commented 3 years ago

I agree, MongoDB adds a heavy layer of complexity.

The ambition eventually is for CytoPy to run on a cloud platform with a web app frontend and GUI, hence why MongoDB and the mongoengine ODM was chosen in the design. MongoDB also gives us a bit more freedom when designing projects, for example when you add a Subject you can associate any kind of meta data to it you like, such a nested dictionaries.

This makes it very powerful but also makes it difficult for new python programmers and people that don't need that level of complexity.

I've had this feedback from alot of people, so I'm thinking at some point of creating "CytoPyLite" which will contain alot of the same functionality but uses SQLAlchemy and SQLite.

prubbens commented 3 years ago

Yeah I understand. The institute I am working at uses MongoDB, so in the long run the package could be really useful for them.

Just a Mongo-novice myself at this point.

prubbens commented 3 years ago

Related to the error, does it have something to do with an improper connection to MongoDB? Cause it's really weird I don't get an error.

burtonrj commented 3 years ago

It's very strange that you didn't receive an error. It looks as if the files have been added to the Experiment correctly....if not I would expect either an Assertion error for a mongoengine error when self.save is called within the add_new_sample function.

The only other explanation is that you possibly have multiple Experiment objects in your environment? And you've mixed them up perhaps?

This is one of the confusing things about using mongoengine (the object-document-mapper). You need be careful with state. A good practice is to reload your Project after big operations like adding lots of files or deleting experiments/files. And then always load your experiments from that Project object using load_experiment.

burtonrj commented 3 years ago

You should also get a success message (when verbose = True) when adding files:

"Successfully created {sample_id} and associated to {self.experiment_id}"

prubbens commented 3 years ago

Indeed, the error was due to adding experiments wrongly. Initially I got an error due to a mismatch in the template file, but I can't seem to fix it.

Can I send you a copy via mail (or put a printscreen or something), to help me out?

burtonrj commented 3 years ago

CytoPy 2.0 was released today making v1.0 redundant.