MarioniLab / miloR

R package implementation of Milo for testing for differential abundance in KNN graphs
https://bioconductor.org/packages/release/bioc/html/miloR.html
GNU General Public License v3.0
344 stars 22 forks source link

Should not perform any direct filtering on `da_result` before executing `groupNhoods` #353

Open isaamael opened 5 days ago

isaamael commented 5 days ago

Hi !

Thank you for your outstanding software. While following the tutorial for analysis, I filtered da_result to remove some irrelevant cell types in plotDAbeeswarm

>packageVersion("miloR")
[1] ‘1.8.1’
>da_result= da_result[!da_result$celltype %in% c("UN1","UN2","UN3","UN4","UN5","UN6","Mixed"),]

As a consequence, groupNhoods throws the error:

Error in .group_nhoods_from_adjacency(nhoods(x), nhood.adj = nhoodAdjacency(x), :
Subsetting is.da vector length is not the same dimension as adjacency

The reason is that groupNhoodschecks for equality between

>length(colnames(nhoods(da)))
[1] 5113
>length(colnames(nhoodAdjacency(da)))
[1] 5113
>length(da_result$SpatialFDR)
[1] 4267

filtering in advance causes this error. I am reporting this here in hopes it helps others.

Additionally, I have a question~

Within the same cluster, some Nhoodshave increased/decreased after treatment, while others show no significant change. I am particularly interested in which genes lead to the different changes in Nhoodswithin the same cluster. Once I obtain the Nhoodsand their corresponding clusters, can I manually annotate them instead of using groupNhoodsfor reclassification? For example, can I assign Nhoodswithin the same cluster, like C1, that have increased/unchanged/decreased to different NhoodGroups (1/2/3), and then execute findNhoodGroupMarkersamong them? Is this approach reasonable?

Any advice from you would be helpful!

MikeDMorgan commented 5 days ago

If you have a single-cell level annotation in a column of colData() then you can use annotateNhoods to assign a label to each nhood in your DA results data frame. It does this by a majority voting scheme and reports the fraction of cells in the Nhoods with that specific label.

If you want to create a beeswarm or any other nhood plots on a subset of nhoods you need to use the subset.hoods argument for the relevant plotting function.

It sounds like you want to DE testing within a group of Nhoods? That is what the testDiffExp function is for. You can essentially use the same variable as you did for the DA testing to get this.