Skip to content

Commit

Permalink
add greedy mode for cell pairing
Browse files Browse the repository at this point in the history
  • Loading branch information
lzj1769 committed Sep 22, 2023
1 parent bafa116 commit ef7d1c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Encoding: UTF-8
LazyData: true
URL: https://costalab.github.io/scMEGA/
Depends:
R (>= 4.2.0)
R (>= 4.3.0)
Suggests:
knitr,
rmarkdown,
Expand Down
21 changes: 16 additions & 5 deletions R/pair_cells.R
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ PairCells <- function(object,
ident1 = "ATAC",
ident2 = "RNA",
assay = "RNA",
pair.mode = "greedy",
pair.mode = "knn",
tol = 0.0001,
search.range = 0.2,
max.multimatch = 5,
Expand Down Expand Up @@ -339,12 +339,23 @@ PairCells <- function(object,
all.pairs <- rbind(all.pairs, pair.list)
}
} else if(pair.mode == "greedy"){



n_ATAC <- dim(embedding.atac)[1]
n_RNA <- dim(embedding.rna)[1]

if (n_ATAC >= n_RNA){
print("Pairing all RNA cells to nearest ATAC cells")
pair_knn <- FNN::get.knnx(data = embedding.atac, query = embedding.rna, k = 1)
ATAC_paired <- rownames(embedding.atac)[pair_knn$nn.index]
RNA_paired <- rownames(embedding.rna)
} else{
print("Pairing all ATAC cells to nearest RNA cells")
pair_knn <- FNN::get.knnx(data = embedding.rna, query = embedding.atac, k = 1)
ATAC_paired <- rownames(embedding.rna)[pair_knn$nn.index]
RNA_paired <- rownames(embedding.atac)
}
all.pairs <- data.frame(ATAC=ATAC_paired, RNA=RNA_paired, stringsAsFactors=FALSE)
}


# pairs are sometimes repreated, here we make the results unique
all.pairs <- all.pairs[!duplicated(all.pairs$ATAC),]
all.pairs$cell_name <- paste0("cell_", 1:nrow(all.pairs))
Expand Down

0 comments on commit ef7d1c4

Please sign in to comment.