{mod}raven_toolbox.localization assigns reactions to compartments by MILP — deterministic
(not simulated annealing), predictor-agnostic, and partial-update friendly.
-
Load predictor/database scores into the
gene × compartment{class}raven_toolbox.localization.LocalizationScoresframe: {func}raven_toolbox.localization.load_deeploc(DeepLoc 2 per-protein CSV), {func}raven_toolbox.localization.load_mulocdeep(MULocDeep wide table), {func}raven_toolbox.localization.load_compartments(COMPARTMENTS evidence database), or {func}raven_toolbox.localization.load_uniprot(curated UniProtKBSubcellular location). {func}raven_toolbox.localization.fetch_uniprot_localizationqueries the UniProt REST API by organism id directly, no manual export needed. Pass {data}raven_toolbox.localization.DEFAULT_COMPARTMENT_MAPto rename predictor labels to your model's compartment ids. raven-toolbox does not shell out to the predictor — run it separately and feed in its output.Fuse and tune the evidence. Since no single source is authoritative (two curated sources agree only ~90% on yeast-GEM — see the DeepLoc benchmark), {func}
raven_toolbox.localization.combine_scoresmerges severalLocalizationScoresinto a consensus (agreement reinforced).load_deeplocalso takesmin_confidence=(drop unreliable low-confidence genes — DeepLoc's probability is well calibrated),membrane_split={"m":"mm"}(route mitochondrion to its membrane sub-compartment using the transmembrane signal; mito only), andnormalise=False(keep raw probabilities instead of rescaling each gene's best compartment to 1.0 — accuracy-neutral for assignment, so the default normalises; opt out when you want the calibrated magnitudes, e.g. for triage). -
Predict / apply: {func}
raven_toolbox.localization.predict_localizationis the MILP entry point. Pass the set of reactions to relocate (everything else is pinned); extra compartments beyond a reaction's primary one pay amulti_compartment_penalty. Withapply=Falseyou get a {class}raven_toolbox.localization.LocalizationProposaldiff to inspect before committing; {func}raven_toolbox.localization.apply_localizationapplies a result. -
Triage for curation (optional): {func}
raven_toolbox.localization.triage_localizationtakes the proposal + scores and returns a {class}raven_toolbox.localization.ReviewReportranking the genes/reactions whose localisation is shakiest (low confidence, near-ties, source disagreement, no evidence, low-trust compartment, multi-localisation), each with a reason — so a curator knows where to look. Passload_deeploc(..., keep_raw_confidence=True)so the (strongest) confidence signal survives normalisation.
The defaults and accuracy (including a predictor-noise sweep) are validated against curated yeast-GEM in the yeast localization benchmark.
Sequence predictors take a protein FASTA and emit the per-protein table the loaders read back.
{func}raven_toolbox.localization.prepare_deeploc_input writes that FASTA for your model's genes —
sequences fetched from UniProtKB, headers set to the gene ids so the predictor's output lines up
with the model (and with {func}raven_toolbox.localization.load_deeploc) without remapping:
from raven_toolbox.localization import prepare_deeploc_input, load_deeploc, DEFAULT_COMPARTMENT_MAP
# yeast-GEM gene ids are ORF names (e.g. YNR001C) = UniProt ordered-locus, the default key
res = prepare_deeploc_input(model, 559292, "deeploc_yeast.fasta") # 559292 = S. cerevisiae
print(res) # "1143/1143 sequences -> deeploc_yeast_001.fasta, ... (0 missing)"
print(res.missing) # genes with no reviewed UniProt sequence — chase these separately
# ... run DeepLoc 2.1 on res.paths yourself, then:
scores = load_deeploc("deeploc_results.csv", compartment_map=DEFAULT_COMPARTMENT_MAP)DeepLoc 2.1 has no public batch API, so run it yourself on the FASTA:
the web server (max 500 sequences per
submission — prepare_deeploc_input chunks the FASTA at that limit into …_001.fasta, …_002.fasta,
…) or the downloadable standalone (no limit; pass max_records_per_file=None). Sequences must be
≥ 10 aa (enforced). {func}raven_toolbox.localization.fetch_protein_sequences and
{func}raven_toolbox.localization.write_fasta are the underlying building blocks if you need finer
control. A ready-to-run script is scripts/prepare_deeploc_yeast.py.