Skip to content

Instantly share code, notes, and snippets.

View kieranrcampbell's full-sized avatar

Kieran R Campbell kieranrcampbell

View GitHub Profile
@kieranrcampbell
kieranrcampbell / snakefile_for_rmarkdown
Created May 12, 2017 08:55
Snakemake to build Rmarkdown files
rule exploratory_analysis:
input:
"data/tec_sceset_qc.rds", "analysis/02_exploratory_analysis.html"
output:
"data/tec_sceset_clusters.rds",
"analysis/02_exploratory_analysis.Rmd",
"data/deseq2_results.csv"
shell:
"Rscript -e \"rmarkdown::render('analysis/02_exploratory_analysis.Rmd')\""
@kieranrcampbell
kieranrcampbell / go_analysis.R
Created May 3, 2017 14:07
Gene ontology enrichment analysis with Goseq
# A function that takes a set of genes and a background list and goes through the
# steps in goseq to output the enriched list
library(goseq)
#' Run all steps for a goseq analysis
#'
#' @param genes The genes "differentially expressed" or in the condition
#' @param all_genes The background gene set
#' @param genome The genome of genes and all_genes, e.g. mm10 or hg19
from edward.models import RandomVariable
import tensorflow as tf
from tensorflow.contrib.distributions import Distribution
class Weibull(RandomVariable, Distribution):
"""Weibull distribution
The Weibull distribution is defined over the non-negative real numbers.
@kieranrcampbell
kieranrcampbell / calc_tpr_fpr_fdr.R
Created March 16, 2017 15:39
Calculate true positive rate, false positive rate & false discovery rate from contingency table in R
## Suppose we have a contigency table tbl formed by the table(...) command in R, with
## a logical vector of discoveries as the first argument and a logical vector of
## the ground truth as the second, e.g. tbl <- table(discoveries, ground_truth), then
## this function calculates the true positive rate, false positive rate and false discovery rate
## as per the wikipedia definition at https://en.wikipedia.org/wiki/Sensitivity_and_specificity
calculate_statistics <- function(tbl) {
P <- sum(tbl[,2])
N <- sum(tbl[,1])
TP <- tbl[2,2]
// [[Rcpp::export]]
NumericMatrix sample_tau_pg(NumericMatrix beta,
double a_beta, double b_beta) {
int P = beta.nrow();
int G = beta.ncol();
NumericMatrix tau_pg(P, G);
for(int p = 0; p < P; p++) {
for(int g = 0; g < G; g++) {
@kieranrcampbell
kieranrcampbell / reproduce-tscan.R
Last active May 20, 2016 14:06
TSCAN applied to small subset of monocle data
library(TSCAN)
set.seed(1)
load("X.rda")
dim(X)
## [1] 228 5
ts <- exprmclust(t(X))