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 / extract.portion.R
Created November 20, 2014 22:54
Extract only a portion of a bigWig file
extract.portion <- function(file, chr, start, end, verbose = TRUE){
rl <- IRanges::RangesList(IRanges::IRanges(start=start, end=end))
names(rl) <- chr
portion <- import(file, as="Rle",format = "bw", selection = BigWigSelection(rl))
portion <- portion[chr]
portion <- as.numeric(portion[[chr]])
portion
}
@Jfortin1
Jfortin1 / extractMetaGsm.R
Created November 16, 2014 17:13
To obtain metadata from GSM**** files
library(GEOquery)
extractMetaGsm <- function(GEO){
require(GEOquery)
GSElimits=NULL
AnnotGPL=FALSE
destdir <- tempdir()
meta <- list()
for (i in 1:length(GEO)){
@Jfortin1
Jfortin1 / getPCS.R
Created November 14, 2014 19:48
Fast eigenvalue decomposition for first 2 pcs
getPCS <- function(matrix, ncomp=2){
require(mixOmics)
nipals(matrix, ncomp = ncomp)$p
}
@Jfortin1
Jfortin1 / makeAutosomal.R
Last active August 10, 2022 17:20
To remove sex chromosome probes from a 450k matrix
makeAutosomal <- function(matrix){
require(IlluminaHumanMethylation450kanno.ilmn12.hg19)
ann <- getAnnotation(IlluminaHumanMethylation450kanno.ilmn12.hg19)
good.probes <- rownames(ann)[-which(ann$chr=="chrX" | ann$chr=="chrY")]
matrix[rownames(matrix) %in% good.probes,]
}
makeX <- function(matrix){
require(IlluminaHumanMethylation450kanno.ilmn12.hg19)
@Jfortin1
Jfortin1 / getSnpBeta.R
Created August 1, 2014 19:34
To get the Beta values for the 65 SNP probes
# object must be an RGChannelSet object from the minfi package
getSnpBeta <- function(object){
require(minfi)
minfi:::.isRG(object)
manifest <- getManifest(object)
snpProbesII <- getProbeInfo(manifest, type = "SnpII")$Name
M.II <- getGreen(object)[getProbeInfo(object, type = "SnpII")$AddressA,]