singlepp
A C++ library for cell type classification
Loading...
Searching...
No Matches
classify_integrated.hpp
Go to the documentation of this file.
1#ifndef SINGLEPP_CLASSIFY_INTEGRATED_HPP
2#define SINGLEPP_CLASSIFY_INTEGRATED_HPP
3
4#include "defs.hpp"
5
6#include "tatami/tatami.hpp"
7
8#include "annotate_cells_integrated.hpp"
10
11#include <vector>
12#include <cstddef>
13#include <unordered_map>
14#include <unordered_set>
15
21namespace singlepp {
22
27template<typename Float_ = DefaultFloat>
33 Float_ quantile = 0.8;
34
39 Float_ fine_tune_threshold = 0.05;
40
45 bool fine_tune = true;
46
51 int num_threads = 1;
52};
53
59template<typename RefLabel_ = DefaultRefLabel, typename Float_ = DefaultFloat>
65 RefLabel_* best;
66
73 std::vector<Float_*> scores;
74
80 Float_* delta;
81};
82
126template<typename Value_, typename Index_, typename Label_, typename RefLabel_, typename Float_>
128 const tatami::Matrix<Value_, Index_>& test,
129 const std::vector<const Label_*>& assigned,
130 const TrainedIntegrated<Index_>& trained,
133{
134 if (trained.test_nrow != static_cast<Index_>(-1) && trained.test_nrow != test.nrow()) {
135 throw std::runtime_error("number of rows in 'test' is not the same as that used to build 'trained'");
136 }
137 internal::annotate_cells_integrated(
138 test,
139 trained,
140 assigned,
141 options.quantile,
142 options.fine_tune,
143 options.fine_tune_threshold,
144 buffers.best,
145 buffers.scores,
146 buffers.delta,
147 options.num_threads
148 );
149}
150
156template<typename RefLabel_ = DefaultRefLabel, typename Float_ = DefaultFloat>
161 ClassifyIntegratedResults(std::size_t ncells, std::size_t nrefs) : best(ncells), delta(ncells) {
162 scores.reserve(nrefs);
163 for (decltype(nrefs) r = 0; r < nrefs; ++r) {
164 scores.emplace_back(ncells);
165 }
166 }
175 std::vector<RefLabel_> best;
176
182 std::vector<std::vector<Float_> > scores;
183
188 std::vector<Float_> delta;
189};
190
205template<typename RefLabel_ = DefaultRefLabel, typename Value_, typename Index_, typename Label_, typename Float_>
207 const tatami::Matrix<Value_, Index_>& test,
208 const std::vector<const Label_*>& assigned,
209 const TrainedIntegrated<Index_>& trained,
211{
212 ClassifyIntegratedResults<RefLabel_, Float_> results(test.ncol(), trained.num_references());
214 buffers.best = results.best.data();
215 buffers.delta = results.delta.data();
216 buffers.scores.reserve(results.scores.size());
217 for (auto& s : results.scores) {
218 buffers.scores.emplace_back(s.data());
219 }
220 classify_integrated(test, assigned, trained, buffers, options);
221 return results;
222}
223
224}
225
226#endif
Classifier that integrates multiple reference datasets.
Definition train_integrated.hpp:240
std::size_t num_references() const
Definition train_integrated.hpp:245
Common definitions for singlepp.
Cell type classification using the SingleR algorithm in C++.
Definition classify_single.hpp:20
void classify_integrated(const tatami::Matrix< Value_, Index_ > &test, const std::vector< const Label_ * > &assigned, const TrainedIntegrated< Index_ > &trained, ClassifyIntegratedBuffers< RefLabel_, Float_ > &buffers, const ClassifyIntegratedOptions< Float_ > &options)
Integrate classifications from multiple references.
Definition classify_integrated.hpp:127
Output buffers for classify_single().
Definition classify_integrated.hpp:60
RefLabel_ * best
Definition classify_integrated.hpp:65
Float_ * delta
Definition classify_integrated.hpp:80
std::vector< Float_ * > scores
Definition classify_integrated.hpp:73
Options for classify_integrated().
Definition classify_integrated.hpp:28
bool fine_tune
Definition classify_integrated.hpp:45
int num_threads
Definition classify_integrated.hpp:51
Float_ quantile
Definition classify_integrated.hpp:33
Float_ fine_tune_threshold
Definition classify_integrated.hpp:39
Results of classify_integrated().
Definition classify_integrated.hpp:157
std::vector< std::vector< Float_ > > scores
Definition classify_integrated.hpp:182
std::vector< RefLabel_ > best
Definition classify_integrated.hpp:175
std::vector< Float_ > delta
Definition classify_integrated.hpp:188
Prepare for integrated classification across references.