예제 #1
0
def change_model_metabolites(curation_metabolites=None, content=None):
    """
    Changes metabolites' identifiers

    This function changes metabolites' identifiers according to information
    about translation.

    arguments:
        curation_metabolites (list<dict<str>>): changes to information about
            metabolites
        content (object): content from file in Systems Biology Markup Language
            (XML)

    raises:

    returns:
        (object): content with changes

    """

    # Copy and interpret content.
    reference = metabocurator_collection.copy_interpret_content_recon2m2(
        content=content)
    # Change content for each combination of original and novel identifiers.
    for row in curation_metabolites:
        # Construct targets to recognize original and novel identifiers.
        # Use trailing underscore to match complete identifiers.
        original_elements = [row["identifier_original"], "_"]
        original_target = "".join(original_elements)
        novel_elements = [row["identifier_novel"], "_"]
        novel_target = "".join(novel_elements)
        # Change identifiers of metabolites.
        for metabolite in reference["metabolites"].findall(
                "version:species", reference["space"]):
            # Determine whether to change metabolite's identifier.
            if original_target in metabolite.attrib["id"]:
                metabolite.attrib["id"] = metabolite.attrib["id"].replace(
                    original_target, novel_target)
        # Change identifiers of reactions' metabolites.
        for reaction in reference["reactions"].findall("version:reaction",
                                                       reference["space"]):
            # Search reaction's metabolites.
            for metabolite in reaction.iter(
                    "{http://www.sbml.org/sbml/level2/version4}speciesReference"
            ):
                # Determine whether to change metabolite's identifier.
                if original_target in metabolite.attrib["species"]:
                    metabolite.attrib["species"] = (
                        metabolite.attrib["species"].replace(
                            original_target, novel_target))
    # Return content with changes.
    return reference["content"]
예제 #2
0
def remove_model_metabolite_prefix(content=None):
    """
    Removes unnecessary prefixes from identifiers for model's entities

    This function removes unnecessary prefixes from identifiers for
    metabolites.

    arguments:
        content (object): content from file in Systems Biology Markup Language
            (XML)

    raises:

    returns:
        (object): content with changes

    """

    # Copy and interpret content.
    reference = metabocurator_collection.copy_interpret_content_recon2m2(
        content=content)
    # Remove prefixes from identifiers for metabolites.
    for metabolite in reference["metabolites"].findall("version:species",
                                                       reference["space"]):
        # Remove prefix from metabolite's identifier.
        novel_identifier = re.sub(r"^M_", "", metabolite.attrib["id"])
        metabolite.attrib["id"] = novel_identifier
        # Search metabolite's annotation.
        for description in metabolite.iter(
                "{http://www.w3.org/1999/02/22-rdf-syntax-ns#}description"):
            # Remove prefix from metabolite's identifier.
            novel_identifier = re.sub(
                r"^#M_", "#", description.
                attrib["{http://www.w3.org/1999/02/22-rdf-syntax-ns#}about"])
            description.attrib[
                "{http://www.w3.org/1999/02/22-rdf-syntax-ns#}about"] = novel_identifier
    # Remove prefixes from identifiers for reactions' metabolites.
    for reaction in reference["reactions"].findall("version:reaction",
                                                   reference["space"]):
        # Search reaction's metabolites.
        for metabolite in reaction.iter(
                "{http://www.sbml.org/sbml/level2/version4}speciesReference"):
            # Remove prefix from metabolite's identifier.
            novel_identifier = re.sub(r"^M_", "", metabolite.attrib["species"])
            metabolite.attrib["species"] = novel_identifier
    # Return content with changes.
    return reference["content"]
예제 #3
0
def change_model_boundary(content=None):
    """
    Changes annotations for a model's boundary

    This function changes annotations of a model's boundary in compartments,
    metabolites, and reactions.

    arguments:
        content (object): content from file in Systems Biology Markup Language
            (XML)

    raises:

    returns:
        (object): content with changes

    """

    # Copy and interpret content.
    reference = metabocurator_collection.copy_interpret_content_recon2m2(
        content=content)
    # Correct designation of model's boundary in metabolites.
    for metabolite in reference["metabolites"].findall("version:species",
                                                       reference["space"]):
        # Determine whether metabolite's compartment is model's boundary.
        if "boundary" in metabolite.attrib["id"]:
            novel_identifier = re.sub(r"_[eciglmnrx]_boundary", "_b",
                                      metabolite.attrib["id"])
            metabolite.attrib["id"] = novel_identifier
            novel_compartment = "b"
            metabolite.attrib["compartment"] = novel_compartment
    # Correct designation of model's boundary in reactions.
    for reaction in reference["reactions"].findall("version:reaction",
                                                   reference["space"]):
        # Search reaction's metabolites.
        for metabolite in reaction.iter(
                "{http://www.sbml.org/sbml/level2/version4}speciesReference"):
            # Determine whether metabolite's compartment is model's boundary.
            if "boundary" in metabolite.attrib["species"]:
                novel_identifier = re.sub(r"_[eciglmnrx]_boundary", "_b",
                                          metabolite.attrib["species"])
                metabolite.attrib["species"] = novel_identifier
    # Return content with changes.
    return reference["content"]
예제 #4
0
def count_model_sets_entities(content=None):
    """
    Counts compartments, reactions, and metabolites in model.

    arguments:
        content (object): content from file in Systems Biology Markup Language
            (XML)

    raises:

    returns:
        (dict<int>): summary

    """

    # Copy and interpret content.
    reference = metabocurator_collection.copy_interpret_content_recon2m2(
        content=content)
    # Count compartments.
    compartments = 0
    for compartment in reference["compartments"].findall(
            "version:compartment", reference["space"]):
        compartments = compartments + 1
    # Count reactions.
    reactions = 0
    for reaction in reference["reactions"].findall("version:reaction",
                                                   reference["space"]):
        reactions = reactions + 1
    # Count metabolites.
    metabolites = 0
    for metabolite in reference["metabolites"].findall("version:species",
                                                       reference["space"]):
        metabolites = metabolites + 1
    # Compile and return inforation.
    return {
        "compartments": compartments,
        "reactions": reactions,
        "metabolites": metabolites
    }