DEGreport icon indicating copy to clipboard operation
DEGreport copied to clipboard

Extracting Gene-Gene distance matrix from DegPatterns

Open chk63 opened this issue 3 years ago • 3 comments

Hello,

I used DegPatterns to cluster my genes which worked, but for upstream analysis I require the gene-gene distance matrix that was used to create these clusters. Is there any way to extract this matrix? Thanks!

chk63 avatar Sep 01 '21 14:09 chk63

Hey, sorry for the late reply. I think the best way is to do it by yourself since you know the genes.

.summarize_scale <- function(ma, group, scale = TRUE){
    counts_group = t(sapply(rownames(ma), function(g){
        sapply(levels(group), function(i){
            idx = which(group == i)
            mean(ma[g, idx], na.rm = TRUE)
        })
    }))
    colnames(counts_group) = levels(group)
    .logger(head(counts_group), "summarize_scale::counts_group")
    .logger(head(group), "summarize_scale::group")
    if (scale) {
        norm_sign <- t(apply(counts_group, 1, .scale))
    }else{
        norm_sign <- counts_group
    }
    colnames(norm_sign) = colnames(counts_group)
    norm_sign
}
    # ma is the matrix only with your genes of interest 
    # metadata[[summarize]] is the vector with the time or group information matching the samples order in ma
    counts_group <- .summarize_scale(ma,
                                     metadata[[summarize]],
                                     FALSE)

    m <- (1 - cor(t(counts_group), method = "kendall"))
    d <- as.dist(m^2)

I could try to add the output package but not sure when I could do that. Let me know.

lpantano avatar Sep 01 '21 20:09 lpantano

Hello,

When I run the code, I'm getting the following error message: Error in summarize_scale(cluster_rlog_inf, infected_coldata_10E7_Null[[summarize]], : unused argument (FALSE). Any ideas why this could be happening? Thank you!

On Wed, Sep 1, 2021 at 4:28 PM Lorena Pantano @.***> wrote:

Hey, sorry for the late reply. I think the best way is to do it by yourself since you know the genes.

.summarize_scale <- function(ma, group, scale = TRUE){ counts_group = t(sapply(rownames(ma), function(g){ sapply(levels(group), function(i){ idx = which(group == i) mean(ma[g, idx], na.rm = TRUE) }) })) colnames(counts_group) = levels(group) .logger(head(counts_group), "summarize_scale::counts_group") .logger(head(group), "summarize_scale::group") if (scale) { norm_sign <- t(apply(counts_group, 1, .scale)) }else{ norm_sign <- counts_group } colnames(norm_sign) = colnames(counts_group) norm_sign } # ma is the matrix only with your genes of interest # metadata[[summarize]] is the vector with the time or group information matching the samples order in ma counts_group <- .summarize_scale(ma, metadata[[summarize]], FALSE)

m <- (1 - cor(t(counts_group), method = "kendall"))
d <- as.dist(m^2)

I could try to add the output package but not sure when I could do that. Let me know.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lpantano/DEGreport/issues/47#issuecomment-910712434, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOY6HF2UZNZC4L46JMNY3NLT72EHBANCNFSM5DGR6ZFQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Catherine Kagemann PhD Candidate, Aquadro Lab | Genetics, Genomics, and Development Dept. of Molecular Biology and Genetics Cornell University | Ithaca, NY

chk63 avatar Sep 01 '21 21:09 chk63

mm, not sure what is happening. are you using the function as .summarize_scale with a dot in front of the function? (assuming you have copy/paste my code) i use the door in front of functions to tell they are internal, and I took it directly from the code. Not sure if you tried to use directly like that and then calling it without the dot. Feel free to share the exact code you are using and/or share the R environment with me. Happy to try to help. Cheers

lpantano avatar Sep 04 '21 23:09 lpantano