From 4486e91d7228e9c79950236d7f146db2a0b099ee Mon Sep 17 00:00:00 2001 From: Pjotr Prins Date: Sun, 7 Dec 2025 12:03:51 +0100 Subject: Support loco for mdb kinship compute --- src/gemma_io.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/gemma_io.cpp') 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(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(key.data()); + auto chr = static_cast(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); -- cgit 1.4.1