Skip to content

Commit

Permalink
change
Browse files Browse the repository at this point in the history
  • Loading branch information
yuelyu21 committed May 8, 2024
1 parent a8c6b8c commit 7720ff8
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
^\.github$
^doc$
^Meta$
SCIntRuler.Rproj
^inst$



3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
.DS_Store
.quarto
docs
inst/doc
inst/
/doc/
/Meta/

1 change: 1 addition & 0 deletions R/CalcuSCIR.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ utils::globalVariables(c("P.value", "revDiff", "V2", "finecluster", "rarecluster
#' CalcuSCIR(sim_result[[1]], seuratlist, sim_result[[4]])

CalcuSCIR <- function(fullcluster, seuratlist, testres, p = 0.1){

stopifnot(exprs = {
is.list(fullcluster)
is.list(seuratlist)
Expand Down
6 changes: 3 additions & 3 deletions R/FindCell.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ FindCell <- function(seuratobj,seuratlist,fullcluster, distmat,firstn = 15){
attid <- c()

for (q in seq_len(nclust)){
dist1 <- as.vector(do.call(cbind, distmat[[i]][[1]][[q]])[,1:firstn])
dist2 <- as.vector(do.call(cbind, distmat[[i]][[2]][[q]])[,1:firstn])
dist1 <- as.vector(do.call(cbind, distmat[[i]][[1]][[q]])[,seq_len(firstn)])
dist2 <- as.vector(do.call(cbind, distmat[[i]][[2]][[q]])[,seq_len(firstn)])
disttest[[q]] <- data.frame(rbind(cbind(dist1,rep("Internal Dist",length(dist1))),
cbind(dist2,rep("External Dist",length(dist1)))))%>%
dplyr::mutate(dist = as.numeric(dist1),group = factor(V2)) %>% dplyr::select(3,4)
Expand All @@ -52,7 +52,7 @@ FindCell <- function(seuratobj,seuratlist,fullcluster, distmat,firstn = 15){
testres[q,2] <- round((mean(dist2) - mean(dist1))/max(mean(dist2),mean(dist1)),4)

if(testres[q,1] > 0.9 & testres[q,2] < 0){
print(paste0("Sample",i,"_",q))
# print(paste0("Sample",i,"_",q))
attid <- c(attid,paste0("Sample",i,"_",q))
}

Expand Down
24 changes: 12 additions & 12 deletions R/FindNNDist.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ FindNNDist <- function(fullcluster,normCount, meaningn = 20) {
onemeta <- fullcluster[[j]] # 2400 * 3

tmpvec <- c()
newcounter = 1
newcounter <- 1

# when j = 1, the dimension of othercount is 9763 3500 study 3+ study 2
# when j = 2, the dimension of othercount is 9763 4800 study 1+ study 3
# when j = 3, the dimension of othercount is 9763 4800 study 2+ study 3
for(qqq in seq_along(fullcluster)) {
if(qqq != j) {
if(newcounter == 1) {
othercount = normCount[[qqq]]
newcounter = newcounter + 1
othercount <- normCount[[qqq]]
newcounter <- newcounter + 1
} else {
othercount = cbind(othercount, normCount[[qqq]])
othercount <- cbind(othercount, normCount[[qqq]])
}
}
}
Expand All @@ -84,9 +84,9 @@ FindNNDist <- function(fullcluster,normCount, meaningn = 20) {
for(q in seq_along(allCT)) {
# print(q)

ct = allCT[q]
ct <- allCT[q]

onecdist_internal = onecdist_external <- list()
onecdist_internal <- onecdist_external <- list()

max1 <- sum(onemeta$finecluster == ct)
max2 <- sum(onemeta$finecluster != ct)
Expand All @@ -97,16 +97,16 @@ FindNNDist <- function(fullcluster,normCount, meaningn = 20) {
# onecount 9763 x 2400 othercount 9763 * 3500

# otherc_external 9763 * 1000
otherc_external <- as.matrix(othercount[,sample(1:ncol(othercount), min(500*length(normCount[-j]), ncol(othercount))) ])
otherc_external <- as.matrix(othercount[,sample(seq_len(ncol(othercount)), min(500*length(normCount[-j]), ncol(othercount))) ])
# sample(1: 3500 , min(500* 2 , 3500. )

for(nnn in seq_along(ncol(subc))) {
## tmp dim 1 * 500
tmp <- sort(sqrt(Matrix::colSums(sweep(otherc, 1, subc[,nnn], "-")^2)))[1:meaningn]
tmp <- sort(sqrt(Matrix::colSums(sweep(otherc, 1, subc[,nnn], "-")^2)))[seq_len(meaningn)]
onecdist_internal[[nnn]] <- tmp

## tmp1 dim 1 * 1000
tmp1 <- sort(sqrt(Matrix::colSums(sweep(otherc_external, 1, subc[,nnn], "-")^2)))[1:meaningn]
tmp1 <- sort(sqrt(Matrix::colSums(sweep(otherc_external, 1, subc[,nnn], "-")^2)))[seq_len(meaningn)]
onecdist_external[[nnn]] <- tmp1
}

Expand All @@ -125,8 +125,8 @@ FindNNDist <- function(fullcluster,normCount, meaningn = 20) {
# ksout <- t.test(dist1, dist2)
# onep_vec[q] <- ksout$p.value
}
names(onep_internal) <- paste0("Cluster-",seq(1:length(allCT)),"-dist1")
names(onep_external) <- paste0("Cluster-",seq(1:length(allCT)),"-dist2")
names(onep_internal) <- paste0("Cluster-",seq(seq_len(length(allCT))),"-dist1")
names(onep_external) <- paste0("Cluster-",seq(seq_len(length(allCT))),"-dist2")

dist_mat[[j]] <- list(onep_internal,onep_external)

Expand All @@ -135,6 +135,6 @@ FindNNDist <- function(fullcluster,normCount, meaningn = 20) {
}
close(pb)

names(dist_mat) <- paste0("sample-",seq(1:length(fullcluster)))
names(dist_mat) <- paste0("sample-",seq(seq_len(length(fullcluster))))
return(dist_mat)
}
12 changes: 6 additions & 6 deletions R/FindNNDistC.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,29 @@ FindNNDistC <- function(fullcluster,normCount, meaningn = 20) {
onemeta <- fullcluster[[j]]

tmpvec <- c()
newcounter = 1
newcounter <- 1

for(qqq in seq_along(fullcluster)) {
if(qqq != j) {
if(newcounter == 1) {
othercount = normCount[[qqq]]
newcounter = newcounter + 1
othercount <- normCount[[qqq]]
newcounter <- newcounter + 1
} else {
othercount = cbind(othercount, normCount[[qqq]])
othercount <- cbind(othercount, normCount[[qqq]])
}
}
}


allCT <- sort(unique(onemeta$finecluster))

onep_internal = onep_external = list()
onep_internal <- onep_external = list()

for(q in seq_along(allCT)) {

ct = allCT[q]

onecdist_internal = onecdist_external <- list()
onecdist_internal <- onecdist_external <- list()

max1 <- sum(onemeta$finecluster == ct)
max2 <- sum(onemeta$finecluster != ct)
Expand Down
2 changes: 1 addition & 1 deletion R/GetCluster.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ GetCluster <- function(seuratlist,n1 = 50,n2 = 200) {
onedata <- Seurat::ScaleData(onedata, features = all.genes)
onedata <- Seurat::RunPCA(onedata,
features = Seurat::VariableFeatures(object = onedata),seed.use = sample(1000,1))
onedata <- Seurat::FindNeighbors(onedata, dims = 1:20)
onedata <- Seurat::FindNeighbors(onedata, dims = seq_len(20))
onedata <- Seurat::FindClusters(onedata, resolution = 0.5)
allcluster[[i]] <- onedata$seurat_clusters
}
Expand Down
2 changes: 1 addition & 1 deletion R/SCIntRuler-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' robust and accurate analyses.
#' @author Yue Lyu
#'
#'
#' @return This is the main page for SCIntRuler package.
#' @section Features:
#' \itemize{
#' \item{Informed Decision Making: Helps researchers decide on the necessity
Expand Down
6 changes: 3 additions & 3 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#' @format An example PBMC data with SingleCellExperiment format
#' \describe{
#' \item{\code{int_elementMetadata}}{A DataFrame with 3000 rows and 1 column, storing simulated gene information.}
#' \item{\code{int_colData}}{A DataFrame with 800 rows and 3 columns, representing metadata for each cell such as condition, cell type, and treatment group.}
#' \item{\code{int_colData}}{A DataFrame with 800 rows and 3 columns, representing metadata for each cell.}
#' \item{\code{int_metadata}}{A list containing two elements that provide additional global metadata about the experiment.}
#' \item{\code{rowRanges}}{A CompressedGRangesList object providing genomic range data associated with each row/gene.}
#' \item{\code{colData}}{A DataFrame with 800 rows and 8 columns, detailing cell-level metadata including phenotypic traits and experimental conditions.}
#' \item{\code{assays}}{A SimpleAssay object with matrix dimensions 3000x800, representing the gene expression matrix with 3000 genes across 800 cells.}
#' \item{\code{colData}}{A DataFrame with 800 rows and 8 columns, detailing cell-level metadata.}
#' \item{\code{assays}}{A SimpleAssay object with matrix dimensions 3000x800, representing the gene expression matrix.}
#' \item{\code{elementMetadata}}{A DataFrame linked with assays, providing gene-level metadata.}
#' }
#' @details
Expand Down
3 changes: 3 additions & 0 deletions man/SCIntRuler-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/sim_data_sce.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/testthat/test-SCEtoSeurat.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
library(S4Vectors)
test_that("SCEtoSeurat", {
data("sim_data_sce")

Expand Down

0 comments on commit 7720ff8

Please sign in to comment.