Skip to content

Instantly share code, notes, and snippets.

View tavareshugo's full-sized avatar

Hugo Tavares tavareshugo

View GitHub Profile
@tavareshugo
tavareshugo / deseq2_numericContrast.R
Last active November 13, 2022 11:58
Create numeric contrast for DESeq2::results() function
#' Create numeric contrast for DESeq2::results() function
#'
#' @param object a DESeqDataSet object.
#' @param group1 logical expression indicating the columns from colData(object) that form part of group1 (numerator).
#' @param group2 logical expression indicating the columns from colData(object) that form part of group2 (denominator).
#'
#' @examples
#' # example data for a two-factor design with interaction
#' dds <- makeExampleDESeqDataSet()
#' dds$timepoint <- factor(rep(1:3, 4))
@tavareshugo
tavareshugo / relChange.R
Last active December 6, 2019 11:35
calculate the change over a time variable, relative to one of the time points
#' Calculate relative change across time
#'
#' @param value a vector with the values to calculate the change over.
#' @param time a vector with the time points.
#' @param ref_time the reference time point to scale the change by.
relChange <- function(value, time, ref_time = min(time)){
# check if reference time is contained in the given vector
if(any(is.na(value))) stop("Missing values in 'value' not supported. Remove them first.")
if(any(is.na(time))) stop("Missing values in 'time' not supported. Remove them first.")
@tavareshugo
tavareshugo / _qtl2helpers.md
Last active January 17, 2022 10:16
qtl2helpers

Helper functions to manipulate and/or coerce qtl2 objects. Eventually might make sense to submit as pull request?

#' Tidying methods for DESeq2 DESeqTransform objects
#'
#' This reshapes a DESeq2 transform object (output from `rlog()` and
#' `varianceStabilizingTransform()` functions) into a tidy format.
#'
#' @param x DESeqTransform object
#' @param colData whether colData should be included in the tidied output
#' for those in the DESeqTransform object.
#' @param ... extra arguments (not used)
#'
@tavareshugo
tavareshugo / prcomp_DESeqTransform.R
Last active March 6, 2024 14:25
Principal Component Analysis on Bioconductor/DESeq2 object
#' Perform Principal Components Analysis on a DESeqTransform object
#'
#' This function is based on the `DESeq2::plotPCA()` function, but returns the
#' results of `prcomp` in a tidy list format. This is more flexible for further
#' custom plotting and exploring factor loadings of the PCA.
#'
#' @param x an object of class DESeqTransform
#' @ntop number of most-variable genes to select. Igored if "genes" is specified.
#' @genes character vector of specific genes to use
#'