Skip to content

Instantly share code, notes, and snippets.

---
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).
###########################
# 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
@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
@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 / 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 / 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))