| 1 |
#ifndef __PLINK2_PSAM_H__ |
| 2 |
#define __PLINK2_PSAM_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 |
|
| 21 |
#include "plink2_common.h" |
| 22 |
|
| 23 |
#ifdef __cplusplus |
| 24 |
namespace plink2 { |
| 25 |
#endif |
| 26 |
|
| 27 |
// Key .psam properties: (i) .fam files are valid .psam files; (ii) .fam-like |
| 28 |
// files with an additional 'SID' column ("source ID", disambiguating multiple |
| 29 |
// samples from e.g. the same cancer patient) are valid; (iii) zero, or many, |
| 30 |
// phenotypes are now ok; (iv) Oxford .sample files can be converted to .psam |
| 31 |
// without loss of information; and (v) loader should work on .ped files as |
| 32 |
// well. |
| 33 |
|
| 34 |
// File starts with an arbitrary (possibly zero) number of header lines marked |
| 35 |
// by a leading '#'. All lines which don't start with '#FID' or '#IID' are |
| 36 |
// currently ignored. The #FID/IID line specifies the columns in the .psam |
| 37 |
// file; the following column headers are recognized: |
| 38 |
// IID (required, must be first or second) |
| 39 |
// SID (must immediately follow IID if present) |
| 40 |
// PAT |
| 41 |
// MAT |
| 42 |
// SEX |
| 43 |
// FID must either be the first column, or absent. If it's absent, all FID |
| 44 |
// values are now set to '0' by default, and FID is omitted by default from |
| 45 |
// output files when there's a choice. (This is a change from both v1.9 and |
| 46 |
// v2.0 alpha 1.) |
| 47 |
// Any other value is treated as a phenotype/covariate name. |
| 48 |
// |
| 49 |
// The loader will error out of multiple #FID/IID lines are in the header for |
| 50 |
// some bizarre reason. If no #FID/IID line is present, fam_cols controls the |
| 51 |
// default (e.g. fam_cols == FAM_COL_13456 means "#FID IID PAT MAT SEX PHENO"). |
| 52 |
|
| 53 |
|
| 54 |
// Memory for all the return arrays is allocated off the bottom of g_bigstack. |
| 55 |
|
| 56 |
// todo: the new indiv_represent[] bitvector tracks which sample should be |
| 57 |
// considered the primary one for an individual, when there are multiple |
| 58 |
// samples with identical FID/IID but differing SID. (Default is the first |
| 59 |
// sample for each individual, but if a later sample has SID == '0' that takes |
| 60 |
// precedence.) |
| 61 |
// plink2 order of operations should be arranged so that FID/IID-insensitive |
| 62 |
// sample filters happen first, then indiv_represent is computed, then |
| 63 |
// FID/IID-sensitive sample filters are applied. |
| 64 |
|
| 65 |
// chosen to be likely to fit in L3 cache |
| 66 |
CONSTI32(kCatHtableSize, 524287); |
| 67 |
static_assert(kCatHtableSize >= kMaxPhenoCt, "kCatHtableSize cannot be smaller than kMaxPhenoCt."); |
| 68 |
|
| 69 |
PglErr LoadPsam(const char* psamname, const RangeList* pheno_range_list_ptr, const char* missing_catname, FamCol fam_cols, uint32_t pheno_ct_max, int32_t missing_pheno, uint32_t affection_01, uint32_t no_categorical, uint32_t neg9_pheno_really_missing, uint32_t max_thread_ct, PedigreeIdInfo* piip, uintptr_t** sample_include_ptr, uintptr_t** founder_info_ptr, uintptr_t** sex_nm_ptr, uintptr_t** sex_male_ptr, PhenoCol** pheno_cols_ptr, char** pheno_names_ptr, uint32_t* raw_sample_ct_ptr, uint32_t* pheno_ct_ptr, uintptr_t* max_pheno_name_blen_ptr); |
| 70 |
|
| 71 |
HEADER_INLINE BoolErr IsReservedPhenoName(const char* pheno_name, uint32_t pheno_name_slen) { |
| 72 |
if (pheno_name_slen != 3) { |
| 73 |
return 0; |
| 74 |
} |
| 75 |
// tolerate "SEX" column in phenotype/covariate files; just impose some |
| 76 |
// restrictions on it when writing .psam files. |
| 77 |
return memequal_k(pheno_name, "FID", 3) || memequal_k(pheno_name, "IID", 3) || memequal_k(pheno_name, "SID", 3) || memequal_k(pheno_name, "PAT", 3) || memequal_k(pheno_name, "MAT", 3); |
| 78 |
} |
| 79 |
|
| 80 |
// also for loading covariates. set affection_01 to 2 to prohibit case/control |
| 81 |
PglErr LoadPhenos(const char* pheno_fname, const RangeList* pheno_range_list_ptr, const uintptr_t* sample_include, const SampleIdInfo* siip, const char* missing_catname, uint32_t raw_sample_ct, uint32_t sample_ct, int32_t missing_pheno, uint32_t affection_01, uint32_t no_categorical, uint32_t iid_only, uint32_t numeric_ranges, uint32_t neg9_pheno_really_missing, uint32_t max_thread_ct, PhenoCol** pheno_cols_ptr, char** pheno_names_ptr, uint32_t* pheno_ct_ptr, uintptr_t* max_pheno_name_blen_ptr); |
| 82 |
|
| 83 |
PglErr IgnorePhenosOrCovars(const char* not_pheno_flattened, uint32_t is_covar, PhenoCol** pheno_cols_ptr, char** pheno_names_ptr, uint32_t* pheno_ct_ptr, uintptr_t* max_pheno_name_blen_ptr); |
| 84 |
|
| 85 |
#ifdef __cplusplus |
| 86 |
} // namespace plink2 |
| 87 |
#endif |
| 88 |
|
| 89 |
#endif // __PLINK2_PSAM_H__ |