just_dna_enricher.cpic_build¶
just_dna_enricher.cpic_build ¶
Build the CPIC snapshot ([dev]) — the whole PostgREST database as five parquet tables (RM38).
CPIC is open and unauthenticated, so this cache is not about access. It is about a host not spending one shared per-IP allowance on every caller's request, and about the terms being accepted once, by the operator who built the snapshot, rather than implicitly on each incoming request. That is RM38's argument, and it is the same one for ClinPGx; PharmVar adds a third reason (a personal key) that these two do not have.
The whole database fits, comfortably. Probed live on 2026-08-07: 132 genes, 1,361 alleles, 1,337 allele definitions over 3,120 location values, 2,115 recommendations across 324 drugs, and 112,754 diplotypes — the last being the only large one, and four narrow string columns of it is under a megabyte of zstd parquet. There is no gene filter here for that reason: a snapshot that covers only the genes the operator thought of is a snapshot that silently answers "CPIC has nothing" for the next one.
Verbatim, and mapped at read time. The vocabulary translations (clinicalfunctionalstatus →
VALID_FUNCTION_STATUS, classification → VALID_RECOMMENDATION_STRENGTH) are not applied here.
They live in cpic.map_function_status / map_classification, which the snapshot client calls on the
way out — so a mapping fix reaches an already-built snapshot, and a live answer and a snapshot answer
are the same object by construction rather than by inspection. Storing a source's value verbatim is the
house rule; the one documented exception is an encoding that lies about its own order (ClinGen's dosage
codes), and CPIC's prose does not.
recommendation.phenotypes is a JSON map, so it is flattened one row per gene named. The live
client keeps a recommendation only when it names exactly one gene — a row about CYP2C19 and CYP2D6 is
not a statement about CYP2C19 alone — so gene_count travels with each flattened row and the reader
applies the identical rule. Flattening without it would silently promote multi-gene rows.
Builder-only: polars is a guarded [dev] import, and the runtime pass reads the parquet through
DuckDB, which is core. Builder in polars, runtime in duckdb — the house convention.
CpicBuildError ¶
Bases: RuntimeError
The CPIC snapshot could not be built.
build_snapshot ¶
build_snapshot(
out_dir: Path,
*,
endpoint: str = DEFAULT_CPIC_ENDPOINT,
client: CpicClient | None = None,
) -> CpicBuildResult
Fetch CPIC whole and write data/*.parquet + release.json under out_dir.
built_at is the only per-run byte and it lives in release.json, outside the parquet, exactly as
in the ClinVar and constraint builders.
Source code in enricher/src/just_dna_enricher/cpic_build.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | |