crispr_analysis_utils.inference_input¶
crispr_analysis_utils.inference_input ¶
One MuData an inference reads, laid out like the IGVF CRISPR pipeline's.
Takes the QC'd per-channel objects of mudata_builder and qc, each already
carrying guide calls in mod['guide'].layers['guide_assignment'], and the
pairs of pairs, and writes the object the pipeline hands to SCEPTRE:
- one cell index across both modalities, the
{barcode}_{measurement_set}idsmudata_buildergave, refused if two channels share one; - unversioned gene ids, so they match the pairs;
intended_target_keyon every guide, and the controls bucketed asnon-targeting|Nby the pipeline's own rule;- the pipeline's covariate names in
obs; moiandcapture_methodinmod['guide'].uns;pairs_to_testinuns, restricted to the genes and guides present.
Guide calls are not made here: how a guide is called is the analysis's decision, and the layer records it.
ASSIGNMENT
module-attribute
¶
ASSIGNMENT = 'guide_assignment'
The layer of binary guide calls, as the pipeline names it.
CONTROL_TYPES
module-attribute
¶
CONTROL_TYPES = ('safe-targeting', 'non-targeting', 'negative control')
Guide types the pipeline treats as controls, as intended_target_key_utils does.
PAIR_COLUMNS
module-attribute
¶
PAIR_COLUMNS = ('guide_id', 'gene_id', *TARGET_COLUMNS, 'intended_target_key', 'pair_type')
What uns['pairs_to_test'] holds, in the pipeline's order; extra pair columns follow.
COVARIATES
module-attribute
¶
COVARIATES = ('batch', 'total_gene_umis', 'total_guide_umis', 'num_expressed_genes', 'percent_mito')
Root obs: the pipeline's design frame under its own names.
InputError ¶
Bases: RuntimeError
The channels cannot be made into one inference object.
Source code in src/crispr_analysis_utils/inference_input.py
70 71 | |
RunResult
dataclass
¶
What run produced.
Source code in src/crispr_analysis_utils/inference_input.py
74 75 76 77 78 79 80 81 | |
target_keys ¶
target_keys(var: DataFrame) -> pd.DataFrame
Add intended_target_key, and bucket the controls as the pipeline does.
A targeting guide's key is coords::name::chr::start::end, or
name_only::name without coordinates. Control guides (targeting
false, or a control type) are sorted by guide id and cut into groups
the size of the median number of guides per targeting element, named
non-targeting|N, with chromosome non-targeting and start and end
N. That is the rule of the pipeline's
annotate_intended_target_groups; an id-preserving element_id it
also honours is absent from the IGVF table.
Parameters:
-
var(DataFrame) –mod['guide'].var, indexed by guide id, withtargeting,typeand the fourintended_target_*columns.
Returns:
-
DataFrame–A copy, with
targetingas bool, coordinates asInt64and the new key column.
Source code in src/crispr_analysis_utils/inference_input.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
cell_covariates ¶
cell_covariates(gene, guide) -> tuple[pd.DataFrame, pd.DataFrame]
Per-cell totals under the pipeline's names.
Returns:
-
tuple of pandas.DataFrame–For
mod['gene'].obs:total_gene_umis,num_expressed_genes,percent_mitoandpct_counts_ribo, percentages from 0 to 100, mitochondrial by contig and ribosomal asqc.gene_classesdecides. Formod['guide'].obs:total_guide_umisandnum_expressed_guides.
Source code in src/crispr_analysis_utils/inference_input.py
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 | |
pairs_frame ¶
pairs_frame(pairs: DataFrame, guide_var: DataFrame, gene_ids: Index) -> tuple[pd.DataFrame, dict]
The pairs the object can test, keyed as the pipeline keys them.
Parameters:
-
pairs(DataFrame) –pairs.runoutput:guide_id,gene_id,pair_typeand the fourintended_target_*columns, among others. -
guide_var(DataFrame) –target_keysoutput. -
gene_ids(Index) –The object's gene index.
Returns:
-
tuple–The kept pairs, with
intended_target_keytaken from the guide and low-cardinality text as categoricals; and a count of what was dropped, by reason, since the pipeline drops such rows without a word.
Source code in src/crispr_analysis_utils/inference_input.py
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 | |
build ¶
build(channels: list, pairs: DataFrame, *, moi: str, capture_method: str, min_guides: int | None = None, max_guides: int | None = None)
Assemble channels into one inference object.
Parameters:
-
channels(list) –QC'd per-channel MuData objects, each with
geneandguideand a binarymod['guide'].layers['guide_assignment']. -
pairs(DataFrame) –The pairs to test.
-
moi(str) –highorlow. -
capture_method(str) –How guides were captured, as the pipeline records it (e.g.
CROP-seqordirect capture). Carried, not read. -
min_guides(int | None, default:None) –Keep cells with at least, and at most, this many assigned guides. None keeps every cell.
-
max_guides(int | None, default:None) –Keep cells with at least, and at most, this many assigned guides. None keeps every cell.
Returns:
-
tuple–The MuData, and a report of what was kept and dropped.
Raises:
-
InputError–A channel lacks a modality or the guide calls, the channels disagree on their features, or the gene ids collide once unversioned.
Source code in src/crispr_analysis_utils/inference_input.py
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 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | |
run ¶
run(inputs: list[str | PathLike[str]], pairs: str | PathLike[str], outdir: str | PathLike[str], *, name: str, moi: str = 'high', capture_method: str, min_guides: int | None = None, max_guides: int | None = None) -> RunResult
Read channels and pairs, build the object, and write it.
Parameters:
-
inputs(list[str | PathLike[str]]) –QC'd per-channel
.h5mufiles with guide calls. -
pairs(str | PathLike[str]) –pairs_to_test.csvfrompairs.run. -
outdir(str | PathLike[str]) –Where the object goes. Nothing is written outside it.
-
name(str) –The object's file stem, such as
day4. -
moi(str, default:'high') –As in
build. -
capture_method(str, default:'high') –As in
build. -
min_guides(str, default:'high') –As in
build. -
max_guides(str, default:'high') –As in
build.
Returns:
-
RunResult–The path written, the report and the run record.
Source code in src/crispr_analysis_utils/inference_input.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |