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
93 auto membership = output.membership.get();
94 auto quality = (options.report_quality ? &(output.quality) : NULL);
95
96 raiigraph::RNGScope rngs(options.seed);
97
98 if (!options.modularity) {
100 graph,
101 weights,
102 NULL,
103 options.resolution,
104 options.beta,
105 false,
106 options.iterations,
107 membership,
108 NULL,
109 quality
110 );
111
112 } else {
113 // More-or-less translated from igraph::cluster_leiden in the R package.
114 raiigraph::RealVector strengths(igraph_vcount(graph));
116
117 double total_weights = igraph_vector_sum(weights);
118 double mod_resolution = options.resolution / total_weights;
119
121 graph,
122 weights,
123 strengths,
125 options.beta,
126 false,
127 options.iterations,
128 membership,
129 NULL,
130 quality
131 );
132 }
133}
134
145inline ClusterLeidenResults cluster_leiden(const raiigraph::Graph& graph, const std::vector<igraph_real_t>& weights, const ClusterLeidenOptions& options) {
146 // No need to free this, as it's just a view.
148 igraph_vector_view(&weight_view, weights.data(), weights.size());
149
152 return output;
153}
154
155}
156
157#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:92
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