Skip to content

Instantly share code, notes, and snippets.

@oganm
Created February 20, 2018 00:42
Show Gist options
  • Save oganm/546469325851cfa376c453b0444d8c79 to your computer and use it in GitHub Desktop.
Save oganm/546469325851cfa376c453b0444d8c79 to your computer and use it in GitHub Desktop.
CellCODE with gene lists
library(CellCODE)
library(dplyr)
library(purrr)
library(magrittr)
library(markerGeneProfile)
data('mouseMarkerGenesCombined')
# this function will turn gene lists into CellCODE inputs
cellCodeInput = function(genes){
geneCount = genes %>% map(length)
allGenes = genes %>% unlist %>% unique
tags = genes %>% lapply(function(x){
out = rep(0,length(allGenes))
out[allGenes %in% x] = 1
return(out)
}) %>% as.data.frame()
rownames(tags) = allGenes
return(tags)
}
# this is marker gene input
geneList = mouseMarkerGenesCombined$Cortex %>% map(mouse2human) %>% map('humanGene')
# remove genes that are not in the dataset
geneList %<>% map(function(x){
x[x %in% rownames(cortex_white)]
})
# code works with gene count > 2. Not sure why but it is a decent cutoff anyway
geneList = geneList[sapply(geneList,length)>2]
tagList = cellCodeInput(geneList)
# dataset input is a MATRIX (not data frame) with genes as rownames
cortex_white = trabzuniRegionsExp[, c(trabzuniRegionsMeta$brainRegion %in% c('frontal cortex', 'white matter'))]
groups = trabzuniRegionsMeta$brainRegion[trabzuniRegionsMeta$brainRegion %in% c('frontal cortex', 'white matter')]
SPVs=getAllSPVs(data = cortex_white %>% as.matrix(),
grp = groups %>% as.factor,
dataTag = tagList,
method = "mixed",
plot = T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment