Skip to content

Instantly share code, notes, and snippets.

@jnpaulson
jnpaulson / gtex_de.R
Created February 1, 2021 06:57
GTEx download of 6p and DE for lung + whole blood
# Actually perform the differential expression analysis
library(yarn)
library(dplyr)
library(readr)
library(biomaRt)
library(limma)
source("voomweights.R")
obj <- readRDS("~/Desktop/gtex_v6p_lung_blood_norm.rds")
gender = pData(obj)$GENDER
batch = factor(as.character(pData(obj)$SMNABTCHT))
@jnpaulson
jnpaulson / rnaseqTools_install.R
Last active April 22, 2019 19:24
Installation code for rnaseqTools
downloadNotInstalled<-function(x){
for(i in x){
if(!require(i,character.only=TRUE)){
if (!requireNamespace("BiocManager")){install.packages("BiocManager")}
BiocManager::install(i)
}
}
}
requiredPackages = c("Biobase", "S4Vectors","SummarizedExperiment","devtools","edgeR")
downloadNotInstalled(requiredPackages)
@jnpaulson
jnpaulson / stratified.R
Created November 15, 2017 06:29 — forked from mrdwab/stratified.R
Stratified random sampling from a `data.frame` in R
stratified <- function(df, group, size, select = NULL,
replace = FALSE, bothSets = FALSE) {
if (is.null(select)) {
df <- df
} else {
if (is.null(names(select))) stop("'select' must be a named list")
if (!all(names(select) %in% names(df)))
stop("Please verify your 'select' argument")
temp <- sapply(names(select),
function(x) df[[x]] %in% select[[x]])
@jnpaulson
jnpaulson / monotone_spline.R
Created February 2, 2017 20:03 — forked from willtownes/monotone_spline.R
monotone splines using package mgcv
library(mgcv)
#library(modules) #devtools::install_github(klmr/modules)
#mgcv<-import_package("mgcv")
mspline<-function(x,y,k=10,lower=NA,upper=NA){
#fits a monotonic spline to data
#small values of k= more smoothing (flatter curves)
#large values of k= more flexible (wiggly curves)
#k is related to effective degrees of freedom and number of knots
#use unconstrained gam to get rough parameter estimates
###########################
# Load Required Libraries #
###########################
library(vegan) # TSS Normalization
library(data.table) # fread
# Install MetagenomeSeq (EM_ZIG Model)
library(devtools)
# install_github('HCBravoLab/metagenomeSeq', ref='per_feature_em')
library(metagenomeSeq) #FIT-ZIG
---
title: "Beginner R Workshop"
output: html_document
date: October 27, 2016
author: Keegan Korthauer and Joseph N. Paulson
---
Today's workshop will be a gentle introduction to the
[R programming language](https://cran.r-project.org/). We have provided RStudio Server instances that you can access on the web, but we'll also briefly overview how you can install R and RStudio on your own computer. We'll start with some basics about programming and then get some hands-on experience with analyzing a real-world messy dataset that we'll collect from everyone live. We hope that you'll get a feel for what R can do as well as learn where you can learn more to use it on your own (great resources are listed at the end).
@jnpaulson
jnpaulson / gtex.R
Last active November 5, 2019 08:01
library(yarn)
library(dplyr)
library(rafalib)
obj = downloadGTEx()
lowSampleSizes = c("Bladder","Cells - Leukemia cell line (CML)","Cervix - Ectocervix","Cervix - Endocervix","Fallopian Tube")
obj = filterSamples(obj,lowSampleSizes,"SMTSD") %>%
filterMissingGenes
@jnpaulson
jnpaulson / EDA.RMD
Created August 23, 2016 17:23
EDA Shiny Rmarkdown script
---
title: "Shiny App"
author: "jpaulson"
output: html_document
runtime: shiny
---
This R Markdown document is made interactive using Shiny and allows you to explore an eSet object.
# Examples
@jnpaulson
jnpaulson / mergeMRexperiments.R
Created August 9, 2016 16:27
function to merge two MRexperiments
extractMR<-function(obj){
mat = MRcounts(obj)
ls = as.vector(libSize(obj))
norm= as.vector(normFactors(obj))
pd = pData(obj)
fd = fData(obj)
dat = list(counts=mat,librarySize=ls,normFactors=norm,pheno=pd,feat=fd)
return(dat)
}
@jnpaulson
jnpaulson / shiny_server.sh
Last active July 22, 2021 10:45
shiny server
sudo sh -c 'echo "deb http://cran.rstudio.com/bin/linux/ubuntu trusty/" &gt;&gt; /etc/apt/sources.list'
gpg --keyserver keyserver.ubuntu.com --recv-key E084DAB9
gpg -a --export E084DAB9 | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install r-base libapparmor1 libcurl4-gnutls-dev libxml2-dev libssl-dev gdebi-core
sudo su - -c "R -e \"install.packages('shiny', repos = 'http://cran.rstudio.com/')\""
sudo su - -c "R -e \"install.packages('devtools', repos='http://cran.rstudio.com/')\""
sudo su - -c "R -e \"devtools::install_github('daattali/shinyjs')\""
sudo su - -c "R -e \"devtools::install_github('bioc/shinyjs')\""