Debian Codegraph @

plink2_ld.h

raw
1 #ifndef __PLINK2_LD_H__
2 #define __PLINK2_LD_H__
3
4 // This file is part of PLINK 2.0, copyright (C) 2005-2025 Shaun Purcell,
5 // Christopher Chang.
6 //
7 // This program is free software: you can redistribute it and/or modify it
8 // under the terms of the GNU General Public License as published by the Free
9 // Software Foundation, either version 3 of the License, or (at your option)
10 // any later version.
11 //
12 // This program 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 General Public License for
15 // more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20
21 #include "plink2_common.h"
22
23 #ifdef __cplusplus
24 namespace plink2 {
25 #endif
26
27 FLAGSET_DEF_START()
28 kfLdPrune0,
29 kfLdPruneWindowBp = (1 << 0),
30 kfLdPrunePairwise = (1 << 1),
31 kfLdPrunePairphase = (1 << 2),
32 kfLdPrunePlink1Order = (1 << 3)
33 FLAGSET_DEF_END(LdPruneFlags);
34 // todo: old multicollinearity test
35
36 FLAGSET_DEF_START()
37 kfClump0,
38 kfClumpZs = (1 << 0),
39 kfClumpUnphased = (1 << 1),
40 kfClumpForceA1 = (1 << 2),
41 kfClumpAllowOverlap = (1 << 3),
42 kfClumpInputLog10 = (1 << 4),
43 kfClumpOutputLog10 = (1 << 5),
44 kfClumpNoA1 = (1 << 6),
45 kfClumpNoTest = (1 << 7),
46 kfClumpRange0 = (1 << 8),
47
48 kfClumpColChrom = (1 << 9),
49 kfClumpColPos = (1 << 10),
50 kfClumpColRef = (1 << 11),
51 kfClumpColAlt1 = (1 << 12),
52 kfClumpColAlt = (1 << 13),
53 kfClumpColMaybeprovref = (1 << 14),
54 kfClumpColProvref = (1 << 15),
55 kfClumpColMaybeA1 = (1 << 16),
56 kfClumpColA1 = (1 << 17),
57 kfClumpColMaybeF = (1 << 18),
58 kfClumpColF = (1 << 19),
59 kfClumpColTotal = (1 << 20),
60 kfClumpColMaybeBounds = (1 << 21),
61 kfClumpColBounds = (1 << 22),
62 kfClumpColBins = (1 << 23),
63 kfClumpColSp2 = (1 << 24),
64 kfClumpColDefault = (kfClumpColChrom | kfClumpColPos | kfClumpColMaybeprovref | kfClumpColMaybeA1 | kfClumpColMaybeF | kfClumpColTotal | kfClumpColMaybeBounds | kfClumpColBins | kfClumpColSp2)
65 FLAGSET_DEF_END(ClumpFlags);
66
67 FLAGSET_DEF_START()
68 kfVcor0,
69 kfVcorZs = (1 << 0),
70 kfVcorBin8 = (1 << 1),
71 kfVcorBin4 = (1 << 2),
72 kfVcorEncodemask = (kfVcorZs | kfVcorBin8 | kfVcorBin4),
73 kfVcorMatrixSq = (1 << 3),
74 kfVcorMatrixSq0 = (1 << 4),
75 kfVcorMatrixTri = (1 << 5),
76 kfVcorMatrixShapemask = (kfVcorMatrixSq | kfVcorMatrixSq0 | kfVcorMatrixTri),
77 kfVcorPhased = (1 << 6),
78 kfVcorUnsquared = (1 << 7),
79 kfVcorYesReally = (1 << 8),
80 kfVcorInterChr = (1 << 9),
81 kfVcorRefBased = (1 << 10),
82 kfVcorAllowAmbiguousAllele = (1 << 11),
83
84 kfVcorColChrom = (1 << 12),
85 kfVcorColPos = (1 << 13),
86 kfVcorColId = (1 << 14),
87 kfVcorColRef = (1 << 15),
88 kfVcorColAlt1 = (1 << 16),
89 kfVcorColAlt = (1 << 17),
90 kfVcorColMaybeprovref = (1 << 18),
91 kfVcorColProvref = (1 << 19),
92 kfVcorColMaj = (1 << 20),
93 kfVcorColNonmaj = (1 << 21),
94 kfVcorColFreq = (1 << 22),
95 kfVcorColD = (1 << 23),
96 kfVcorColDprime = (1 << 24),
97 kfVcorColDprimeAbs = (1 << 25),
98 kfVcorColDefault = (kfVcorColChrom | kfVcorColPos | kfVcorColId | kfVcorColMaybeprovref)
99 FLAGSET_DEF_END(VcorFlags);
100
101 CONSTI32(kClumpMaxBinBounds, 0x4000000);
102
103 FLAGSET_DEF_START()
104 kfLdConsole0,
105 kfLdConsoleHweMidp = (1 << 0)
106 FLAGSET_DEF_END(LdConsoleFlags);
107
108 typedef struct LdInfoStruct {
109 NONCOPYABLE(LdInfoStruct);
110 double prune_last_param; // VIF or r^2 threshold
111 LdPruneFlags prune_flags;
112 uint32_t prune_window_size;
113 uint32_t prune_window_incr;
114 LdConsoleFlags ld_console_flags;
115 STD_ARRAY_DECL(char*, 2, ld_console_varids);
116 } LdInfo;
117
118 typedef struct ClumpInfoStruct {
119 NONCOPYABLE(ClumpInfoStruct);
120 char* fnames_flattened;
121 char* range_fname;
122 char* test_name;
123 char* id_field;
124 char* a1_field;
125 char* test_field;
126 char* p_field;
127 double* ln_bin_boundaries;
128 double ln_p1;
129 double ln_p2;
130 double r2;
131 uint32_t bin_bound_ct;
132 uint32_t bp_radius;
133 uint32_t range_border;
134 ClumpFlags flags;
135 } ClumpInfo;
136
137 typedef struct VcorInfoStruct {
138 NONCOPYABLE(VcorInfoStruct);
139 char* ld_snp_list_fname;
140 RangeList ld_snp_range_list;
141 uint32_t var_ct_radius;
142 uint32_t bp_radius;
143 double cm_radius;
144 double min_r2;
145 VcorFlags flags;
146 } VcorInfo;
147
148 void InitLd(LdInfo* ldip);
149
150 void CleanupLd(LdInfo* ldip);
151
152 void InitClump(ClumpInfo* clump_ip);
153
154 void CleanupClump(ClumpInfo* clump_ip);
155
156 void InitVcor(VcorInfo* vcip);
157
158 void CleanupVcor(VcorInfo* vcip);
159
160 PglErr LdPrune(const uintptr_t* orig_variant_include, const ChrInfo* cip, const uint32_t* variant_bps, const char* const* variant_ids, const uintptr_t* allele_idx_offsets, const AlleleCode* maj_alleles, const double* allele_freqs, const uintptr_t* founder_info, const uintptr_t* sex_nm, const uintptr_t* sex_male, const LdInfo* ldip, const char* indep_preferred_fname, uint32_t raw_variant_ct, uint32_t variant_ct, uint32_t raw_sample_ct, uint32_t founder_ct, uint32_t nosex_ct, uint32_t max_thread_ct, PgenReader* simple_pgrp, char* outname, char* outname_end);
161
162 PglErr LdConsole(const uintptr_t* variant_include, const ChrInfo* cip, const char* const* variant_ids, const uintptr_t* allele_idx_offsets, const char* const* allele_storage, const AlleleCode* maj_alleles, const uintptr_t* founder_info, const uintptr_t* sex_nm, const uintptr_t* sex_male, const LdInfo* ldip, uint32_t variant_ct, uint32_t raw_sample_ct, uint32_t founder_ct, PgenReader* simple_pgrp);
163
164 PglErr ClumpReports(const uintptr_t* orig_variant_include, const ChrInfo* cip, const uint32_t* variant_bps, const char* const* variant_ids, const uintptr_t* allele_idx_offsets, const char* const* allele_storage, const uintptr_t* founder_info, const uintptr_t* sex_nm, const uintptr_t* sex_male, const ClumpInfo* clump_ip, uint32_t raw_variant_ct, uint32_t orig_variant_ct, uint32_t raw_sample_ct, uint32_t founder_ct, uint32_t nosex_ct, uint32_t max_variant_id_slen, uint32_t max_allele_slen, double output_min_ln, uint32_t max_thread_ct, uintptr_t pgr_alloc_cacheline_ct, PgenFileInfo* pgfip, PgenReader* simple_pgrp, char* outname, char* outname_end);
165
166 PglErr Vcor(const uintptr_t* orig_variant_include, const ChrInfo* cip, const uint32_t* variant_bps, const char* const* variant_ids, const double* variant_cms, const uintptr_t* allele_idx_offsets, const char* const* allele_storage, const AlleleCode* maj_alleles, const double* allele_freqs, const uintptr_t* founder_info, const uintptr_t* sex_nm, const uintptr_t* sex_male, const VcorInfo* vcip, uint32_t raw_variant_ct, uint32_t orig_variant_ct, uint32_t raw_sample_ct, uint32_t founder_ct, uint32_t max_variant_id_slen, uint32_t max_allele_slen, uint32_t parallel_idx, uint32_t parallel_tot, uint32_t max_thread_ct, PgenReader* simple_pgrp, char* outname, char* outname_end);
167
168 #ifdef __cplusplus
169 } // namespace plink2
170 #endif
171
172 #endif // __PLINK2_LD_H__