FelixTheStudent / cellpypes

Cell type pipes for R
GNU General Public License v3.0
51 stars 3 forks source link

Backtrace which cells that got classified? #20

Closed RolantusdataExp closed 2 years ago

RolantusdataExp commented 2 years ago

Hi Felix, Thank you so much for this very useful tool!

I was wondering if you were considering adding a function to backtrace the classification to individual cells of the Single-cell RNA seq data. I would love to be able to import the results classifier back to my Seurat object with the classification.

Al the best, Peter

FelixTheStudent commented 2 years ago

Hi Peter,

thanks for the idea! Let me ask you about some more details and how you would use that functionality.

Is it the rules you’d like to import into the Seurat object? Or information which rule was positive for which cell?

And is your goal to have reproducibility when sharing the Seurat object, or would you like to use this somehow in Seurat operations (plotting, subsetting, …)?

Looking forward to hearing back from you.

Best,

Felix

RolantusdataExp commented 2 years ago

I think it would be an amazing addition if we were able to add the results from the CellPype rules to the metadata of our Seurat Object (i.e. the classification results, thus serving as some kind of annotation).

Ideally, the "only" thing you need to add in CellPypes is the ability to identify which cells the different rules ably to maybe based on the colnames of the Seurat object. For this to work you of course need to include these in the CellPypes object.

Best regards,

Peter

FelixTheStudent commented 2 years ago

Hi Peter,

thanks for spinning this thought further. I think the functionality we're discussing here exists in almost the form you describe, let me explain.

Adding labels to Seurat's meta data I think the following code will do what you want:

pype_labels <- pype_from_seurat(seurat) %>% rule("T", "CD3E", ">", 1) %>% classify()
seurat$pype_labels <- pype_labels
DimPlot(seurat, group.by = "pype_labels")

Note that cellpypes was written so that it does not change the order of cells, so the code above works without double-checking the barcodes (Seurat colnames) -- and the DimPlot should validate this nicely. Still, if you wanted to check programatically you could, because the pype_labels in above code are a factor named with the barcodes. If they are not, install the newest version of cellpypes with install_github("FelixTheStudent/cellpypes") and restart RStudio!

See for each cell which rule applies I intend my users (you in this case!) to use the plot_last function after every rule to see which cells get selected by that rule. Would that work for you, and if not, why not? :) Also, check out the return_logical_matrix argument in the classify function. It'll return a logical data.frame with one column per class. You can tell classify which classes to return and it'll apply all rules you defined for these classes.

Question to you How far is that from what you had in mind? Is this a viable solution, or does that not work for you? Why not?

Looking forward to hearing from you!

Best,

Felix

RolantusdataExp commented 2 years ago

Hi Felix,

Exactly what I was thinking of! Thank you

FelixTheStudent commented 2 years ago

Excellent, glad cellpypes works well for you. Keep posting issues here, they are great feedback for me and can be helpful for others, too!