Skip to content

Instantly share code, notes, and snippets.

setMethod("normFactors", signature(object="MRexperiment"),
function(object) {
nf <- pData(obj@expSummary$expSummary)[["normFactors"]]
nf <- unlist(nf)
names( nf ) <- sampleNames(object)
nf
})
setReplaceMethod("normFactors", signature(object="MRexperiment", value="numeric"),
function( object, value ) {
@jnpaulson
jnpaulson / import_biom2.R
Last active February 22, 2018 01:47
This will convert a biom class object into a phyloseq object.
import_biom2 <- function(x,
treefilename=NULL, refseqfilename=NULL, refseqFunction=readDNAStringSet, refseqArgs=NULL,
parseFunction=parse_taxonomy_default, parallel=FALSE, version=1.0, ...){
# initialize the argument-list for phyloseq. Start empty.
argumentlist <- list()
x = biom(x)
b_data = biom_data(x)
b_data_mat = as(b_data, "matrix")
@jnpaulson
jnpaulson / merge_hmp_msd16s
Created May 8, 2015 21:39
merge hmp and msd16s
load("HMPv35_100nt.biom_MRexperiment.rdata")
library(msd16s)
k = which(pData(obj)$bodysite == "UBERON_stool")
obj = obj[,k]
mergeData = function(o1,o2,norm=FALSE){
o1names = rownames(o1)
o2names = rownames(o2)
@jnpaulson
jnpaulson / springer-free-maths-books.md
Created December 29, 2015 15:14 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of books available for free, here are the direct links
@jnpaulson
jnpaulson / continentInfo.tsv
Created February 3, 2016 21:46
Country and continent information
Algeria Africa
Angola Africa
Benin Africa
Botswana Africa
Burkina Faso Africa
Burundi Africa
Cameroon Africa
Cape Verde Africa
Central African Republic Africa
Chad Africa
@jnpaulson
jnpaulson / server.R
Created May 12, 2016 14:03 — forked from xiaodaigh/server.R
A gist of programatically changing panel tabs in Shiny
library(shiny)
# Define server logic for random distribution application
shinyServer(function(input, output) {
# Reactive expression to generate the requested distribution. This is
# called whenever the inputs change. The renderers defined
# below then all use the value computed from this expression
data <- reactive({
dist <- switch(input$dist,
@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')\""
@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 / 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 / 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