From 765a361d517adefc8cb806bb7030399deaf13178 Mon Sep 17 00:00:00 2001 From: LTLA Date: Sun, 22 Dec 2024 22:43:17 -0800 Subject: [PATCH] Test and document that weights=NULL is supported for unweighted graphs. --- CMakeLists.txt | 2 +- include/scran_graph_cluster/cluster_leiden.hpp | 1 + include/scran_graph_cluster/cluster_multilevel.hpp | 1 + include/scran_graph_cluster/cluster_walktrap.hpp | 1 + tests/src/cluster_leiden.cpp | 13 +++++++++++++ tests/src/cluster_multilevel.cpp | 9 +++++++++ tests/src/cluster_walktrap.cpp | 9 +++++++++ 7 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2cbe36..a6d8830 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.14) project(scran_graph_cluster - VERSION 0.1.2 + VERSION 0.1.3 DESCRIPTION "Cluster cells using graph-based methods" LANGUAGES CXX) diff --git a/include/scran_graph_cluster/cluster_leiden.hpp b/include/scran_graph_cluster/cluster_leiden.hpp index 50dabb1..f9e43b1 100644 --- a/include/scran_graph_cluster/cluster_leiden.hpp +++ b/include/scran_graph_cluster/cluster_leiden.hpp @@ -85,6 +85,7 @@ struct ClusterLeidenResults { * @param graph An existing graph. * @param weights Pointer to an array of weights of length equal to the number of edges in `graph`. * This should be in the same order as the edge list in `graph`. + * Alternatively `NULL`, if the graph is unweighted. * @param options Further options. * @param[out] output On output, this is filtered with the clustering results. * The input value is ignored, so this object can be re-used across multiple calls to `cluster_leiden()`. diff --git a/include/scran_graph_cluster/cluster_multilevel.hpp b/include/scran_graph_cluster/cluster_multilevel.hpp index 37be82d..3e939ef 100644 --- a/include/scran_graph_cluster/cluster_multilevel.hpp +++ b/include/scran_graph_cluster/cluster_multilevel.hpp @@ -78,6 +78,7 @@ struct ClusterMultilevelResults { * @param graph An existing graph. * @param weights Pointer to an array of weights of length equal to the number of edges in `graph`. * This should be in the same order as the edge list in `graph`. + * Alternatively `NULL`, if the graph is unweighted. * @param options Further options. * @param[out] output On output, this is filtered with the clustering results. * The input value is ignored, so this object can be re-used across multiple calls to `cluster_multilevel()`. diff --git a/include/scran_graph_cluster/cluster_walktrap.hpp b/include/scran_graph_cluster/cluster_walktrap.hpp index 8c22820..f24ccc1 100644 --- a/include/scran_graph_cluster/cluster_walktrap.hpp +++ b/include/scran_graph_cluster/cluster_walktrap.hpp @@ -74,6 +74,7 @@ struct ClusterWalktrapResults { * @param graph An existing graph. * @param weights Pointer to an array of weights of length equal to the number of edges in `graph`. * This should be in the same order as the edge list in `graph`. + * Alternatively `NULL`, if the graph is unweighted. * @param options Further options. * @param[out] output On output, this is filtered with the clustering results. * The input value is ignored, so this object can be re-used across multiple calls to `cluster_walktrap()`. diff --git a/tests/src/cluster_leiden.cpp b/tests/src/cluster_leiden.cpp index cab908f..3928a91 100644 --- a/tests/src/cluster_leiden.cpp +++ b/tests/src/cluster_leiden.cpp @@ -70,3 +70,16 @@ TEST(ClusterLeiden, Sanity) { validate(output.membership, nclusters); } } + +TEST(ClusterLeiden, Unweighted) { + auto mock = mock_clusters(899, 6); + + scran_graph_cluster::ClusterLeidenResults output; + scran_graph_cluster::ClusterLeidenOptions opts; + scran_graph_cluster::cluster_leiden(mock.first.get(), NULL, opts, output); + EXPECT_EQ(output.membership.size(), 899); + + opts.modularity = true; + scran_graph_cluster::cluster_leiden(mock.first.get(), NULL, opts, output); + EXPECT_EQ(output.membership.size(), 899); +} diff --git a/tests/src/cluster_multilevel.cpp b/tests/src/cluster_multilevel.cpp index fe570a6..1c86f49 100644 --- a/tests/src/cluster_multilevel.cpp +++ b/tests/src/cluster_multilevel.cpp @@ -82,3 +82,12 @@ TEST(ClusterMultilevel, Sanity) { auto output = scran_graph_cluster::cluster_multilevel(mock.first, mock.second, opts); validate(output.membership, nclusters); } + +TEST(ClusterMultilevel, Unweighted) { + auto mock = mock_clusters(899, 6); + + scran_graph_cluster::ClusterMultilevelResults output; + scran_graph_cluster::ClusterMultilevelOptions opts; + scran_graph_cluster::cluster_multilevel(mock.first.get(), NULL, opts, output); + EXPECT_EQ(output.membership.size(), 899); +} diff --git a/tests/src/cluster_walktrap.cpp b/tests/src/cluster_walktrap.cpp index 149e6c6..0bbee59 100644 --- a/tests/src/cluster_walktrap.cpp +++ b/tests/src/cluster_walktrap.cpp @@ -59,3 +59,12 @@ TEST(ClusterWalktrap, Sanity) { auto output = scran_graph_cluster::cluster_walktrap(mock.first, mock.second, opts); validate(output.membership, nclusters); } + +TEST(ClusterWalktrap, Unweighted) { + auto mock = mock_clusters(899, 6); + + scran_graph_cluster::ClusterWalktrapResults output; + scran_graph_cluster::ClusterWalktrapOptions opts; + scran_graph_cluster::cluster_walktrap(mock.first.get(), NULL, opts, output); + EXPECT_EQ(output.membership.size(), 899); +}