A result named by catalog keys¶
as_mudata() turns the MuData or AnnData APB2 wrote into a new MuData that holds only the fields the named catalog sets describe, each under its key. Any set works. write_h5mu writes the new object like any MuData, and the source object is left unchanged.
import mudata
from apb_catalog.api_pandas import DataCatalog
mdata = mudata.read_h5mu("diann.h5mu") # DIA-NN 1.8.1: precursors and protein groups
keyed = DataCatalog(mdata, "abundance_alpha", "confidence_alpha", "apb_alpha").as_mudata()
keyed.write_h5mu("diann_keyed.h5mu")
keyed
MuData object with n_obs × n_vars = 4 × 12
uns: 'catalog'
2 modalities
peptidoform_ion: 4 × 6
var: 'q_value', 'library_q_value', 'peptide', 'peptidoform', 'peptidoform_ion', 'decoy', 'contaminant', 'protein_assignment', 'fasta_accessions'
uns: 'catalog'
layers: 'intensity', 'intensity_norm_settings', 'q_value', 'pep'
protein: 4 × 6
var: 'library_q_value', 'q_value', 'decoy', 'contaminant', 'protein_assignment', 'fasta_accessions'
uns: 'catalog'
layers: 'intensity', 'intensity_norm_settings[aggregation=top_n]', 'intensity_norm_settings[aggregation=maxlfq]', 'q_value'
What the new object holds¶
- Sets: the named ones alone;
apb_alphabrings the identifiers and thedecoyandcontaminantflags only when named - Modalities: one per level that has a cataloged field;
levels["protein"].as_anndata()converts a single level layers,var,obs: one entry per cataloged field, named by its key- Run and feature names: the result's own
X: empty, since no set says which layer is primary- A field two keys name: written under both; DIA-NN's
Protein_Groupis bothprotein_assignmentandfasta_accessions - A field in
varm: becomes avarcolumn
Layers only¶
The abundance set's keys are all layers, so on its own it gives a MuData of layers; the run and feature names stay as obs_names and var_names:
DataCatalog(mdata, "abundance_alpha").as_mudata()
MuData object with n_obs × n_vars = 4 × 12
uns: 'catalog'
2 modalities
peptidoform_ion: 4 × 6
uns: 'catalog'
layers: 'intensity', 'intensity_norm_settings'
protein: 4 × 6
uns: 'catalog'
layers: 'intensity', 'intensity_norm_settings[aggregation=top_n]', 'intensity_norm_settings[aggregation=maxlfq]'
One key, two fields¶
DIA-NN 1.8 reports two protein intensities normalized as the run was set up: PG_Normalised, from the top N precursors, and PG_MaxLFQ. Both are intensity_norm_settings. The qualifier that tells them apart is added to the key, paired with its value:
| Column | DIA-NN's name |
|---|---|
intensity |
PG_Quantity |
intensity_norm_settings[aggregation=top_n] |
PG_Normalised |
intensity_norm_settings[aggregation=maxlfq] |
PG_MaxLFQ |
q_value |
PG_Q_Value |
Two fields that no qualifier tells apart get their own name as well. With an SDRF and obs_annotation_alpha named, every factor column is group, so the factors treatment and dose become group[field=factor_value_treatment] and group[field=factor_value_dose].
The record in uns["catalog"]¶
Each column records where it came from:
protein = keyed["protein"]
protein.uns["catalog"]["layers"]["intensity_norm_settings[aggregation=maxlfq]"]
{'set': 'abundance_alpha', 'key': 'intensity_norm_settings', 'qualifiers': {'normalization': 'run_setting', 'aggregation': 'maxlfq', 'ms_level': 'ms2'}, 'location': 'layers', 'name': 'PG_MaxLFQ'}
layers,var,obs: for each column, its set, key, qualifiers, and the level's own name for the field and where it satabsent: the required and recommended keys the level lacks. Spectronaut 21's ion level reports no unnormalized intensity, so withabundance_alphathe record reads{'layers': {'intensity': 'recommended'}}source: the level's APB2 record,uns["apb"]as the result held it- MuData root: its own
uns["catalog"]names the sets and holds the result's root record
From a Parquet or DuckDB result¶
as_mudata starts from the AnnData or MuData APB2 wrote. Write a result in another format to h5mu first:
from pathlib import Path
from apb2.api import read_parsed_levels, write_parsed_levels
write_parsed_levels(read_parsed_levels(Path("diann.parquet")), Path("diann.h5mu"))