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 igraph_int_t steps = 4;
31
35 bool report_merges = true;
36
40 bool report_modularity = true;
41};
42
50 raiigraph::IntegerVector membership;
51
59 raiigraph::IntegerMatrix merges;
60
66 raiigraph::RealVector modularity;
67};
68
84inline void cluster_walktrap(const igraph_t* graph, const igraph_vector_t* weights, const ClusterWalktrapOptions& options, ClusterWalktrapResults& output) {
85 const auto membership = output.membership.get();
86 const auto modularity = (options.report_modularity ? output.modularity.get() : static_cast<igraph_vector_t*>(NULL));
87 const auto merges = (options.report_merges ? output.merges.get() : static_cast<igraph_matrix_int_t*>(NULL));
88
89 const auto status = igraph_community_walktrap(graph, weights, options.steps, merges, modularity, membership);
90 raiigraph::check_code(status);
91}
92
104inline ClusterWalktrapResults cluster_walktrap(const raiigraph::Graph& graph, const std::vector<igraph_real_t>& weights, const ClusterWalktrapOptions& options) {
105 // No need to free this, as it's just a view.
106 const auto weight_view = igraph_vector_view(weights.data(), sanisizer::cast<igraph_int_t>(weights.size()));
107
109 cluster_walktrap(graph.get(), &weight_view, options, output);
110 return output;
111}
112
113}
114
115#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:84
Options for cluster_walktrap().
Definition cluster_walktrap.hpp:22
igraph_int_t 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:50
raiigraph::IntegerMatrix merges
Definition cluster_walktrap.hpp:59
raiigraph::RealVector modularity
Definition cluster_walktrap.hpp:66