1 #ifndef __PLINK2_GLM_H__
2 #define __PLINK2_GLM_H__
3 
4 // This file is part of PLINK 2.00, copyright (C) 2005-2020 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_adjust.h"
22 
23 #ifdef __cplusplus
24 namespace plink2 {
25 #endif
26 
27 FLAGSET_DEF_START()
28   kfGlm0,
29   kfGlmZs = (1 << 0),
30 
31   kfGlmOmitRef = (1 << 1),
32 
33   // mutually exclusive
34   kfGlmSex = (1 << 2),
35   kfGlmNoXSex = (1 << 3),
36 
37   kfGlmLog10 = (1 << 4),
38 
39   // mutually exclusive
40   kfGlmGenotypic = (1 << 5),
41   kfGlmHethom = (1 << 6),
42   kfGlmDominant = (1 << 7),
43   kfGlmRecessive = (1 << 8),
44 
45   kfGlmInteraction = (1 << 9),
46   kfGlmHideCovar = (1 << 10),
47   kfGlmIntercept = (1 << 11),
48   kfGlmSkip = (1 << 12),
49   kfGlmNoFirth = (1 << 13),
50   kfGlmFirth = (1 << 14),
51   kfGlmPerm = (1 << 15),
52   kfGlmPermCount = (1 << 16),
53   kfGlmConditionDominant = (1 << 17),
54   kfGlmConditionRecessive = (1 << 18),
55   kfGlmConditionMultiallelic = (1 << 19),
56   kfGlmLocalOmitLast = (1 << 20),
57   kfGlmTestsAll = (1 << 21),
58   kfGlmPhenoIds = (1 << 22),
59   kfGlmLocalHaps = (1 << 23),
60   kfGlmLocalCats1based = (1 << 24)
61 FLAGSET_DEF_END(GlmFlags);
62 
63 FLAGSET_DEF_START()
64   kfGlmCol0,
65   kfGlmColChrom = (1 << 0),
66   kfGlmColPos = (1 << 1),
67   kfGlmColRef = (1 << 2),
68   kfGlmColAlt1 = (1 << 3),
69   kfGlmColAlt = (1 << 4),
70   kfGlmColAx = (1 << 5),
71   kfGlmColA1count = (1 << 6),
72   kfGlmColTotallele = (1 << 7),
73   kfGlmColA1countcc = (1 << 8),
74   kfGlmColTotallelecc = (1 << 9),
75   kfGlmColGcountcc = (1 << 10),
76   kfGlmColA1freq = (1 << 11),
77   kfGlmColA1freqcc = (1 << 12),
78   kfGlmColMachR2 = (1 << 13),
79   kfGlmColFirthYn = (1 << 14),
80   kfGlmColTest = (1 << 15),
81   kfGlmColNobs = (1 << 16),
82 
83   // if beta specified, ignore orbeta
84   kfGlmColBeta = (1 << 17),
85   kfGlmColOrbeta = (1 << 18),
86 
87   kfGlmColSe = (1 << 19),
88   kfGlmColCi = (1 << 20),
89   kfGlmColTz = (1 << 21),
90   kfGlmColP = (1 << 22),
91   kfGlmColErr = (1 << 23),
92   kfGlmColDefault = (kfGlmColChrom | kfGlmColPos | kfGlmColRef | kfGlmColAlt | kfGlmColFirthYn | kfGlmColTest | kfGlmColNobs | kfGlmColOrbeta | kfGlmColSe | kfGlmColCi | kfGlmColTz | kfGlmColP | kfGlmColErr)
93 FLAGSET_DEF_END(GlmColFlags);
94 
95 typedef struct GlmInfoStruct {
96   NONCOPYABLE(GlmInfoStruct);
97   GlmFlags flags;
98   GlmColFlags cols;
99   uint32_t mperm_ct;
100   uint32_t local_cat_ct;
101   uint32_t local_header_line_ct;
102   uint32_t local_chrom_col;
103   uint32_t local_bp_col;
104   uint32_t local_first_covar_col;
105   double max_corr;
106   char* condition_varname;
107   char* condition_list_fname;
108   RangeList parameters_range_list;
109   RangeList tests_range_list;
110 } GlmInfo;
111 
112 void InitGlm(GlmInfo* glm_info_ptr);
113 
114 void CleanupGlm(GlmInfo* glm_info_ptr);
115 
116 // for testing purposes
117 // plink2_matrix.h must be included in this file
118 // BoolErr LogisticRegression(const float* yy, const float* xx, uint32_t sample_ct, uint32_t predictor_ct, float* coef, uint32_t* is_unfinished_ptr, float* ll, float* pp, float* vv, float* hh, float* grad, float* dcoef) {
119 
120 // BoolErr FirthRegression(const float* yy, const float* xx, uint32_t sample_ct, uint32_t predictor_ct, float* coef, uint32_t* is_unfinished_ptr, float* hh, double* half_inverted_buf, MatrixInvertBuf1* inv_1d_buf, double* dbl_2d_buf, float* pp, float* vv, float* grad, float* dcoef, float* ww, float* tmpnxk_buf) {
121 
122 PglErr GlmMain(const uintptr_t* orig_sample_include, const SampleIdInfo* siip, const uintptr_t* sex_nm, const uintptr_t* sex_male, const PhenoCol* pheno_cols, const char* pheno_names, const PhenoCol* covar_cols, const char* covar_names, 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 char* const* allele_storage, const GlmInfo* glm_info_ptr, const AdjustInfo* adjust_info_ptr, const APerm* aperm_ptr, const char* local_covar_fname, const char* local_pvar_fname, const char* local_psam_fname, uint32_t raw_sample_ct, uint32_t orig_sample_ct, uint32_t pheno_ct, uintptr_t max_pheno_name_blen, uint32_t orig_covar_ct, uintptr_t max_covar_name_blen, uint32_t raw_variant_ct, uint32_t orig_variant_ct, uint32_t max_variant_id_slen, uint32_t max_allele_slen, uint32_t xchr_model, double ci_size, double vif_thresh, double ln_pfilter, 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);
123 
124 #ifdef __cplusplus
125 }  // namespace plink2
126 #endif
127 
128 #endif  // __PLINK2_GLM_H__
129