Skip to content

Commit

Permalink
Merge pull request #587 from gregmedlock/develop
Browse files Browse the repository at this point in the history
switch order of list check to account for multiple SBO entries
  • Loading branch information
Midnighter committed Jan 26, 2019
2 parents 807bfab + b3c5a18 commit c48095e
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 13 deletions.
6 changes: 4 additions & 2 deletions memote/support/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def is_faulty(annotation, key, pattern):

pattern = {
"metabolites": METABOLITE_ANNOTATIONS,
"reactions": REACTION_ANNOTATIONS
"reactions": REACTION_ANNOTATIONS,
"genes": GENE_PRODUCT_ANNOTATIONS
}[component][db]
return [elem for elem in elements
if is_faulty(elem.annotation, db, pattern)]
Expand All @@ -225,7 +226,8 @@ def generate_component_id_namespace_overview(model, components):
"""
patterns = {
"metabolites": METABOLITE_ANNOTATIONS,
"reactions": REACTION_ANNOTATIONS
"reactions": REACTION_ANNOTATIONS,
"genes": GENE_PRODUCT_ANNOTATIONS
}[components]
databases = list(patterns)
data = list()
Expand Down
15 changes: 11 additions & 4 deletions memote/support/sbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ def check_component_for_specific_sbo_term(items, term):
The components without any or that specific SBO term annotation.
"""
return [elem for elem in items if
elem.annotation is None or
'sbo' not in elem.annotation or
elem.annotation['sbo'] not in term]
# check for multiple allowable SBO terms
if isinstance(term, list):
return [elem for elem in items if
elem.annotation is None or
'sbo' not in elem.annotation or
not any(i in elem.annotation['sbo'] for i in term)]
else:
return [elem for elem in items if
elem.annotation is None or
'sbo' not in elem.annotation or
term not in elem.annotation['sbo']]
93 changes: 92 additions & 1 deletion tests/test_for_support/test_for_annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def no_annotations(base):
met1 = cobra.Metabolite(id='met1_c', name="Met1")
rxn = cobra.Reaction(id='RXN', name="Rxn")
rxn.add_metabolites({met: -1, met1: 1})
rxn.gene_reaction_rule = 'gene1'
base.add_reactions([rxn])
return base

Expand All @@ -59,6 +60,13 @@ def rxn_annotations(base):
base.add_reactions([rxn])
return base

@register_with(MODEL_REGISTRY)
def gene_annotations(base):
rxn = cobra.Reaction(id='RXN', name="Rxn")
rxn.gene_reaction_rule = 'gene1'
base.add_reactions([rxn])
base.genes.get_by_id('gene1').annotation = {'kegg.genes': 'syn:ssr3451'}
return base

@register_with(MODEL_REGISTRY)
def met_each_present(base):
Expand Down Expand Up @@ -121,6 +129,33 @@ def rxn_each_absent(base):
base.add_reactions([rxn])
return base

@register_with(MODEL_REGISTRY)
def gene_each_present(base):
rxn = cobra.Reaction(id='RXN', name="Rxn")
rxn.gene_reaction_rule = 'gene1'
base.add_reactions([rxn])
base.genes[0].annotation = {'refseq': "YP_002410268.1",
'uniprot': "P31663",
'ecogene': "EG10173",
'kegg.genes': "syn:ssr3451",
'ncbigi': "GI:9082283",
'ncbigene': "00001",
'ncbiprotein': "CAA71118.1",
'ccds': "CCDS13573.1",
'hprd': "00001",
'asap': "ABE-0009634"}
return base


@register_with(MODEL_REGISTRY)
def gene_each_absent(base):
rxn = cobra.Reaction(id='RXN', name="Rxn")
rxn.gene_reaction_rule = 'gene1'
base.add_reactions([rxn])
base.genes[0].annotation = {'old_database': "broken_identifier",
'KEGG': "bad_kegg_gene"}
return base


@register_with(MODEL_REGISTRY)
def met_broken_id(base):
Expand Down Expand Up @@ -159,6 +194,23 @@ def rxn_broken_id(base):
base.add_reactions([rxn])
return base

@register_with(MODEL_REGISTRY)
def gene_broken_id(base):
rxn = cobra.Reaction(id='RXN', name="Rxn")
rxn.gene_reaction_rule = 'gene1'
base.add_reactions([rxn])
base.genes[0].annotation = {'refseq': "YPA_002410268.1",
'uniprot': "PGG31663",
'ecogene': "EG:10173",
'kegg.genes': "syn_ssr3451",
'ncbigi': "GIX_9082283",
'ncbigene': "0000xx1",
'ncbiprotein': "CAA+xz71AB118.1",
'ccds': "CCDS:13573.1",
'hprd': "A:00001",
'asap': "ABE_9634"}
return base


@register_with(MODEL_REGISTRY)
def consistent_ids(base):
Expand All @@ -167,10 +219,13 @@ def consistent_ids(base):
met2 = cobra.Metabolite(id='oaa_c', name="Oxaloacetate")
rxn = cobra.Reaction(id='PYK', name="Pyruvate kinase")
rxn.add_metabolites({met: -1, met1: 1})
rxn.gene_reaction_rule = 'eco:b1854'
rxn2 = cobra.Reaction(id='PPC', name="Phosphoenolpyruvate carboxylase")
rxn2.add_metabolites({met1: -1, met2: 1})
rxn2.gene_reaction_rule = 'eco:b3956'
rxn3 = cobra.Reaction(id='OAADC', name="Oxaloacetate decarboxylase")
rxn3.add_metabolites({met2: -1, met: 1})
rxn3.gene_reaction_rule = 'eco:b3997'
base.add_reactions([rxn, rxn2, rxn3])
return base

