GreenleafLab / ArchR

ArchR : Analysis of Regulatory Chromatin in R (www.ArchRProject.com)
MIT License
388 stars 140 forks source link

Differential deviation by ChromVAR #340

Closed yxiao832 closed 4 years ago

yxiao832 commented 4 years ago

Hi ArchR team,

I started using ArchR recently and it has been wonderful!

Just one comment on the ChromVAR analysis in ArchR.

The original ChromVAR has a function "differentialDeviations" which allows me to extract clusters of interest and do pairwise comparison between cluster A and cluster B.

I wonder whether ArchR can include this? or it's already in ArchR and I just missed it.

Thanks again! Yang

rcorces commented 4 years ago

I believe what you are looking for would be using getMarkerFeatures() with useMatrix="MotifMatrix". You will have to specify the correct argument for useSeqnames - this post might explain that https://github.com/GreenleafLab/ArchR/issues/55#issuecomment-614350514

jgranja24 commented 4 years ago

My recommended parameters when doing this is something like

diffMotif <- getMarkerFeatures(
    ArchRProj = proj, 
    testMethod = "wilcoxon",
        useGroups = "ClusterA",
        bgdGroups = "ClusterB",
    binarize = FALSE,
    useMatrix = "MotifMatrix",
    groupBy = "Clusters",
    useSeqnames="z"
)
yxiao832 commented 4 years ago

Thank you for the answer!

One more question, can I do a differential test for three groups in ArchR? such as Kruskal–Wallis test in the old "differentialDeviations" function.

jgranja24 commented 4 years ago

What do you mean by that?

yxiao832 commented 4 years ago

This is what I found about the "differentialDeviations" function in ChromVAR (below).

In this function, it looks to me that when the input are more than two groups, it will be a different test such as Kruskal–Wallis test for non-parametric, which will tell me whether they are different in general across three or more different groups.

But in "getMarkerFeatures", it seems I can only do pair-wise comparison. For example, I can only know whether A is different from B&C, not a general result whether A,B, C are different.

function (object, groups, alternative = c("two.sided", "less", "greater"), parametric = TRUE) { stopifnot(is(object, "chromVARDeviations")) if (length(groups) == 1 && groups %in% colnames(colData(object))) { groups <- colData(object)[[groups]] } else if (length(groups) != ncol(object)) { stop("invalid groups input, must be vector of lench ncol(object) or column", " name from colData(object)") } groups <- as.factor(groups) alternative <- match.arg(alternative) inputs <- deviations(object) if (parametric) { if (nlevels(groups) == 2) { p_val <- apply(inputs, 1, t_helper, groups, alternative) } else { p_val <- apply(inputs, 1, anova_helper, groups) } } else { if (nlevels(groups) == 2) { p_val <- apply(inputs, 1, wilcoxon_helper, groups, alternative) } else { p_val <- apply(inputs, 1, kw_helper, groups) } } p_adj <- p.adjust(p_val, method = "BH") return(data.frame(p_value = p_val, p_value_adjusted = p_adj)) }

apelonero-GladstoneInstitutes commented 2 years ago

Came across this issue two years later, so I'll comment this here just in case anyone needs it: chromVAR Statistics for ArchR Deviations.

This repo contains slightly modified chromVAR differential deviations/variability functions that work with deviations stored in ArchR, allowing us to run any variety of stats offered by these chromVAR functions on ArchR projects.

AnjaliC4 commented 2 years ago

Hi @apelonero-GladstoneInstitutes, thanks for implementing this with ArchR. I was trying to understand your code. In ChromVar, they use deviations for differentialdeviations and deviationScores for differentialVariability. I believe the difference is that differentialdeviations uses deviations and differentialVariability would use the bias-corrected z-scores. In your code, you use deviations from ArchR for both. What do you think about this? inputs <- as.matrix(archrMotifMatrix@assays@data@listData$deviations) instead of inputs <- as.matrix(archrMotifMatrix@assays@data@listData$z)

apelonero-GladstoneInstitutes commented 2 years ago

Hi @AnjaliC4. I forgot to change that line when refactoring the code from deviations to variability. I've implemented this fix and pushed it to the repo - thank you!