|
2 | 2 | // |
3 | 3 | // GetData.cpp: Get data from a SeqArray GDS file |
4 | 4 | // |
5 | | -// Copyright (C) 2015-2024 Xiuwen Zheng |
| 5 | +// Copyright (C) 2015-2025 Xiuwen Zheng |
6 | 6 | // |
7 | 7 | // This file is part of SeqArray. |
8 | 8 | // |
@@ -58,6 +58,7 @@ static const string VAR_GENO_INDEX("@genotype"); |
58 | 58 | static const string VAR_PHASE("phase"); |
59 | 59 |
|
60 | 60 | // variable list: internally generated |
| 61 | +static const string VAR_CHROM_RLE("$chromosome"); |
61 | 62 | static const string VAR_DOSAGE("$dosage"); |
62 | 63 | static const string VAR_DOSAGE_ALT("$dosage_alt"); |
63 | 64 | static const string VAR_DOSAGE_ALT2("$dosage_alt2"); |
@@ -152,6 +153,38 @@ static SEXP get_chrom(CFileInfo &File, TVarMap &Var, void *param) |
152 | 153 | return rv_ans; |
153 | 154 | } |
154 | 155 |
|
| 156 | +/// get RLE-coded chromosome from '$chromosome' |
| 157 | +static SEXP get_chrom_rle(CFileInfo &File, TVarMap &Var, void *param) |
| 158 | +{ |
| 159 | + int n = File.VariantSelNum(); |
| 160 | + SEXP rv_ans = PROTECT(NEW_CHARACTER(n)); |
| 161 | + if (n > 0) |
| 162 | + { |
| 163 | + CChromIndex &Chrom = File.Chromosome(); |
| 164 | + TSelection &Sel = File.Selection(); |
| 165 | + C_BOOL *s = Sel.pVariant + Sel.varStart; |
| 166 | + size_t p = 0, i = Sel.varStart; |
| 167 | + SEXP lastR = Rf_mkChar(""); |
| 168 | + string lastS; |
| 169 | + for (; n > 0; i++) |
| 170 | + { |
| 171 | + if (*s++) |
| 172 | + { |
| 173 | + const string &ss = Chrom[i]; |
| 174 | + if (ss != lastS) |
| 175 | + { |
| 176 | + lastS = ss; |
| 177 | + lastR = Rf_mkChar(ss.c_str()); |
| 178 | + } |
| 179 | + SET_STRING_ELT(rv_ans, p++, lastR); |
| 180 | + n--; |
| 181 | + } |
| 182 | + } |
| 183 | + } |
| 184 | + UNPROTECT(1); |
| 185 | + return rv_ans; |
| 186 | +} |
| 187 | + |
155 | 188 | /// get variant-specific data from node without indexing (e.g., variant.id) |
156 | 189 | static SEXP get_data_1d(CFileInfo &File, TVarMap &Var, void *param) |
157 | 190 | { |
@@ -1141,7 +1174,11 @@ COREARRAY_DLL_LOCAL TVarMap &VarGetStruct(CFileInfo &File, const string &name) |
1141 | 1174 | } else |
1142 | 1175 | // =========================================================== |
1143 | 1176 | // internally generated variables |
1144 | | - if (name == VAR_DOSAGE) |
| 1177 | + if (name == VAR_CHROM_RLE) |
| 1178 | + { |
| 1179 | + vm.Init(File, VAR_CHROM, get_chrom_rle); |
| 1180 | + CHECK_VARIANT_ONE_DIMENSION |
| 1181 | + } else if (name == VAR_DOSAGE) |
1145 | 1182 | { |
1146 | 1183 | vm.Func = get_dosage; |
1147 | 1184 | } else if (name == VAR_DOSAGE_ALT) |
|
0 commit comments