scran_graph_cluster
Graph-based clustering of cells
Loading...
Searching...
No Matches
cluster_walktrap.hpp
Go to the documentation of this file.
1#ifndef SCRAN_CLUSTER_WALKTRAP_HPP
2#define SCRAN_CLUSTER_WALKTRAP_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
30 int steps = 4;
31
35 bool report_merges = true;
36
40 bool report_modularity = true;
41};
42
51 int status = 0;
52
56 raiigraph::IntegerVector membership;
57
65 raiigraph::IntegerMatrix merges;
66
72 raiigraph::RealVector modularity;
73};
74
88inline void cluster_walktrap(const igraph_t* graph, const igraph_vector_t* weights, const ClusterWalktrapOptions& options, ClusterWalktrapResults& output) {
89 const auto membership = output.membership.get();
90 const auto modularity = (options.report_modularity ? output.modularity.get() : static_cast<igraph_vector_t*>(NULL));
91 const auto merges = (options.report_merges ? output.merges.get() : static_cast<igraph_matrix_int_t*>(NULL));
92 output.status = igraph_community_walktrap(graph, weights, options.steps, merges, modularity, membership);
93}
94
106inline ClusterWalktrapResults cluster_walktrap(const raiigraph::Graph& graph, const std::vector<igraph_real_t>& weights, const ClusterWalktrapOptions& options) {
107 // No need to free this, as it's just a view.
108 igraph_vector_t weight_view;
109 igraph_vector_view(&weight_view, weights.data(), sanisizer::cast<igraph_integer_t>(weights.size()));
110
112 cluster_walktrap(graph.get(), &weight_view, options, output);
113 return output;
114}
115
116}
117
118#endif
Graph-based clustering of single-cell data.
Definition build_snn_graph.hpp:22
void cluster_walktrap(const igraph_t *graph, const igraph_vector_t *weights, const ClusterWalktrapOptions &options, ClusterWalktrapResults &output)
Definition cluster_walktrap.hpp:88
Options for cluster_walktrap().
Definition cluster_walktrap.hpp:22
int steps
Definition cluster_walktrap.hpp:30
bool report_merges
Definition cluster_walktrap.hpp:35
bool report_modularity
Definition cluster_walktrap.hpp:40
Result of cluster_walktrap().
Definition cluster_walktrap.hpp:46
raiigraph::IntegerVector membership
Definition cluster_walktrap.hpp:56
int status
Definition cluster_walktrap.hpp:51
raiigraph::IntegerMatrix merges
Definition cluster_walktrap.hpp:65
raiigraph::RealVector modularity
Definition cluster_walktrap.hpp:72