Skip to content

Commit

Permalink
Test and document that weights=NULL is supported for unweighted graphs.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Dec 23, 2024
1 parent 370f679 commit 765a361
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
1 change: 1 addition & 0 deletions include/scran_graph_cluster/cluster_leiden.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down
1 change: 1 addition & 0 deletions include/scran_graph_cluster/cluster_multilevel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down
1 change: 1 addition & 0 deletions include/scran_graph_cluster/cluster_walktrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()`.
Expand Down
13 changes: 13 additions & 0 deletions tests/src/cluster_leiden.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
9 changes: 9 additions & 0 deletions tests/src/cluster_multilevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
9 changes: 9 additions & 0 deletions tests/src/cluster_walktrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 765a361

Please sign in to comment.