def test_reaction_annotation_wrong_ids(read_only_model, db): """ Expect all annotations of reactions to be in the correct format. To identify databases and the identifiers belonging to them, computational tools rely on the presence of specific patterns. Only when these patterns can be identified consistently is an ID truly machine-readable. This test checks if the database cross-references in reaction annotations conform to patterns defined according to the MIRIAM guidelines, i.e. matching those that are defined at https://identifiers.org/. The required formats, i.e., regex patterns are further outlined in `annotation.py`. This test does not carry out a web query for the composed URI, it merely controls that the regex patterns match the identifiers. """ ann = test_reaction_annotation_wrong_ids.annotation ann["data"][db] = get_ids( annotation.generate_component_annotation_miriam_match( read_only_model.reactions, "reactions", db)) ann["metric"][db] = len(ann["data"][db]) / len(read_only_model.reactions) ann["message"][db] = wrapper.fill( """The provided reaction annotations for the {} database do not match the regular expression patterns defined on identifiers.org. A total of {} reaction annotations ({:.2%}) needs to be fixed: {}""".format( db, len(ann["data"][db]), ann["metric"][db], truncate(ann["data"][db]))) assert len(ann["data"][db]) == 0, ann["message"][db]
def test_generate_reaction_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.reactions, components, db) assert len(faulty) == num
def test_generate_component_annotation_miriam_match(model, num, components): """ Expect all items to have annotations that match MIRIAM patterns. The required databases are outlined in `annotation.py`. """ annotation_matches = annotation.generate_component_annotation_miriam_match( model, components) for key in annotation_matches.columns: assert annotation_matches[key].sum() == num
def test_metabolite_annotation_wrong_ids(read_only_model, store): """ Expect all annotations of metabolites to be in the correct format. The required formats, i.e., regex patterns are outlined in `annotation.py`. """ has_annotation = annotation.generate_component_annotation_overview( read_only_model, "metabolites") matches = annotation.generate_component_annotation_miriam_match( read_only_model, "metabolites") wrong = DataFrame(has_annotation.values & (~matches.values), index=has_annotation.index, columns=has_annotation.columns) store['met_wrong_annotation_ids'] = df2dict(wrong) for db in annotation.METABOLITE_ANNOTATIONS: sub = wrong.loc[wrong[db], db] assert len(sub) == 0, \ "The following metabolites use wrong IDs for {}: " \ "{}".format(db, ", ".join(sub.index))
def test_gene_product_annotation_wrong_ids(model, db): """ Expect all annotations of genes/gene-products to be in the correct format. To identify databases and the identifiers belonging to them, computational tools rely on the presence of specific patterns. Only when these patterns can be identified consistently is an ID truly machine-readable. This test checks if the database cross-references in reaction annotations conform to patterns defined according to the MIRIAM guidelines, i.e. matching those that are defined at https://identifiers.org/. The required formats, i.e., regex patterns are further outlined in `annotation.py`. This test does not carry out a web query for the composed URI, it merely controls that the regex patterns match the identifiers. Implementation: For those genes whose annotation keys match any of the tested databases, check if the corresponding values match the identifier pattern of each database. """ ann = test_gene_product_annotation_wrong_ids.annotation ann["data"][db] = total = get_ids( set(model.genes).difference( annotation.generate_component_annotation_overview( model.genes, db))) ann["metric"][db] = 1.0 ann["message"][db] = wrapper.fill( """There are no gene annotations for the {} database. """.format(db)) assert len(total) > 0, ann["message"][db] ann["data"][db] = get_ids( annotation.generate_component_annotation_miriam_match( model.genes, "genes", db)) ann["metric"][db] = len(ann["data"][db]) / len(model.genes) ann["message"][db] = wrapper.fill( """A total of {} gene annotations ({:.2%}) do not match the regular expression patterns defined on identifiers.org for the {} database: {}""".format( len(ann["data"][db]), ann["metric"][db], db, truncate(ann["data"][db]))) assert len(ann["data"][db]) == 0, ann["message"][db]
def test_gene_product_annotation_wrong_ids(model, db): """ Expect all annotations of genes/gene-products to be in the correct format. To identify databases and the identifiers belonging to them, computational tools rely on the presence of specific patterns. Only when these patterns can be identified consistently is an ID truly machine-readable. This test checks if the database cross-references in reaction annotations conform to patterns defined according to the MIRIAM guidelines, i.e. matching those that are defined at https://identifiers.org/. The required formats, i.e., regex patterns are further outlined in `annotation.py`. This test does not carry out a web query for the composed URI, it merely controls that the regex patterns match the identifiers. Implementation: For those genes whose annotation keys match any of the tested databases, check if the corresponding values match the identifier pattern of each database. """ ann = test_gene_product_annotation_wrong_ids.annotation ann["data"][db] = total = get_ids( set(model.genes).difference( annotation.generate_component_annotation_overview(model.genes, db))) ann["metric"][db] = 1.0 ann["message"][db] = wrapper.fill( """There are no gene annotations for the {} database. """.format(db)) assert len(total) > 0, ann["message"][db] ann["data"][db] = get_ids( annotation.generate_component_annotation_miriam_match( model.genes, "genes", db)) ann["metric"][db] = len(ann["data"][db]) / len(model.genes) ann["message"][db] = wrapper.fill( """A total of {} gene annotations ({:.2%}) do not match the regular expression patterns defined on identifiers.org for the {} database: {}""".format(len(ann["data"][db]), ann["metric"][db], db, truncate(ann["data"][db]))) assert len(ann["data"][db]) == 0, ann["message"][db]