Closed mariamasotti1 closed 1 year ago
Interesting. Would you mind posting a code sample that includes a specific call of new_QuantileDist
where the bug occurs? That might be easiest for me to work through
You wouldn't be able to see the bug from a call to newQualtileDist because it's a problem with the intensity calc and the intensities are not returned. But it will be messing up the distance calculations slightly because one of the grids of the intensities is omitted in the calc. Does that make sense?
I only found the bug because I wanted to plot intensities faceted by the quantile for visualization purposes and noticed that when I plotted it there was a grid of the intensities missing.
From: nateosher @.> Sent: Wednesday, February 8, 2023 3:47:47 PM To: nateosher/DistDist @.> Cc: Maria Masotti @.>; Author @.> Subject: Re: [nateosher/DistDist] bug in new_QuantileDist (Issue #1)
External Email - Use Caution
Interesting. Would you mind posting a code sample that includes a specific call of new_QuantileDist where the bug occurs? That might be easiest for me to work through
— Reply to this email directly, view it on GitHubhttps://github.com/nateosher/DistDist/issues/1#issuecomment-1423219490, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A227BRM3P2MD3GZAFYWAF2TWWQA7HANCNFSM6AAAAAAUVXCUEM. You are receiving this because you authored the thread.Message ID: @.***>
Electronic Mail is not secure, may not be read every day, and should not be used for urgent or sensitive issues
I tend to use R/Rstudio's debugger functionality, which lets you "step into" function calls that a function makes and see what's going on inside, so I think that would still be ok
ok just getting back to this...I made a new branch with a fix to the problem
Does this issue have an associated PR? If so, let's reopen and link this issue to that PR.
linking the PR: https://github.com/nateosher/DistDist/pull/2
thanks!
found a bug!! it is in the calculation of the quantiles of intensity...specifically in the fuzzy_join part. I noticed it when I was trying to make intensity plots faceted by quantile for the shiny app. There is one grid of the intensity that is missing from calculations. Not sure the best way to fix it since I am new to the concept of fuzzy_join.
########### code to replicate bug ############ source(here("R/MltplxObject.R")) source(here("R/MltplxImage.R")) source(here("R/MltplxIntensity.R")) source(here("R/MltplxDist.R")) source(here("R/MakeDistMat.R")) source(here("R/MltplxExperiment.R")) source(here("R/intensities.R")) source(here("R/jsd.R")) source(here("R/generics.R")) library(readr) CRC_master <- read_csv("data/CRC_master.csv") crc_data<-CRC_master %>% mutate(type = factor(type)) %>% filter(!(type %in% c("dirt","undefined"))) %>% mutate(type = fct_collapse(type, stroma = c("stroma","nerves","lymphatics"), "CD163+ macros" = c("CD68+CD163+ macrophages","CD163+ macrophages"), "CD68+ macros" = c("CD11b+ monocytes","CD11b+CD68+ macrophages","CD68+ macrophages", "CD68+ macrophages GzmB+","CD11c+ DCs"), "generic immune" = c("tumor cells / immune cells","immune cells","immune cells / vasculature"), "memory CD4+ T"="CD4+ T cells CD45RO+", "CD4+ T cells" = c("CD4+ T cells","CD4+ T cells GATA3+","CD3+ T cells"))) %>% droplevels()
data<-crc_data%>%filter(spots=="1_A")
create multiplex object from first spot
exp1<-new_MltplxObject(x=data$X,y=data$Y,marks=as.factor(data$type),slide_id=data$spots,ps=10,bw=30)
the following code I pulled from th new_QuantileDist() function to investigate this bug:
intensities <- exp1$mltplx_intensity$intensities %>% as.data.frame() mask_type<-"tumor cells" mask_intensities <- intensities %>% pull(!!sym(mask_type)) q_probs<-cbind.data.frame(from=c(0,25,50,75),to=c(25,50,75,100)) q <- q_probs %>% pmap_dfr((from,to) { as.vector(quantile(mask_intensities,probs=c(from,to)/100)) -> x x <- c(x,from,to) names(x) <- c("q1","q2","p1","p2") x }) %>% mutate(q_fac = factor(1:nrow(.)))
############### here is the problem ##################### intensities %>% fuzzyjoin::fuzzy_join(q, by = setNames(c("q1","q2"),c(mask_type,mask_type)), match_fun = list(
>=
,<
)) -> joined_qdim does not match
dim(joined_q)[1]==dim(intensities)[1]
the highest intensity gridpoint is omitted
ggplot(joined_q,aes(X,Y))+geom_raster(aes(fill=
tumor cells
))+facet_grid()