scran_graph_cluster
Graph-based clustering of cells
Loading...
Searching...
No Matches
cluster_leiden.hpp
Go to the documentation of this file.
1#ifndef SCRAN_GRAPH_CLUSTER_CLUSTER_LEIDEN_HPP
2#define SCRAN_GRAPH_CLUSTER_CLUSTER_LEIDEN_HPP
3
4#include <vector>
5#include <algorithm>
6
7#include "raiigraph/raiigraph.hpp"
8#include "sanisizer/sanisizer.hpp"
9
10#include "igraph.h"
11
17namespace scran_graph_cluster {
18
28 igraph_real_t resolution = 1;
29
34 igraph_real_t beta = 0.01;
35
42 igraph_int_t iterations = 2;
43
50 igraph_leiden_objective_t objective = IGRAPH_LEIDEN_OBJECTIVE_CPM;
51
55 bool report_quality = true;
56
60 igraph_uint_t seed = 42;
61};
62
70 raiigraph::IntegerVector membership;
71
76 igraph_real_t quality = 0;
77};
78
94inline void cluster_leiden(const igraph_t* graph, const igraph_vector_t* weights, const ClusterLeidenOptions& options, ClusterLeidenResults& output) {
95 const auto membership = output.membership.get();
96 const auto quality = (options.report_quality ? &(output.quality) : static_cast<igraph_real_t*>(NULL));
97
98 const raiigraph::RNGScope rngs(options.seed);
99
100 const auto status = igraph_community_leiden_simple(
101 graph,
102 weights,
103 options.objective,
104 options.resolution,
105 options.beta,
106 false,
107 options.iterations,
108 membership,
109 NULL,
110 quality
111 );
112
113 raiigraph::check_code(status);
114}
115
127inline ClusterLeidenResults cluster_leiden(const raiigraph::Graph& graph, const std::vector<igraph_real_t>& weights, const ClusterLeidenOptions& options) {
128 // No need to free this, as it's just a view.
129 const auto weight_view = igraph_vector_view(weights.data(), sanisizer::cast<igraph_int_t>(weights.size()));
130
132 cluster_leiden(graph.get(), &weight_view, options, output);
133 return output;
134}
135
136}
137
138#endif
Graph-based clustering of single-cell data.
Definition build_snn_graph.hpp:22
void cluster_leiden(const igraph_t *graph, const igraph_vector_t *weights, const ClusterLeidenOptions &options, ClusterLeidenResults &output)
Definition cluster_leiden.hpp:94
Options for cluster_leiden().
Definition cluster_leiden.hpp:22
igraph_int_t iterations
Definition cluster_leiden.hpp:42
igraph_uint_t seed
Definition cluster_leiden.hpp:60
igraph_real_t beta
Definition cluster_leiden.hpp:34
bool report_quality
Definition cluster_leiden.hpp:55
igraph_leiden_objective_t objective
Definition cluster_leiden.hpp:50
igraph_real_t resolution
Definition cluster_leiden.hpp:28
Result of cluster_leiden().
Definition cluster_leiden.hpp:66
igraph_real_t quality
Definition cluster_leiden.hpp:76
raiigraph::IntegerVector membership
Definition cluster_leiden.hpp:70