Hidden Functions
Hidden functions for all MixIns.
Advanced / Internal
The functions in this section are internal utilities. They may change
without notice and are not guaranteed to remain stable across releases.
Use only if you understand the internal architecture of pAnnData.
src.scpviz.pAnnData.analysis
src.scpviz.pAnnData.base
src.scpviz.pAnnData.editing
src.scpviz.pAnnData.enrichment
_pretty_vs_key
Format a DE contrast key into a human-readable string.
This function attempts to convert a string representation of a DE comparison
(e.g., a list of dictionaries) into a simplified "group1 vs group2" format,
using the values from each dictionary in the left and right group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
k |
str
|
DE key string, typically in the format |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
A simplified, human-readable version of the DE comparison key. |
Source code in src/scpviz/pAnnData/enrichment.py
_resolve_de_key
Resolve a user-supplied DE key to a valid key stored in .stats["de_results"].
This function matches a flexible, human-readable DE key against the internal keys
stored in the DE results dictionary. It supports both raw and pretty-formatted keys,
and can handle suffixes like _up or _down for directional analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stats_dict |
dict
|
Dictionary of DE results (typically |
required |
user_key |
str
|
User-supplied key to resolve, e.g., "AS_kd vs AS_sc_down". |
required |
debug |
bool
|
If True, prints detailed debug output for tracing. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
The matching internal DE result key. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no matching key is found. |
Source code in src/scpviz/pAnnData/enrichment.py
src.scpviz.pAnnData.filtering
_detect_ambiguous_input
Detects ambiguous user input mixing file and group identifiers.
This helper checks whether the group list includes both
file-like identifiers (present in .var as 'Found In: .uns as ('group', 'count') tuples).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group |
list of str
|
User-provided identifiers for filtering. |
required |
var |
DataFrame
|
The |
required |
group_metrics |
DataFrame
|
MultiIndex DataFrame from |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
(bool, list, list)
|
(is_ambiguous, annotated_files, annotated_groups) - is_ambiguous (bool): True if both file-like and group-like entries coexist. - annotated_files (list): Entries that match file-level columns. - annotated_groups (list): Entries that match group-level metrics. |
Source code in src/scpviz/pAnnData/filtering.py
src.scpviz.pAnnData.history
src.scpviz.pAnnData.identifier
src.scpviz.pAnnData.io
_import_proteomeDiscoverer
_import_proteomeDiscoverer(prot_file: Optional[str] = None, pep_file: Optional[str] = None, obs_columns: Optional[List[str]] = ['sample'], **kwargs)
Source code in src/scpviz/pAnnData/io.py
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 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 | |
_import_diann
_import_diann(report_file: Optional[str] = None, obs_columns: Optional[List[str]] = None, delimiter: Optional[str] = '_', obs: Optional[pd.DataFrame] = None, prot_value='PG.MaxLFQ', pep_value='Precursor.Normalised', prot_var_columns=['Genes', 'Master.Protein'], pep_var_columns=['Genes', 'Protein.Group', 'Precursor.Charge', 'Modified.Sequence', 'Stripped.Sequence', 'Precursor.Id', 'All Mapped Proteins', 'All Mapped Genes'], **kwargs)
Source code in src/scpviz/pAnnData/io.py
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 466 467 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 | |
_create_pAnnData_from_parts
_create_pAnnData_from_parts(prot_X, pep_X, rs, prot_obs, prot_var, prot_obs_names, prot_var_names, pep_obs=None, pep_var=None, pep_obs_names=None, pep_var_names=None, obs_columns=None, X_mbr_prot=None, X_mbr_pep=None, X_qval_prot=None, X_qval_pep=None, X_precursor_pep=None, found_threshold=0, fdr_threshold=0.01, metadata=None, history_msg='')
Assemble a pAnnData object from processed matrices and metadata.
This function is typically called internally by import functions. It constructs
.prot and .pep AnnData objects, assigns optional metadata and MBR layers,
adds identifier mappings and sample-level summary metrics, and returns a
validated pAnnData object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prot_X |
csr_matrix
|
Protein-level expression matrix (samples × proteins). |
required |
pep_X |
csr_matrix or None
|
Peptide-level expression matrix (samples × peptides). |
required |
rs |
csr_matrix or None
|
Binary matrix linking proteins (rows) to peptides (columns). |
required |
prot_obs |
DataFrame
|
Sample-level metadata for protein data. |
required |
prot_var |
DataFrame
|
Feature-level metadata for proteins. |
required |
prot_obs_names |
list - like
|
Sample identifiers for |
required |
prot_var_names |
list - like
|
Protein accession identifiers for |
required |
pep_obs |
DataFrame
|
Sample metadata for |
None
|
pep_var |
DataFrame
|
Feature metadata for peptides. |
None
|
pep_obs_names |
list - like
|
Sample identifiers for |
None
|
pep_var_names |
list - like
|
Peptide identifiers. |
None
|
obs_columns |
list of str
|
Columns from filenames to include in |
None
|
X_mbr_prot |
ndarray or DataFrame
|
Optional protein-level MBR identification info. |
None
|
X_mbr_pep |
ndarray or DataFrame
|
Optional peptide-level MBR identification info. |
None
|
X_qval_prot |
ndarray or DataFrame
|
Optional protein-level Q-value info. |
None
|
X_qval_pep |
ndarray or DataFrame
|
Optional peptide-level Q-value info. |
None
|
X_precursor_pep |
ndarray or DataFrame
|
Optional peptide-level precursor quantity info. (for directLFQ normalization) |
None
|
metadata |
dict
|
Optional dictionary of import metadata (e.g. |
None
|
history_msg |
str
|
Operation description to append to the history log. |
''
|
Returns:
| Name | Type | Description |
|---|---|---|
pAnnData |
Initialized object with |
Note
This is a low-level function. In most cases, users should call import_data(), import_proteomeDiscoverer(), or import_diann() instead.
Source code in src/scpviz/pAnnData/io.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 | |
_build_rs_matrix
Build a sparse boolean RS (protein × peptide) relational matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pep_prot_list |
list or Series
|
List/Series where each entry contains one or more protein accessions (as lists or split strings). |
required |
prot_var_names |
list
|
Ordered list of protein accessions to align RS columns. If None, uses the order returned by MultiLabelBinarizer. |
None
|
Returns:
| Type | Description |
|---|---|
|
scipy.sparse.csr_matrix: Sparse boolean RS matrix (peptides × proteins). |