Commit 1f1e6aee authored by Bagueneau Mathias's avatar Bagueneau Mathias
Browse files

- Optimisations

parent a039cda0
This diff is collapsed.
......@@ -69,7 +69,7 @@ print("The Grid page allows a great visualization for genes plots.
In this page, you could choose many genes to visualize. Some presets are available to show genes plots depending a cell type, a pathway, ...
You could also change some parameters, like the graph mode or the number of columns you want.
The grid plot is exportable in .png.")}
## Functions to customize the Grid Presets ----
## Grid page : Functions to customize the Grid Presets ----
# First : if you want to add a preset, add it into "choices" here :
PresetsGrid <- function() {
selectInput(inputId = "presets_grid",
......
......@@ -94,7 +94,7 @@ SelectionInformation <- function(obj, input_class_selector) {
}
## Compare : Data for the plots function ----
## Compare page : Data for the plots function ----
CellsToPlot <- function(obj, class, group, add, addclass, addgroup) {
data <- SubsetData(object = obj,
cells=rownames(obj@meta.data)[which(eval(parse(text=paste0("obj@meta.data$",class))) %in% group)] )
......@@ -104,12 +104,12 @@ CellsToPlot <- function(obj, class, group, add, addclass, addgroup) {
}
return(data)
}
## Compare : Meta.data for csv export function ----
## Compare page : Meta.data for csv export function ----
MetaData <- function(cells, obj) {
data <- data.frame(FetchData(cells,
names(rapply(obj@meta.data, class=c("factor","character","numeric","integer"), f=class))))
}
## Compare : Scale color for feature plots ----
## Compare page : Scale color for feature plots ----
ScaleColors <- function(obj, var, cells) {
palette.full <- c("lightgrey", plasma(200))
data.max.global <- max(FetchData(obj, var))
......@@ -117,3 +117,37 @@ ScaleColors <- function(obj, var, cells) {
palette.local <- palette.full[1:ceiling(length(palette.full) * data.max.local / data.max.global)]
return(palette.local)
}
## Compare page : Custom FindMarkers function ----
FindMakersCompare <- function(tempdata, group1, group2, addgroup1, addgroup2, class, word) {
df <- withProgress(data.frame(FindMarkers(tempdata,
paste0(group1, addgroup1),
paste0(group2, addgroup2),
test.use = "MAST")), message = "Preparing data", value=1)
setDT(df, keep.rownames = TRUE)[]
df <- data.frame(c(df,(class)))
names(df)[[4]] <- paste("pct.",sapply(group1, paste, collapse=""), collapse=" + ",as.character(word),sapply(addgroup1, paste, collapse=""))
names(df)[[5]] <- paste("pct.",sapply(group2, paste, collapse=""), collapse=" + ",as.character(word),sapply(addgroup2, paste, collapse=""))
names(df)[[1]] <- "Gene"
names(df)[[7]] <- paste("",class)
leftgenes <- df %>% top_n(30, df$avg_logFC)
rightgenes <- df %>% top_n(-30, df$avg_logFC)
findmarkers_compare_results <- list("findmarkers_compareData" = df, "leftgenes_compare" = leftgenes, "rightgenes_compare" = rightgenes)
return(findmarkers_compare_results)
}
## Compare page : Gene Ontology function ----
FindOntologyCompare <- function(gene_list, ontology_mode) {
gene_chain <- strsplit(gene_list, "\n")
genes <- bitr(gene_chain[[1]],
fromType = "SYMBOL",
toType = "ENTREZID",
OrgDb = org.Hs.eg.db,drop = TRUE)
gene_ontology <- withProgress(enrichGO(gene = genes$ENTREZID,
OrgDb = "org.Hs.eg.db",
keyType= "ENTREZID",
ont = ontology_mode,
readable = TRUE), value = 1, message = "Ontology in progress...")
GOdata <- data.table(gene_ontology@result$Description, gene_ontology@result$GeneRatio, gene_ontology@result$pvalue, gene_ontology@result$p.adjust)[which(gene_ontology@result$Count > 2)]
colnames(GOdata) <- c("Description","Gene Ratio","P-value","FDR")
return(GOdata)
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment