singlepp
A C++ library for cell type classification
Loading...
Searching...
No Matches
Intersection.hpp
Go to the documentation of this file.
1#ifndef SINGLEPP_INTERSECTION_HPP
2#define SINGLEPP_INTERSECTION_HPP
3
4#include "defs.hpp"
5
6#include <vector>
7#include <algorithm>
8#include <cstdint>
9#include <numeric>
10#include <unordered_map>
11
17namespace singlepp {
18
34template<typename Index_ = DefaultIndex>
35using Intersection = std::vector<std::pair<Index_, Index_> >;
36
53template<typename Index_, typename Id_>
55 std::unordered_map<Id_, Index_> ref_found;
56 for (Index_ i = 0; i < ref_nrow; ++i) {
57 auto current = ref_id[i];
58 auto tfIt = ref_found.find(current);
59 if (tfIt == ref_found.end()) { // only using the first occurrence of each ID in ref_id.
61 }
62 }
63
65 for (Index_ i = 0; i < test_nrow; ++i) {
66 auto current = test_id[i];
67 auto tfIt = ref_found.find(current);
68 if (tfIt != ref_found.end()) {
69 output.emplace_back(i, tfIt->second);
70 ref_found.erase(tfIt); // only using the first occurrence of each ID in test_id; the next will not enter this clause.
71 }
72 }
73
74 // This is implicitly sorted by the test indices... not that it really
75 // matters, as subset_to_markers() doesn't care that it's unsorted.
76 return output;
77}
78
79}
80
81#endif
Common definitions for singlepp.
Cell type classification using the SingleR algorithm in C++.
Definition classify_single.hpp:19
Intersection< Index_ > intersect_genes(Index_ test_nrow, const Id_ *test_id, Index_ ref_nrow, const Id_ *ref_id)
Definition Intersection.hpp:54
std::vector< std::pair< Index_, Index_ > > Intersection
Definition Intersection.hpp:35
std::vector< std::vector< std::vector< Index_ > > > Markers
Definition Markers.hpp:40