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 "igraph.h"
9
15namespace scran_graph_cluster {
16
26 double resolution = 1;
27
32 double beta = 0.01;
33
39 int iterations = 2;
40
46 bool modularity = false;
47
51 bool report_quality = true;
52
56 int seed = 42;
57};
58
67 int status = 0;
68
72 raiigraph::IntegerVector membership;
73
79};
80
94 auto membership = output.membership.get();
95 auto quality = (options.report_quality ? &(output.quality) : NULL);
96
97 raiigraph::RNGScope rngs(options.seed);
98
99 if (!options.modularity) {
101 graph,
102 weights,
103 NULL,
104 options.resolution,
105 options.beta,
106 false,
107 options.iterations,
108 membership,
109 NULL,
110 quality
111 );
112
113 } else {
114 // More-or-less translated from igraph::cluster_leiden in the R package.
115 raiigraph::RealVector strengths(igraph_vcount(graph));
117
119 double mod_resolution = options.resolution / total_weights;
120
122 graph,
123 weights,
124 strengths,
126 options.beta,
127 false,
128 options.iterations,
129 membership,
130 NULL,
131 quality
132 );
133 }
134}
135
146inline ClusterLeidenResults cluster_leiden(const raiigraph::Graph& graph, const std::vector<igraph_real_t>& weights, const ClusterLeidenOptions& options) {
147 // No need to free this, as it's just a view.
149 igraph_vector_view(&weight_view, weights.data(), weights.size());
150
153 return output;
154}
155
156}
157
158#endif
Graph-based clustering of single-cell data.
Definition build_snn_graph.hpp:20
void cluster_leiden(const igraph_t *graph, const igraph_vector_t *weights, const ClusterLeidenOptions &options, ClusterLeidenResults &output)
Definition cluster_leiden.hpp:93
void build_snn_graph(size_t num_cells, GetNeighbors_ get_neighbors, GetIndex_ get_index, const BuildSnnGraphOptions &options, BuildSnnGraphResults< Node_, Weight_ > &output)
Definition build_snn_graph.hpp:133
Options for cluster_leiden().
Definition cluster_leiden.hpp:20
int seed
Definition cluster_leiden.hpp:56
bool modularity
Definition cluster_leiden.hpp:46
double beta
Definition cluster_leiden.hpp:32
double resolution
Definition cluster_leiden.hpp:26
bool report_quality
Definition cluster_leiden.hpp:51
int iterations
Definition cluster_leiden.hpp:39
Result of cluster_leiden().
Definition cluster_leiden.hpp:62
int status
Definition cluster_leiden.hpp:67
igraph_real_t quality
Definition cluster_leiden.hpp:78
raiigraph::IntegerVector membership
Definition cluster_leiden.hpp:72