singlepp
A C++ library for cell type classification
Loading...
Searching...
No Matches
classify_single.hpp
Go to the documentation of this file.
1#ifndef SINGLEPP_CLASSIFY_SINGLE_HPP
2#define SINGLEPP_CLASSIFY_SINGLE_HPP
3
4#include "defs.hpp"
5
6#include "tatami/tatami.hpp"
7
8#include "annotate_cells_single.hpp"
9#include "train_single.hpp"
10
11#include <vector>
12#include <stdexcept>
13
19namespace singlepp {
20
25template<typename Float_ = DefaultFloat>
35
44
49 bool fine_tune = true;
50
55 int num_threads = 1;
56};
57
63template<typename Label_ = DefaultLabel, typename Float_ = DefaultFloat>
70
77 std::vector<Float_*> scores;
78
85};
86
130template<typename Value_, typename Index_, typename Float_, typename Label_>
132 const tatami::Matrix<Value_, Index_>& test,
136{
137 internal::annotate_cells_single(
138 test,
139 trained.get_subset(),
140 trained.get_references(),
141 trained.get_markers(),
142 options.quantile,
143 options.fine_tune,
144 options.fine_tune_threshold,
145 buffers.best,
146 buffers.scores,
147 buffers.delta,
148 options.num_threads
149 );
150}
151
168template<typename Value_, typename Index_, typename Float_, typename Label_>
170 const tatami::Matrix<Value_, Index_>& test,
174{
175 internal::annotate_cells_single(
176 test,
177 trained.get_test_subset(),
178 trained.get_references(),
179 trained.get_markers(),
180 options.quantile,
181 options.fine_tune,
182 options.fine_tune_threshold,
183 buffers.best,
184 buffers.scores,
185 buffers.delta,
186 options.num_threads
187 );
188}
189
195template<typename Label_ = DefaultLabel, typename Float_ = DefaultFloat>
200 ClassifySingleResults(size_t num_cells, size_t num_labels) : best(num_cells), delta(num_cells) {
201 scores.reserve(num_labels);
202 for (size_t l = 0; l < num_labels; ++l) {
203 scores.emplace_back(num_cells);
204 }
205 }
214 std::vector<Label_> best;
215
221 std::vector<std::vector<Float_> > scores;
222
227 std::vector<Float_> delta;
228};
229
233namespace internal {
234
235template<typename Label_, typename Float_>
238 output.best = results.best.data();
239 output.delta = results.delta.data();
240 output.scores.reserve(results.scores.size());
241 for (auto& s : results.scores) {
242 output.scores.emplace_back(s.data());
243 }
244 return output;
245}
246
247}
267template<typename Label_ = DefaultLabel, typename Value_, typename Index_, typename Float_>
269 const tatami::Matrix<Value_, Index_>& test,
272{
273 ClassifySingleResults<Label_, Float_> output(test.ncol(), trained.get_references().size());
274 auto buffers = internal::results_to_buffers(output);
276 return output;
277}
278
294template<typename Label_ = DefaultLabel, typename Value_, typename Index_, typename Float_>
296 const tatami::Matrix<Value_, Index_>& test,
299{
300 ClassifySingleResults<Label_, Float_> output(test.ncol(), trained.get_references().size());
301 auto buffers = internal::results_to_buffers(output);
303 return output;
304}
305
306}
307
308#endif
Common definitions for singlepp.
Cell type classification using the SingleR algorithm in C++.
Definition classify_single.hpp:19
std::vector< std::vector< std::vector< Index_ > > > Markers
Definition Markers.hpp:40
void classify_single_intersect(const tatami::Matrix< Value_, Index_ > &test, const TrainedSingleIntersect< Index_, Float_ > &trained, const ClassifySingleBuffers< Label_, Float_ > &buffers, const ClassifySingleOptions< Float_ > &options)
Definition classify_single.hpp:169
void classify_single(const tatami::Matrix< Value_, Index_ > &test, const TrainedSingle< Index_, Float_ > &trained, const ClassifySingleBuffers< Label_, Float_ > &buffers, const ClassifySingleOptions< Float_ > &options)
Implements the SingleR algorithm for automated annotation of single-cell RNA-seq data.
Definition classify_single.hpp:131
Output buffers for classify_single().
Definition classify_single.hpp:64
Float_ * delta
Definition classify_single.hpp:84
Label_ * best
Definition classify_single.hpp:69
std::vector< Float_ * > scores
Definition classify_single.hpp:77
Options for classify_single() and friends.
Definition classify_single.hpp:26
bool fine_tune
Definition classify_single.hpp:49
Float_ fine_tune_threshold
Definition classify_single.hpp:43
int num_threads
Definition classify_single.hpp:55
Float_ quantile
Definition classify_single.hpp:34
Results of classify_single() and classify_single_intersect().
Definition classify_single.hpp:196
std::vector< Float_ > delta
Definition classify_single.hpp:227
std::vector< Label_ > best
Definition classify_single.hpp:214
std::vector< std::vector< Float_ > > scores
Definition classify_single.hpp:221
Train a classifier from a single reference.