Debian Codegraph @

pgenlibr/src/pvar.h

raw
1 #ifndef __PVAR_H__
2 #define __PVAR_H__
3
4 #include "include/pvar_ffi_support.h"
5 #include <map>
6
7 #include <Rcpp.h>
8 using namespace Rcpp;
9
10 struct classcomp {
11 bool operator() (const char* const& lhs, const char* const& rhs) const {
12 return strcmp(lhs, rhs) < 0;
13 }
14 };
15
16 class RPvar {
17 public:
18 // only tracks variant IDs and allele codes for now
19 RPvar();
20
21 #if __cplusplus >= 201103L
22 RPvar(const RPvar&) = delete;
23 RPvar& operator=(const RPvar&) = delete;
24 #endif
25
26 void Load(String filename, bool omit_chrom, bool omit_pos);
27
28 uint32_t GetVariantCt() const;
29
30 const char* GetVariantChrom(uint32_t variant_idx) const;
31
32 int32_t GetVariantPos(uint32_t variant_idx) const;
33
34 const char* GetVariantId(uint32_t variant_idx) const;
35
36 std::pair<std::multimap<const char*, int, classcomp>::iterator, std::multimap<const char*, int, classcomp>::iterator> GetVariantsById(const char* id);
37
38 uint32_t GetAlleleCt(uint32_t variant_idx) const;
39
40 const char* GetAlleleCode(uint32_t variant_idx, uint32_t allele_idx) const;
41
42 plink2::RefcountedWptr* GetAlleleIdxOffsetsp();
43
44 uint32_t GetMaxAlleleCt() const;
45
46 void Close();
47
48 ~RPvar();
49
50 private:
51 plink2::MinimalPvar _mp;
52
53 // this is slow, should be switched to plink2's hash table
54 std::multimap<const char*, int, classcomp> _nameToIdxs;
55 };
56
57 HEADER_INLINE int strcmp_r_c(String r_string, const char* cstr) {
58 return strcmp(r_string.get_cstring(), cstr);
59 }
60
61 #endif // __PVAR_H__