| 1 |
#ifndef __PVAR_FFI_SUPPORT_H__ |
| 2 |
#define __PVAR_FFI_SUPPORT_H__ |
| 3 |
|
| 4 |
// This library is part of PLINK 2.0, copyright (C) 2005-2025 Shaun Purcell, |
| 5 |
// Christopher Chang. |
| 6 |
// |
| 7 |
// This library is free software: you can redistribute it and/or modify it |
| 8 |
// under the terms of the GNU Lesser General Public License as published by the |
| 9 |
// Free Software Foundation; either version 3 of the License, or (at your |
| 10 |
// option) any later version. |
| 11 |
// |
| 12 |
// This library is distributed in the hope that it will be useful, but WITHOUT |
| 13 |
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 15 |
// for more details. |
| 16 |
// |
| 17 |
// You should have received a copy of the GNU Lesser General Public License |
| 18 |
// along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
#include "pgenlib_misc.h" |
| 21 |
|
| 22 |
#ifdef __cplusplus |
| 23 |
namespace plink2 { |
| 24 |
#endif |
| 25 |
|
| 26 |
// Would prefer to make p a flexible array member, but that doesn't adhere to |
| 27 |
// current CRAN coding standards, so we have an extra dereference here. |
| 28 |
struct RefcountedWptrStruct { |
| 29 |
uintptr_t ref_ct; |
| 30 |
uintptr_t* p; |
| 31 |
}; |
| 32 |
|
| 33 |
typedef struct RefcountedWptrStruct RefcountedWptr; |
| 34 |
|
| 35 |
RefcountedWptr* CreateRefcountedWptr(uintptr_t size); |
| 36 |
|
| 37 |
void CondReleaseRefcountedWptr(RefcountedWptr** rwpp); |
| 38 |
|
| 39 |
// Only enforced for chr_names for now. |
| 40 |
CONSTI32(kMaxIdSlen, 16000); |
| 41 |
|
| 42 |
// This is based on plink2 defaults: 65376 = 1 unplaced + 95 autosomes + 6 |
| 43 |
// special cases (X/Y/XY/MT/PAR1/PAR2) + 65274 contigs |
| 44 |
CONSTI32(kMaxChromosomes, 65376); |
| 45 |
// We use a simple fixed-size hash table for the chromosome names. Ensure load |
| 46 |
// factor doesn't exceed 0.5 (of course it's almost always tiny in practice). |
| 47 |
CONSTI32(kChrHtableSize, 130752); |
| 48 |
typedef uint16_t ChrIdx; |
| 49 |
|
| 50 |
// Minimal .pvar loader (CHROM/POS optional; no QUAL/FILTER/INFO), using |
| 51 |
// malloc/free instead of bigstack. Necessary for clean multiallelic-variant |
| 52 |
// support. |
| 53 |
struct MinimalPvarStruct { |
| 54 |
const char** chr_names; |
| 55 |
const ChrIdx* chr_idxs; |
| 56 |
const int32_t* variant_bps; |
| 57 |
const char** variant_ids; |
| 58 |
const char** allele_storage; // part of varisnt_ids allocation |
| 59 |
|
| 60 |
// reference-counted since ownership can be shared with .pgen object |
| 61 |
RefcountedWptr* allele_idx_offsetsp; |
| 62 |
|
| 63 |
uint32_t chr_ct; |
| 64 |
uint32_t variant_ct; |
| 65 |
uint32_t max_allele_ct; |
| 66 |
}; |
| 67 |
|
| 68 |
typedef struct MinimalPvarStruct MinimalPvar; |
| 69 |
|
| 70 |
void PreinitMinimalPvar(MinimalPvar* mpp); |
| 71 |
|
| 72 |
FLAGSET_DEF_START() |
| 73 |
kfLoadMinimalPvar0, |
| 74 |
kfLoadMinimalPvarOmitChrom = (1 << 0), |
| 75 |
kfLoadMinimalPvarOmitPos = (1 << 1) |
| 76 |
FLAGSET_DEF_END(LoadMinimalPvarFlags); |
| 77 |
|
| 78 |
PglErr LoadMinimalPvarEx(const char* fname, LoadMinimalPvarFlags flags, MinimalPvar* mpp, char* errstr_buf); |
| 79 |
|
| 80 |
HEADER_INLINE PglErr LoadMinimalPvar(const char* fname, MinimalPvar* mpp, char* errstr_buf) { |
| 81 |
return LoadMinimalPvarEx(fname, kfLoadMinimalPvarOmitChrom | kfLoadMinimalPvarOmitPos, mpp, errstr_buf); |
| 82 |
} |
| 83 |
|
| 84 |
void CleanupMinimalPvar(MinimalPvar* mpp); |
| 85 |
|
| 86 |
#ifdef __cplusplus |
| 87 |
} // namespace plink2 |
| 88 |
#endif |
| 89 |
|
| 90 |
#endif // __PVAR_FFI_SUPPORT_H__ |