### Install Development Version from GitHub Source: https://github.com/althonos/pronto/blob/master/README.md Install a development version from GitHub using setuptools. Ensure dependencies are installed first. ```console $ git clone https://github.com/althonos/pronto $ cd pronto # python setup.py install ``` -------------------------------- ### Install Pronto with Pip Source: https://github.com/althonos/pronto/blob/master/README.md Install Pronto using pip. Use `--user` for user-site installation if admin rights are unavailable. ```console # pip install pronto # if you have the admin rights $ pip install pronto --user # install it in a user-site directory ``` -------------------------------- ### Install Pronto using pip Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/install.md Install the Pronto library and its dependencies using pip. This is the recommended method for most users. ```console pip install --user pronto ``` -------------------------------- ### Install Pronto from GitHub using pip Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/install.md Install the development version of Pronto directly from its GitHub repository using pip. This may install an unstable version. ```console pip install --user git+https://github.com/althonos/pronto/ ``` -------------------------------- ### Install Pronto using Conda Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/install.md Install Pronto from the bioconda channel using the conda package manager. Useful for users within the Anaconda ecosystem. ```console conda install -c bioconda pronto ``` -------------------------------- ### Download and Parse MzML File Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/examples/ms.ipynb Downloads an example MzML file from a given URL and parses it using xml.etree.ElementTree. Ensure the 'urllib.request' and 'xml.etree.ElementTree' modules are imported. ```python import urllib.request import xml.etree.ElementTree as etree URL = "http://ftp.ebi.ac.uk/pub/databases/metabolights/studies/public/MTBLS341/pos_Exp2-K3_2-E,5_01_7458.d.mzML" mzml = etree.parse(urllib.request.urlopen(URL)) ``` -------------------------------- ### Get Direct Subclasses and Superclasses Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/updating.md To retrieve only direct subclasses or superclasses, similar to the old `Term.children` and `Term.parents`, use `distance=1` along with `with_self=False`. ```python children: Iterable[Term] = term.subclasses(with_self=False, distance=1) parents: Iterable[Term] = term.superclasses(with_self=False, distance=1) ``` -------------------------------- ### Get True Subclasses and Superclasses Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/updating.md To exclude the term itself from subclass and superclass results, use `with_self=False`. ```python children_iter: Iterable[Term] = term.subclasses(with_self=False) parents_iter: Iterable[Term] = term.superclasses(with_self=False) ``` -------------------------------- ### Load Ontology from URL and OBO Library Source: https://github.com/althonos/pronto/blob/master/README.md Load an ontology from a persistent URL or using the Ontology.from_obo_library method. ```python >>> cl = Ontology("http://purl.obolibrary.org/obo/cl.obo") >>> stato = Ontology.from_obo_library("stato.owl") ``` -------------------------------- ### Visualize Instrument Hierarchy with Vega Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/examples/ms.ipynb Loads a Vega radial tree layout, replaces its default data with the extracted instrument hierarchy, and renders the visualization. Tooltips display the instrument description. ```python import json import urllib.request # Let's use the Vega radial tree example as a basis of the visualization view = json.load(urllib.request.urlopen("https://vega.github.io/vega/examples/radial-tree-layout.vg.json")) # First replace the default data with our own view['data'][0].pop('url') view['data'][0]['values'] = data view['marks'][1]['encode']['enter']['tooltip'] = {"signal": "datum.desc"} view['signals'][4]['value'] = 'cluster' # Render the clustered tree display({"application/vnd.vega.v5+json": view}, raw=True) ``` -------------------------------- ### Load Ontology from Local File Source: https://github.com/althonos/pronto/blob/master/README.md Instantiate an Ontology object from a local ontology file path. Supports compressed files. ```python >>> go = Ontology("tests/data/go.obo.gz") ``` -------------------------------- ### View Pronto Ontology API Reference Source: https://github.com/althonos/pronto/blob/master/README.md Access the complete API reference for the Pronto Ontology directly from your command line using the pydoc tool. ```console $ pydoc pronto.Ontology ``` -------------------------------- ### Import Ontology Class Source: https://github.com/althonos/pronto/blob/master/README.md Import the main Ontology class from the pronto library. ```python >>> from pronto import Ontology ``` -------------------------------- ### Load MS Ontology from OBO Library Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/examples/ms.ipynb Loads the MS Ontology from the OBO library. May produce UnicodeWarnings due to imported legacy ontologies. ```python import pronto ms = pronto.Ontology.from_obo_library("ms.obo") ``` -------------------------------- ### Create and Edit New Term Source: https://github.com/althonos/pronto/blob/master/README.md Create a new term, set its name, and define its superclasses and disjointness relationships. ```python >>> pr = Ontology.from_obo_library("pr.obo") >>> brh = ms.create_term("PR:XXXXXXXX") >>> brh.name = "Bacteriorhodopsin" >>> brh.superclasses().add(pr["PR:000001094"]) # is a rhodopsin-like G-protein >>> brh.disjoint_from.add(pr["PR:000036194"]) # disjoint from eukaryotic proteins ``` -------------------------------- ### Convert OWL Ontology to OBO Format Source: https://github.com/althonos/pronto/blob/master/README.md Serialize an ontology to OBO format using the Ontology.dump method. The output is written to a file in binary write mode. ```python >>> edam = Ontology("http://edamontology.org/EDAM.owl") >>> with open("edam.obo", "wb") as f: ... edam.dump(f, format="obo") ``` -------------------------------- ### Export Ontology to OBO Format Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/updating.md Use `dumps` and `dump` methods for exporting ontologies to OBO or other formats, replacing the direct `ontology.obo` attribute access. ```python # before print(ontology.obo) open("out.obo", "w").write(ontology.obo) ``` ```python # after print(ontology.dumps(format="obo")) ontoloy.dump(open("out.obo", "w"), format="obo") ``` -------------------------------- ### Access Term with URI Compaction Source: https://github.com/althonos/pronto/blob/master/README.md When loading OWL ontologies, URIs are compacted to CURIEs where possible. Access terms using these compacted IDs. ```python >>> aeo = Ontology.from_obo_library("aeo.owl") >>> aeo["AEO:0000078"] Term('AEO:0000078', name='lumen of tube') ``` -------------------------------- ### Access Subclasses and Superclasses Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/updating.md Access subclasses and superclasses using `term.subclasses()` and `term.superclasses()`. These methods return iterators and include the term itself by default. ```python # before children: pronto.TermList = term.rchildren() parents: pronto.TermList = term.rparents() ``` ```python # after children_iter: Iterable[Term] = term.subclasses() parents_iter: Iterable[Term] = term.superclasses() ``` -------------------------------- ### Extract Instruments from MzML Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/examples/ms.ipynb Extracts instrument information by iterating through 'cvParam' elements within the MzML file and checking if their accession IDs are present in the MS ontology's instrument terms. Requires the 'ms' object (presumably a TermSet) and the parsed 'mzml' object. ```python instruments = ms["MS:1000031"].subclasses().to_set().ids study_instruments = [] path = "mzml:instrumentConfigurationList/mzml:instrumentConfiguration/mzml:cvParam" for element in mzml.iterfind(path, {'mzml': 'http://psi.hupo.org/ms/mzml'}): if element.attrib['accession'] in instruments: study_instruments.append(ms[element.attrib['accession']]) print(study_instruments) ``` -------------------------------- ### Find Mismatched CV Terms Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/examples/ms.ipynb Iterates through MzML elements to find 'cvParam' entries where the 'name' attribute does not match the expected name from the ontology based on the 'accession'. Requires the 'ms' ontology to be loaded. ```python mismatches = [ element for element in mzml.iter() if element.tag == "{http://psi.hupo.org/ms/mzml}cvParam" if element.get('accession') in ms if ms[element.get('accession')].name != element.get('name') ] ``` -------------------------------- ### Extract Instrument Hierarchy Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/examples/ms.ipynb Extracts all subclasses of 'MS:1000031' and structures them into a list of dictionaries suitable for tree visualization. Each item includes an ID, name, description, and parent ID if applicable. ```python instruments = ms['MS:1000031'].subclasses().to_set() data = [] for term in instruments: value = {"id": int(term.id[3:]), "name": term.id, "desc": term.name} parents = term.superclasses(with_self=False, distance=1).to_set() & instruments if parents: value['parent'] = int(parents.pop().id[3:]) data.append(value) ``` -------------------------------- ### Find Leaf Terms in Ontology Source: https://github.com/althonos/pronto/blob/master/README.md Iterate over all terms in an ontology and print the IDs of terms that are leaves in the class inclusion graph using the is_leaf method. ```python >>> ms = Ontology("ms.obo") >>> for term in ms.terms(): ... if term.is_leaf(): ... print(term.id) MS:0000000 MS:1000001 ... ``` -------------------------------- ### Report Mismatched CV Terms Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/examples/ms.ipynb Prints a formatted report of the identified mismatches, showing the accession, the name found in the MzML file, and the expected name from the ontology. ```python for m in mismatches: print(f"{m.get('accession')}: {m.get('name')!r} (should be {ms[m.get('accession')].name!r})") ``` -------------------------------- ### Silence Pronto Warnings Source: https://github.com/althonos/pronto/blob/master/README.md Disable Pronto warnings by importing the warnings module and using filterwarnings. This is useful if inconsistencies are acceptable. ```python import warnings import pronto warnings.filterwarnings("ignore", category=pronto.warnings.ProntoWarning) ``` -------------------------------- ### Convert Subclass/Superclass Iterators to TermSet Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/updating.md Convert the iterator results from `subclasses()` or `superclasses()` to a `TermSet` using the `to_set()` method to maintain compatibility with previous `TermList` expectations. ```python # you can use `to_set` to get a `TermSet` from the iterator children: pronto.TermSet = term.subclasses().to_set() parents: pronto.TermSet = term.superclasses().to_set() ``` -------------------------------- ### Extract Instrument Manufacturers Source: https://github.com/althonos/pronto/blob/master/docs/source/guide/examples/ms.ipynb Extracts the manufacturers of the identified instruments. It first determines the direct subclasses of 'instrument model' (MS:1000031) as potential manufacturers and then finds the intersection between these manufacturers and the superclasses of each found instrument. Requires the 'ms' object and the 'study_instruments' list. ```python manufacturers = ms['MS:1000031'].subclasses(distance=1, with_self=False).to_set() study_manufacturers = [] for instrument in study_instruments: study_manufacturers.extend(manufacturers & instrument.superclasses().to_set()) print(study_manufacturers) ``` -------------------------------- ### Access Term by Accession ID Source: https://github.com/althonos/pronto/blob/master/README.md Access a term within an Ontology object using its identifier as a dictionary key. ```python >>> cl['CL:0002116'] Term('CL:0002116', name='B220-low CD38-positive unswitched memory B cell') ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.