Skip to content

Commit

Permalink
check correction
Browse files Browse the repository at this point in the history
  • Loading branch information
debsin committed Aug 29, 2019
1 parent ca6f5ea commit f450157
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
4 changes: 2 additions & 2 deletions R/clustering.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ Cluster<-function(object,
use.previous = FALSE, ...){

invisible(gc())
if(any(names(reducedDims(object))=="CComponents"))
use.reduced.dims = "CComponents"

# If using integrated embeddings for clustering
if(!is.null(use.reduced.dims)){
if(any(object@metadata[["dropClust"]]=="Correction"))
use.reduced.dims = "CComponents"
mat = reducedDim(object, use.reduced.dims)

cat("Clustering on embedded dimensions...")
Expand Down
2 changes: 1 addition & 1 deletion R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Merge<-function(objects, use.de.genes = TRUE){
SummarizedExperiment::colData(mix.data)$Batch = batch

if(use.de.genes){
common_genes_de = intersect(unique(as.vector(unlist(all_de_genes))), unique(unlist(merge_genes)))
common_genes_de = intersect(unique(as.vector(unlist(all_de_genes))), unique(unlist(common_genes)))
SummarizedExperiment::rowData(mix.data)$CommonDEGenes = rep(FALSE, nrow(mix.data))
SummarizedExperiment::rowData(mix.data)$CommonDEGenes[which(rownames(mix.data) %in% common_genes_de)]<- TRUE
}
Expand Down
4 changes: 2 additions & 2 deletions compararisons/CellBench/compare_correction.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library(SingleCellExperiment)
library("magrittr")
## CellBench dataset

load("C:/Projects/CellBench/CellBench_data-master/data/sincell_with_class.RData")
load("C:/Projects/data/Cellbench/sincell_with_class.RData")
load("~/GitHub/dropclust_benchmarks/analysis/bc/Cellbench/out_gene_ids.Rda")

source("compararisons/Cellbench/plots.R")
Expand Down Expand Up @@ -37,7 +37,7 @@ merged_data<-Merge(all.objects)
corrected_data <- Correction(merged_data, close_th = 0.1, cells_th = 0.1,
components = 10, n_neighbors = 20, init = "spca", min_dist = 0.5)

PROJ_c_dc = reducedDim(corrected_data, "iComponents")
PROJ_c_dc = reducedDim(corrected_data, "CComponents")
plot_proj_df_true_dc<-data.frame(Y1 = PROJ_c_dc[,1],Y2 = PROJ_c_dc[,2],
color = as.factor(corrected_data$cell_line),
batch = as.integer(corrected_data$Batch))
Expand Down
22 changes: 17 additions & 5 deletions vignettes/batchCorrection.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ knitr::opts_chunk$set(
```

## Integrative analysis
```{r}
```{r,warning=FALSE,message=FALSE}
library(dropClust)
load(url("https://raw.githubusercontent.com/LuyiTian/CellBench_data/master/data/sincell_with_class.RData"))
Expand Down Expand Up @@ -49,17 +49,29 @@ batch.id = merged_data$Batch
## Perform correction and dimension reduction

```{r}
dc.corr <- Correction(merged_data, close_th = 0.1, cells_th = 0.1,
components = 10, n_neighbors = 30, init = "spca")
set.seed(0)
dc.corr <- Correction(merged_data, method="default", close_th = 0.1, cells_th = 0.1,
components = 10, n_neighbors = 20, init = "spca", min_dist = 0.5)
```

## Perform Clustering on integrated dimensions

```{r}
cc = Cluster(dc.corr,method = "kmeans",centers = 3)
dc.corr = Cluster(dc.corr,method = "default",centers = 3)
```
## Visualizing clusters

Compute 2D embeddings for samples followed by post-hoc clustering.

```{r}
ScatterPlot(dc.corr,title = "Clusters")
PROJ_c_dc = reducedDim(dc.corr, "CComponents")
plot_proj_df_true_dc<-data.frame(Y1 = PROJ_c_dc[,1],Y2 = PROJ_c_dc[,2],
color = as.factor(dc.corr$cell_line),
batch = as.integer(dc.corr$Batch))
batch_plot(plot_proj_df_true_dc,filename = NA, title = "Corrected DC ", type=NULL)
```

## Marker discovery from the merged dataset
```{r}
Expand Down

0 comments on commit f450157

Please sign in to comment.