diff options
| author | Pjotr Prins | 2025-12-07 12:03:51 +0100 |
|---|---|---|
| committer | Pjotr Prins | 2025-12-07 12:03:51 +0100 |
| commit | 4486e91d7228e9c79950236d7f146db2a0b099ee (patch) | |
| tree | b9e90cf8102dd5dc2d83427a1160c707e40692a6 /src/gemma_io.cpp | |
| parent | 127ee6431063dc3e1b83cb1ef3113850697a88f2 (diff) | |
| download | pangemma-4486e91d7228e9c79950236d7f146db2a0b099ee.tar.gz | |
Support loco for mdb kinship compute
Diffstat (limited to 'src/gemma_io.cpp')
| -rw-r--r-- | src/gemma_io.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/gemma_io.cpp b/src/gemma_io.cpp index e183e3f..3e290f4 100644 --- a/src/gemma_io.cpp +++ b/src/gemma_io.cpp @@ -1478,8 +1478,27 @@ void ReadFile_eigenD(const string &file_kd, bool &error, gsl_vector *eval) { // Read bimbam mean genotype file and calculate kinship matrix. -gsl_matrix *mdb_calc_kin(const string file_geno, bool is_loco, const int k_mode) { +gsl_matrix *mdb_calc_kin(const string file_geno, const int k_mode, const string loco) { checkpoint("mdb-kin",file_geno); + bool is_loco = !loco.empty(); + + // Convert loco string to what we use in the chrpos index + uint8_t loco_chr = 0; + if (is_loco) { + if (loco == "X") { + loco_chr = CHR_X; + } else if (loco == "Y") { + loco_chr = CHR_Y; + } else if (loco == "M") { + loco_chr = CHR_M; + } else { + try { + loco_chr = static_cast<uint8_t>(stoi(loco)); + } catch (...) { + loco_chr = 0; + } + } + } /* Create and open the LMDB environment: */ auto env = lmdb::env::create(); @@ -1552,6 +1571,12 @@ gsl_matrix *mdb_calc_kin(const string file_geno, bool is_loco, const int k_mode) if (indicator_snp[t] == 0) continue; */ + const uint8_t* data = reinterpret_cast<const uint8_t*>(key.data()); + auto chr = static_cast<uint8_t>(data[1]); + + if (is_loco && loco_chr == chr) + continue; + #if !defined NDEBUG size_t num_floats = value.size() / sizeof(float); assert(num_floats == ni_total); |
