r3fang / SnapATAC

Analysis Pipeline for Single Cell ATAC-seq
GNU General Public License v3.0
301 stars 125 forks source link

A bug in runClusters.R #62

Open xuzhougeng opened 5 years ago

xuzhougeng commented 5 years ago

I find a small bug in the code of runClusters.R

    }else if(louvain.lib == "leiden"){
        cat("Epoch: finding clusters using leiden\n", file = stderr())      
        data.use = getGraph(obj@graph);     
        set.seed(seed.use);
        obj@cluster <- factor(leiden(data.use, resolution=resolution, ...));

The getGraph(obj@graph) will retrun the obj@graph@mat as the input for leiden.

If the the class of data.use is "dgCMatrix", the leiden will not run successfully, and will give a error message like

Error in r_to_py_impl(x, convert = convert) : 
  Unable to convert R object to Python type

You can reproduce this problem by the following R code

adjacency_matrix <- rbind(cbind(matrix(round(rbinom(4000, 1, 0.8)), 20, 20),
                                matrix(round(rbinom(4000, 1, 0.3)), 20, 20), 
                                matrix(round(rbinom(400, 1, 0.1)), 20, 20)),
                          cbind(matrix(round(rbinom(400, 1, 0.3)), 20, 20), 
                                matrix(round(rbinom(400, 1, 0.8)), 20, 20), 
                                matrix(round(rbinom(4000, 1, 0.2)), 20, 20)),
                          cbind(matrix(round(rbinom(400, 1, 0.3)), 20, 20), 
                                matrix(round(rbinom(4000, 1, 0.1)), 20, 20), 
                                matrix(round(rbinom(4000, 1, 0.9)), 20, 20)))
dgmatrix <- as(adjacency_matrix , "sparseMatrix")
partition <- leiden(dgmatrix)

I think you could add the class check code to avoid this problem.

    }else if(louvain.lib == "leiden"){
        cat("Epoch: finding clusters using leiden\n", file = stderr())      
        data.use = getGraph(obj@graph)
                if ( is ( data.use,  "dgCMatrix") {
                     data.use  = as.matrix(data.use)
                }
        set.seed(seed.use);
        obj@cluster <- factor(leiden(data.use, resolution=resolution, ...));
r3fang commented 5 years ago

Thank you very much! Will correct the error next time when I update the package

-- Rongxin Fang, Ren Lab Ludwig Cancer Research Bioinformatics Ph.D. Student University of California, San Diego

On Jul 23, 2019, at 9:58 PM, xuzhougeng notifications@github.com wrote:

I find a small bug in the code of runClusters.R

}else if(louvain.lib == "leiden"){ cat("Epoch: finding clusters using leiden\n", file = stderr())
data.use = getGraph(obj@graph);
set.seed(seed.use); obj@cluster <- factor(leiden(data.use, resolution=resolution, ...)); The getGraph(obj@graph) will retrun the obj@graph@mat as the input for leiden.

If the the class of data.use is "dgCMatrix", the leiden will not run successfully, and will give a error message like

Error in r_to_py_impl(x, convert = convert) : Unable to convert R object to Python type You can reproduce this problem by the following R code

adjacency_matrix <- rbind(cbind(matrix(round(rbinom(4000, 1, 0.8)), 20, 20), matrix(round(rbinom(4000, 1, 0.3)), 20, 20), matrix(round(rbinom(400, 1, 0.1)), 20, 20)), cbind(matrix(round(rbinom(400, 1, 0.3)), 20, 20), matrix(round(rbinom(400, 1, 0.8)), 20, 20), matrix(round(rbinom(4000, 1, 0.2)), 20, 20)), cbind(matrix(round(rbinom(400, 1, 0.3)), 20, 20), matrix(round(rbinom(4000, 1, 0.1)), 20, 20), matrix(round(rbinom(4000, 1, 0.9)), 20, 20))) dgmatrix <- as(adjacency_matrix , "sparseMatrix") partition <- leiden(dgmatrix) I think you could add the class check code to avoid this problem.

}else if(louvain.lib == "leiden"){ cat("Epoch: finding clusters using leiden\n", file = stderr())
data.use = getGraph(obj@graph) if ( is ( data.use, "dgCMatrix") { data.use = as.matrix(data.use) } set.seed(seed.use); obj@cluster <- factor(leiden(data.use, resolution=resolution, ...)); — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/r3fang/SnapATAC/issues/62?email_source=notifications&email_token=ABT6GG36KFKZKQOCSTYUQ5DQA7OOFA5CNFSM4IGMFPJ2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HBDLMDA, or mute the thread https://github.com/notifications/unsubscribe-auth/ABT6GG3GPXG4TKXP54P6E6DQA7OOFANCNFSM4IGMFPJQ.