SydneyBioX / spicyR

https://sydneybiox.github.io/spicyR/
8 stars 4 forks source link

`signifPlot` with `fdr = TRUE` #28

Closed nilseling closed 1 year ago

nilseling commented 1 year ago

Hi @ellispatrick

thanks for the great tool! I'm now at the visualization part and would like to set a cutoff on the adjusted rather than the raw p value. My expectation is that

data(spicyTest)
signifPlot(spicyTest,
                 fdr = FALSE, 
                 breaks=c(-3, 3, 0.5),
                 curoff = 0.05)

and

data(spicyTest)
signifPlot(spicyTest,
                 fdr = TRUE, 
                 breaks=c(-3, 3, 0.5),
                 curoff = 0.05)

would give different results, which don't seem to be the case. Is there anything I'm missing here?

R version 4.3.0 (2023-04-21)
Platform: x86_64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.7.9

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib 
LAPACK: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

time zone: Europe/Zurich
tzcode source: internal

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] spicyR_1.12.0

loaded via a namespace (and not attached):
  [1] tidyselect_1.2.0            concaveman_1.1.0            dplyr_1.1.2                 farver_2.1.1                R.utils_2.12.2              bitops_1.0-7                SingleCellExperiment_1.22.0
  [8] RCurl_1.98-1.12             spatstat.geom_3.2-4         spatstat.explore_3.2-1      tweenr_2.0.2                lifecycle_1.0.3             spatstat.data_3.0-1         magrittr_2.0.3             
 [15] compiler_4.3.0              rlang_1.1.1                 tools_4.3.0                 utf8_1.2.3                  data.table_1.14.8           labeling_0.4.2              S4Arrays_1.0.5             
 [22] dqrng_0.3.0                 DelayedArray_0.26.7         RColorBrewer_1.1-3          abind_1.4-5                 BiocParallel_1.34.2         HDF5Array_1.28.1            purrr_1.0.1                
 [29] withr_2.5.0                 numDeriv_2016.8-1.1         BiocGenerics_0.46.0         R.oo_1.25.0                 grid_4.3.0                  polyclip_1.10-4             stats4_4.3.0               
 [36] fansi_1.0.4                 beachmat_2.16.0             colorspace_2.1-0            Rhdf5lib_1.22.0             edgeR_3.42.4                ggplot2_3.4.2               spatstat.utils_3.0-3       
 [43] scales_1.2.1                MASS_7.3-60                 SummarizedExperiment_1.30.2 cli_3.6.1                   crayon_1.5.2                generics_0.1.3              rstudioapi_0.15.0          
 [50] rjson_0.2.21                DelayedMatrixStats_1.22.1   minqa_1.2.5                 scuttle_1.10.2              ggforce_0.4.1               rhdf5_2.44.0                zlibbioc_1.46.0            
 [57] splines_4.3.0               parallel_4.3.0              scam_1.2-14                 XVector_0.40.0              matrixStats_1.0.0           vctrs_0.6.3                 boot_1.3-28.1              
 [64] Matrix_1.6-0                IRanges_2.34.1              S4Vectors_0.38.1            tensor_1.5                  magick_2.7.5                locfit_1.5-9.8              limma_3.56.2               
 [71] tidyr_1.3.0                 goftest_1.2-3               spatstat.random_3.1-5       glue_1.6.2                  nloptr_2.0.3                DropletUtils_1.20.0         codetools_0.2-19           
 [78] gtable_0.3.3                deldir_1.0-9                GenomeInfoDb_1.36.1         GenomicRanges_1.52.0        lme4_1.1-34                 lmerTest_3.1-3              munsell_0.5.0              
 [85] tibble_3.2.1                pillar_1.9.0                rhdf5filters_1.12.1         GenomeInfoDbData_1.2.10     R6_2.5.1                    sparseMatrixStats_1.12.2    lattice_0.21-8             
 [92] Biobase_2.60.0              R.methodsS3_1.8.2           SpatialExperiment_1.10.0    pheatmap_1.0.12             Rcpp_1.0.11                 spatstat.sparse_3.0-2       nlme_3.1-162               
 [99] mgcv_1.8-42                 MatrixGenerics_1.12.3       pkgconfig_2.0.3   
ellispatrick commented 1 year ago

Hi Nils,

Great pickup!

sig <- test$p.value[,2] < cutoff
sigLab <- paste0("p-value < ",cutoff)
if(fdr){
sig <- test$p.value[,2] < cutoff   
sigLab <- paste0("fdr < ",cutoff)
}

I've pushed the addition of p.adjust() to github. I'll run Biocheck() etc and push to Bioconductor tomorrow morning. Hopefully it didn't break something.

Let me know if I've screwed thing up.

PS, My students have been generalising these plots for survival data and a few other applications. If needed I can try to push them your way, they may have implemented them in their Statial package, but haven't adapted here.

nilseling commented 1 year ago

Sweet, thanks! I'll check it out again in a couple of days and close this issue once it works.

I think having a few more of these plots would be great. The lab is using spicyR now quite regularly and could use a few more pointers.

nilseling commented 1 year ago

So this has been fixed but it seems that topPairs doesn't select the right rows when specifying cutoff:

spicyTest <- spicy(
  diabetesData_SCE,
  condition = "stage",
  subject = "case"
)

topPairs(spicyTest, cutoff = 0.1, adj = "fdr")

returns 0 rows but it should be 2.