knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message=FALSE, cache=FALSE, cache.path=KNITDIR)
library("ggplot2")
library("formattable")
library("deseq2analysis")
theme_set(theme_bw())
options(knitr.table.format = "html") 
dataList <- prepareDataFromConfig(deseqconfig)
dds <- dataList$dds
dds.r <- dataList$dds.r
deseq.r <- dataList$deseq.r

DESeq2 analysis: overview

Output Files and Other Analyses

   outputFilesTable(deseqconfig, deseq.r) %>%  knitr::kable(caption="output files") %>% kableExtra::kable_styling(bootstrap_options = c("striped", "hover"), latex_options = "striped")
   norm <-  BiocGenerics::counts(dds.r, normalized=TRUE)
   namet <- tibble::tibble(id=rownames(norm))
   print(dim(namet))
   normt <- tibble::as_tibble(norm)
   print(dim(normt))
   dfnorm <- cbind(namet,normt)
   readr::write_tsv(dfnorm, "all.counts.normalised.tab")

Counts of Deregulated Genes

  #color_bar sqishes the numbers
   extractMultiResultsSignif(deseq.r, deseqconfig$deseq2$adjp, lfc <- deseqconfig$deseq2$log2fc)  %>% 
        #dplyr::mutate(dereg=formattable::color_bar("lightgreen")(dereg), up=formattable::color_bar("lightyellow")(up), down=formattable::color_bar("lightorange")(down)) %>%
        knitr::kable(caption="Counts of deregulated genes") %>% kableExtra::kable_styling(bootstrap_options = c("striped", "hover"), latex_options = "striped")
   plotTotalCounts(dds)

Diagnostic Plots Across all Conditions

   plotSizeFactors(dds.r)
   plotCountsPerGeneBoth(dds.r)
   rlogFull <- DESeq2::rlog(dds.r, blind = TRUE)
   DESeq2::plotPCA(rlogFull, intgroup = "group", ntop = 500)
   plotDispEst(dds.r)
   lfc <- deseqconfig$deseq2$log2fc
   pcut <- deseqconfig$deseq2$adjp 


   deseqout <- NULL
   for(deseq.result in deseq.r){

            #comparison was added by me to metadata(deseq.result)
            comparisongroups <- S4Vectors::metadata(deseq.result)$comparison[2:3]
            normcounts <- getCounts(dds.r, comparisongroups, dataList$grouping)
            filterThreshold <- getFilterThreshold(deseq.result)
            urlfun <- deseqconfig$output$urlfunction
            if(! is.null(urlfun)){
              urlfun <- get(urlfun)
            }
            comp <- toSortedTibble(deseq.result, dataList$annotation, filterThreshold, urlfun, normcounts)
            comparisonFoldchange <- getComparisonFoldChange(deseq.result)
            tit <- getComparison(deseq.result)
            titfile <- getComparisonString(deseq.result)

            LOG(paste("creating files for: ", tit, titfile, deseqconfig$output$savetables ))

            if(deseqconfig$output$savetables){
                saveTables(comp, titfile)
            }

            if(!is.null(deseqconfig$functional)){
                if(! is.null(deseqconfig$debug) && !is.null(deseqconfig$debug$loadrds) && deseqconfig$debug$loadrds ){ #check deseqconfig for loadrds: TRUE
                    LOG("skipping functional analysis but creating plots from RDS")
                }else{
                    testfunctionalFromConfig(comp, titfile, deseqconfig, tit)
                }
            }else{
              LOG(paste("skipping funcitonal analysis because of config"))
            }

            ADVENTUROUS <- TRUE ## this works better than FALSE where I don't find any output files after the 1. loop.
            if(ADVENTUROUS){
                pairRmd <- knitLabels(titfile, KNITDIR)
            }else{
                pairRmd <- system.file('deseq2_pairwise.Rmd', package="deseq2analysis")
            }

            deseqout <- c(deseqout, knitr::knit_child(pairRmd, options = list(echo = FALSE, warning = FALSE, results = 'hide')))
   }


  ## cant' find correct environment:
  ## deseqout <- createGroupComparisons(deseqconfig, deseq.r, dds.r, grouping, ensembl)

DESeq2 results: pairwise comparisons

To subsequent diagnostic plots are all done with an adjusted p-value cutoff of r pcut and a minimal log2 fold change of r lfc. This has no influence on the output of the tables which contain all data sorted by adjusted p-value and log2 fold change. The statistics columns of the tables are given in table \@ref(fig:deseqtabledesc).


   knitr::asis_output(deseqout)

session info

   sessioninfo::session_info()


idot/deseq2analysis documentation built on Aug. 14, 2021, 5:12 a.m.