MannLabs / py-lmd

https://mannlabs.github.io/py-lmd/
MIT License
7 stars 1 forks source link

CapID for nonsegmentation shapes? #8

Closed josenimo closed 1 year ago

josenimo commented 1 year ago

Dear @sophiamaedler @GeorgWa,

It has been some time, but I come to you with a specific question. I have a collaborator that want to collect shapes drawn on QuPath. I have created a jupyter notebook that tries to do this. However, I do not know if it is possible to label my polygons with CapIDs so that the lmd will automatically select for which wells to collect into.

I even created the list of dictionary entries for the segmentation loader when I noticed that I am not coming from a segmentation mask. Is there an easy way for me to add this well information to the xml file?

I am adding my notebook, and the test geoJSON file from Qupath. https://filetransfer.mdc-berlin.de/?u=brPCXrXA&p=huzTHgBZ

Thank you for your help! Best, Jose

sophiamaedler commented 1 year ago

Hi Jose, really cool how you have applied the pyLMD library to this new type of data! Looks great so far. You are missing one tiny line of code to get what you want working.

I changed your sample_and_well lookup slightly from the datastructure so that you can easily lookup the well based on the sample name:

#classes represent all the different wells, each class goes into one well.
all_classes = poly_df.Name.unique()

#samples_and_wells will be a dictionary where the key is the sample_type and the value is the well into which this sample should be sorted

samples_and_wells = {}
for sample_class, well in zip(all_classes, list_of_acceptable_wells):
    samples_and_wells[sample_class] = well

And then I added this to where you generate the shape collection: (this of course now needs to be executed after you generated the sample_and_wells dictionary)

#add every polygon to the collection
#it passes the coordenates (formated as list of lists) of every row into the new.shape function 
for i in poly_df.index:
    my_collection.new_shape(poly_df.at[i,'lol'], well = samples_and_wells[poly_df.at[i, "Name"]]) #add well parameter which defines which well the shape should go to

Now when you generate the XML each shape is automatically assigned to a specific well as determined by the sample_and_wells dictionary.

Screen Shot 2023-02-03 at 16 01 37

let me know if you have any further problems! Cheers Sophia

josenimo commented 1 year ago

Just tested it in the lmd, it works perfectly, thank you for the quick response.