Skip to content

Commit

Permalink
REsolved merge conflict by keeping only develop version
Browse files Browse the repository at this point in the history
  • Loading branch information
Katerina Boufea committed May 17, 2019
2 parents 7beff80 + 2b0d1c5 commit c7d3236
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
13 changes: 1 addition & 12 deletions R/find_markers.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<<<<<<< HEAD
#' @export
find_markers <- function(reference_gem, reference_clusters, logFC) {
so_ref <- Seurat::CreateSeuratObject(raw.data = reference_gem)
so_ref <- suppressMessages(Seurat::NormalizeData(so_ref))
so_ref <- suppressMessages(Seurat::ScaleData(so_ref))
so_ref@ident <- as.factor(reference_clusters)

markers <- suppressMessages(Seurat::FindAllMarkers(so_ref, test.use = "MAST", only.pos = TRUE, logfc.threshold = logFC))
=======
#' Function to extract cluster specific genes from reference clusters.
#' This function uses MAST test as implemented in the Seurat package.
#' @param reference_gem Data frame of gene expression (rows) per cell (columns) in reference data
Expand All @@ -27,7 +17,6 @@ find_markers <- function(reference_gem, reference_clusters, logFC, only.pos, nor
so_ref <- suppressMessages(ScaleData(so_ref))
Idents(so_ref) <- as.factor(reference_clusters)
markers <- suppressMessages(FindAllMarkers(so_ref, test.use = "MAST", only.pos = only.pos, logfc.threshold = logFC))
>>>>>>> develop

return(markers)
}
}
16 changes: 13 additions & 3 deletions R/scID.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,18 @@ scid_multiclass <- function(target_gem = NULL, reference_gem = NULL, reference_c
# Stage 1: Find signature genes from reference data
message("Stage 1: extract signatures genes from reference clusters")
markers <- find_markers(reference_gem, reference_clusters, logFC)
# Check if DE genes returned
if (nrow(markers) == 0) {
message("No DE genes identified. Please try again with lower logFC or another reference dataset")
return()
}
# Filter out signature genes that are not present in the target data
markers <- markers[which(markers$gene %in% rownames(target_gem)), ]
# Check if common markers exist
if (nrow(markers) == 0) {
message("None of the DE genes found from the reference are present in the target data.")
return()
}
celltypes <- unique(markers$cluster)
} else {
markers <- markers[which(markers$gene %in% rownames(target_gem)), ]
Expand Down Expand Up @@ -133,7 +143,7 @@ scid_multiclass <- function(target_gem = NULL, reference_gem = NULL, reference_c
signature_genes <- markers$gene[which(markers$cluster == celltypes[i])]
IN <- names(which(reference_clusters == celltypes[i]))
OUT <- setdiff(colnames(reference_gem), IN)
weights[[as.character(celltypes[i])]] <- scID_weight(reference_gem_norm[signature_genes, ], IN, OUT)
weights[[as.character(celltypes[i])]] <- scID_weight(reference_gem_norm[signature_genes, ,drop=FALSE], IN, OUT)
if (i==length(celltypes)) cat("Done!")
}
} else {
Expand All @@ -142,7 +152,7 @@ scid_multiclass <- function(target_gem = NULL, reference_gem = NULL, reference_c
Sys.sleep(1 / length(celltypes))
signature_genes <- markers$gene[which(markers$cluster == celltypes[i])]
putative_groups <- choose_unsupervised(target_gem[markers$gene, ], signature_genes)
weights[[as.character(celltypes[i])]] <- scID_weight(target_gem_norm[signature_genes, ], putative_groups$in_pop, putative_groups$out_pop)
weights[[as.character(celltypes[i])]] <- scID_weight(target_gem_norm[signature_genes, , drop=FALSE], putative_groups$in_pop, putative_groups$out_pop)
if (i==length(celltypes)) cat("Done!")
}
}
Expand All @@ -161,7 +171,7 @@ scid_multiclass <- function(target_gem = NULL, reference_gem = NULL, reference_c
# svMisc::progress(i*100/length(celltypes))
# Sys.sleep(1/length(celltypes))
signature <- names(weights[[as.character(celltypes[i])]])
weighted_gem <- weights[[as.character(celltypes[i])]] * target_gem_norm[signature, ]
weighted_gem <- weights[[as.character(celltypes[i])]] * target_gem_norm[signature, , drop=FALSE]
score <- colSums(weighted_gem)/sum(weights[[as.character(celltypes[i])]])
matches <- final_populations(score, likelihood_threshold)
scores[as.character(celltype), matches] <- scale(score[matches])
Expand Down

0 comments on commit c7d3236

Please sign in to comment.