This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| splitByRow <- function(Y, f){ | |
| require(tidyverse) | |
| names <- dimnames(Y) | |
| Y <- as.matrix(Y); dimnames(Y) <- names | |
| #levels <- sort(unique(f)) %>% as.character | |
| temp <- split(Y, f=f) | |
| names <- names(temp) | |
| ns <- table(f)[names] | |
| temp <- lapply(1:length(temp), function(i){ | |
| x <- matrix(temp[[i]], ncol=ncol(Y), nrow=ns[[i]], byrow=FALSE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| tstat.ord <- fit$coef / fit$stdev.unscaled / fit$sigma |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ComBat2 <- function(dat, batch, mod=NULL, par.prior=TRUE,prior.plots=FALSE,mean.only=FALSE,ref.batch=NULL, verbose=FALSE) { | |
| # make batch a factor and make a set of indicators for batch | |
| require(sva) | |
| if(mean.only==TRUE){ | |
| cat("Using the 'mean only' version of ComBat\n") | |
| } | |
| if(length(dim(batch))>1){ | |
| stop("This version of ComBat only allows one batch variable") | |
| } ## to be updated soon! | |
| batch <- as.factor(batch) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getMNITemplatePath <- function(what=c("full", "brain", "brain_mask"), res=c("1mm", "2mm")){ | |
| require(fslr) | |
| dir <- file.path(fsl_data_dir(), "standard") | |
| what <- match.arg(what) | |
| res <- match.arg(res) | |
| if (what == "full") { | |
| file <- file.path(dir, paste0("MNI152_T1_",res,".nii.gz")) | |
| } | |
| else if (what == "brain") { | |
| file <- file.path(dir, paste0("MNI152_T1_",res,"_brain.nii.gz")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Wrapper to calculate t-statistic from vash with one covariate | |
| getVashT <- function(x, mod, df=NULL, ...){ | |
| require(vashr) | |
| require(limma) | |
| fit <- lmFit(x, mod) | |
| if (is.null(df)){ | |
| df <- ncol(x)-1 | |
| } | |
| temp <- vash(sehat = fit$sigma, df=df, ...) | |
| temp <- fit$coef[,2] / temp$sd.post / fit$stdev.unscaled[,2] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Reduce(intersect, list(a,b,c,d)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| getR2 <- function(Y,X){ | |
| fitted <- t(solve(t(X)%*%X) %*% t(X) %*% t(Y)) %*% t(X) | |
| res <- Y-fitted | |
| Y.demeaned <- t(scale(t(Y), center=TRUE, scale=FALSE)) | |
| ssres <- rowSums(res^2) | |
| sstot <- rowSums(Y.demeaned^2) | |
| 1-ssres/sstot | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fastq-dump file.sra -Z | gzip > file.fastq.gz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| darken <- function(color, factor=1.4){ | |
| col <- col2rgb(color) | |
| col <- col/factor | |
| col <- rgb(t(col), maxColorValue=255) | |
| col | |
| } | |
| lighten <- function(color, factor=1.4){ | |
| col <- col2rgb(color) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Here is how to convert a bigWig file from hg18 to hg19: | |
| bigWigToBedGraph file18.bw hg18.chrom.sizes chfile18.bed | |
| liftOver file18.bed hg18ToHg19.over.chain file19.bed unmapped | |
| bedGraphToBigWig file19.bed hg19.chrom.sizes file19.bw | |
NewerOlder