Expand All @@ -181,11 +236,14 @@ def inconsistent_ids(base):
met1 = cobra.Metabolite(id='pep_c', name="Phosphoenolpyruvate")
met2 = cobra.Metabolite(id='oaa_c', name="Oxaloacetate")
rxn = cobra.Reaction(id='PYK', name="Pyruvate kinase")
rxn.gene_reaction_rule = 'eco:b1854'
rxn.add_metabolites({met: -1, met1: 1})
rxn2 = cobra.Reaction(id='PPC', name="Phosphoenolpyruvate carboxylase")
rxn2.add_metabolites({met1: -1, met2: 1})
rxn2.gene_reaction_rule = 'eco:b3956'
rxn3 = cobra.Reaction(id='4.1.1.3', name="Oxaloacetate decarboxylase")
rxn3.add_metabolites({met2: -1, met: 1})
rxn3.gene_reaction_rule = 'P31663'
rxn4 = cobra.Reaction(
id='KETOGLUCOSE-REDUCTASE-RXN', name="Reaction: 1.1.1.-"
)
Expand Down Expand Up @@ -240,6 +298,22 @@ def test_generate_reaction_annotation_overview(model, num, db):
model.reactions, db)
assert len(overview) == num

@pytest.mark.parametrize("db", list(annotation.GENE_PRODUCT_ANNOTATIONS))
@pytest.mark.parametrize("model, num", [
("gene_each_present", 0),
("gene_each_absent", 1)
], indirect=["model"])
def test_generate_gene_annotation_overview(model, num, db):
"""
Expect all reactions to have `num` annotations from common databases.
The required databases are outlined in `annotation.py`.
"""
overview = \
annotation.generate_component_annotation_overview(
model.genes, db)
assert len(overview) == num


@pytest.mark.parametrize("db", list(annotation.METABOLITE_ANNOTATIONS))
@pytest.mark.parametrize("model, num, components", [
Expand Down Expand Up @@ -273,12 +347,29 @@ def test_generate_reaction_annotation_miriam_match(model, num, components, db):
model.reactions, components, db)
assert len(faulty) == num

@pytest.mark.parametrize("db", list(annotation.GENE_PRODUCT_ANNOTATIONS))
@pytest.mark.parametrize("model, num, components", [
("gene_each_present", 0, "genes"),
("gene_broken_id", 1, "genes")
], indirect=["model"])
def test_generate_gene_annotation_miriam_match(model, num, components, db):
"""
Expect all items to have annotations that match MIRIAM patterns.
The required databases are outlined in `annotation.py`.
"""
faulty = annotation.generate_component_annotation_miriam_match(
model.genes, components, db)
assert len(faulty) == num


@pytest.mark.parametrize("model, namespace, num, components", [
("consistent_ids", "bigg.metabolite", 3, "metabolites"),
("inconsistent_ids", "bigg.metabolite", 2, "metabolites"),
("consistent_ids", "bigg.reaction", 3, "reactions"),
("inconsistent_ids", "bigg.reaction", 2, "reactions")
("inconsistent_ids", "bigg.reaction", 2, "reactions"),
("consistent_ids", "kegg.genes", 3, "genes"),
("inconsistent_ids", "kegg.genes", 2, "genes")
], indirect=["model"])
def test_generate_component_id_namespace_overview(model, namespace, num,
components):
Expand Down
26 changes: 20 additions & 6 deletions tests/test_for_support/test_for_sbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ def specific_sbo_term(base):
base.add_reactions([rxn])
return base

@register_with(MODEL_REGISTRY)
def multiple_sbo_terms(base):
met = cobra.Metabolite(id='met_c', name="Met")
met.annotation = {'sbo': ['SBO:1', 'SBO:2'],
'bigg.metabolite': 'dad_2'}
rxn = cobra.Reaction(id='RXN', name="Rxn")
rxn.add_metabolites({met: -1})
rxn.annotation = {'bigg.reaction': 'DADNt2pp'}
rxn.gene_reaction_rule = '(gene1)'
base.add_reactions([rxn])
return base

@pytest.mark.parametrize("model, num, components", [
("no_annotations", 2, "metabolites"),
Expand All @@ -66,14 +77,17 @@ def test_find_components_without_sbo_terms(model, num, components):
assert len(without_annotation) == num


@pytest.mark.parametrize("model, num, components", [
("specific_sbo_term", 0, "metabolites"),
("specific_sbo_term", 1, "reactions"),
("specific_sbo_term", 1, "genes")
@pytest.mark.parametrize("model, num, components, term", [
("specific_sbo_term", 0, "metabolites", "SBO:1"),
("specific_sbo_term", 1, "reactions", "SBO:1"),
("specific_sbo_term", 1, "genes", "SBO:1"),
("multiple_sbo_terms", 0, "metabolites", ["SBO:1","SBO:2","SBO:3"]),
("multiple_sbo_terms", 1, "reactions", ["SBO:1","SBO:2","SBO:3"]),
("multiple_sbo_terms", 1, "genes", ["SBO:1","SBO:2","SBO:3"])
], indirect=["model"])
def test_find_components_without_specific_sbo_term(model, num, components):
def test_find_components_without_specific_sbo_term(model, num, components,
term):
"""Expect `num` components to have a specific sbo annotation."""
term = 'SBO:1'
no_match_to_specific_term = sbo.check_component_for_specific_sbo_term(
getattr(model, components), term)
assert len(no_match_to_specific_term) == num

0 comments on commit c48095e

Please sign in to comment.