Skip to content

Instantly share code, notes, and snippets.

View Jfortin1's full-sized avatar
🏠
Working from home

Jean-Philippe Fortin Jfortin1

🏠
Working from home
View GitHub Profile
@Jfortin1
Jfortin1 / killscreens.sh
Created December 6, 2014 03:19
To kill all your screen sessions
killscreens () {
screen -ls | grep Detached | cut -d. -f1 | awk '{print $1}' | xargs kill
}
@Jfortin1
Jfortin1 / getLocations.R
Created January 5, 2015 18:23
To get the locations of the 450k probes
library(IlluminaHumanMethylation450kanno.ilmn12.hg19)
locations <- getLocations(IlluminaHumanMethylation450kanno.ilmn12.hg19)
@Jfortin1
Jfortin1 / tar.sh
Created February 5, 2015 16:54
Stupid tar command I always forget
tar -zxvf
@Jfortin1
Jfortin1 / llapply.R
Last active August 29, 2015 14:17
Useful apply functions
pair.lapply <- function(list1, list2, fun, list3=NULL){
results <- list()
for (i in 1:length(list1)){
if (is.null(list3)){
results[[i]] <- do.call(fun, list(list1[[i]],list2[[i]]))
} else {
results[[i]] <- do.call(fun, list(list1[[i]][list3[[i]]],list2[[i]][list3[[i]]]))
}
}
@Jfortin1
Jfortin1 / getCorrelation.R
Created March 24, 2015 21:50
Before I forget
D <- split(as.data.frame(M), A)
correlations <- llapply(D,D,getCorrelation)
llapply <- function(list1,list2, fun){
temp <- unlist(lapply(list1, function(x){
unlist(lapply(list2, function(y){
do.call(fun, list(x,y))
}))
}))
@Jfortin1
Jfortin1 / liftOverFunctions.sh
Last active August 29, 2015 14:17
liftOver functions
#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
@Jfortin1
Jfortin1 / darken.R
Last active September 2, 2023 20:42
Darken or lighten colors in R
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)
@Jfortin1
Jfortin1 / fastq.gz
Created April 23, 2015 23:30
SRA to zipped fastq
fastq-dump file.sra -Z | gzip > file.fastq.gz
@Jfortin1
Jfortin1 / getR2.R
Last active August 29, 2015 14:20
getR2.R
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
}
Reduce(intersect, list(a,b,c,d))