Introduction

Load packages and data

library(conos)
library(pheatmap)
library(fuck)
require(pagoda2)

count_matrix <- data.table::fread('/d0-mendel/home/viktor_petukhov/SmallProjects/conos/data/conditions/seurat_islets/indrop/count_matrix.tsv', sep="\t") %>% as.data.frame() %>%
    (function(x) magrittr::set_rownames(as.matrix(x[, 2:ncol(x)]), x$V1)) %>% # set_rownames setting col1 to rownames of all rest
    as("dgCMatrix")
drop_anno_file <- '/d0-mendel/home/viktor_petukhov/SmallProjects/conos/data/conditions/seurat_islets/indrop/design_info.csv'
drop_anno <- drop_anno_file %>% data.table::fread(sep=",",header=T) %>% as.data.frame() 

turn count matrix into a panel list to facilitate copy-pasta with conos tutorial

drop_panel <- fuck::Panelize(count_matrix, drop_anno, 4)

drop.preprocessed <- lapply(drop_panel, basicP2proc, n.cores=25, min.cells.per.gene=0, n.odgenes=2e3, get.largevis=FALSE, make.geneknn=FALSE)

make conos objects of pre-proced panel

con = Conos$new(drop.preprocessed, n.cores=1)
disannot <- setNames(drop_anno$Disease, drop_anno$CellId)
con$plotPanel(groups = disannot,font.size=2)

Do clustering and plot panels

con$plotPanel(clustering="multilevel", use.local.clusters=T, title.size=6)
con$buildGraph(k=15, k.self=10, k.self.weight=0.1, space='PCA', ncomps=50, n.odgenes=2000, matching.method='mNN', metric='angular', verbose=TRUE)

joint clustering

con$findCommunities(method=multilevel.community, min.group.size=0)
con$plotPanel(font.size=4)
con$plotGraph(color.by='sample',mark.groups=F,alpha=0.1,show.legend=T)
con$plotGraph()

create sample groups for DE (input: annotation, category column, sample column)

samplegroups <- fuck::CreateSampleGroups(drop_anno, 5, 4)

But there's only one diabetes sample?

samplegroups

run DE within each cluster

de_drop_multilevel<- getPerCellTypeDE(con, groups=as.factor(con$clusters$`multi level`$groups),sample.groups = samplegroups, ref.level='normal', n.cores=1)

get union of most variable genes across clusters

mostvar = fuck::GetMostvar(de_drop_multilevel, 15)

get mean raw expression values of the genes for each cluster

cluster_exps = fuck::GetClusterExp(con, mostvar, 'multi level')

make a heatmap

pheatmap(mat = cluster_exps,clustering_distance_cols = 'euclidean', clustering_distance_rows = 'euclidean') 

Sanity check

con$plotGraph()
con$plotGraph(gene = "REG1A")


githubz0r/fuck documentation built on May 15, 2019, 10:39 p.m.