Beispiel #1
0
def ndex(username, password):
    """Upload to NDEx."""
    try:
        from ndex2 import NiceCXBuilder
    except ImportError:
        click.secho('Need to `pip install ndex2` before uploading to NDEx', fg='red')
        return

    miriam_validator = MiriamValidator()
    positive_mappings = load_mappings()
    cx = NiceCXBuilder()
    cx.set_name('Biomappings')
    cx.add_network_attribute('description', 'Manually curated mappings (skos:exactMatch) between biological entities.')
    cx.add_network_attribute('reference', 'https://github.com/biomappings/biomappings')
    cx.add_network_attribute('rights', 'Waiver-No rights reserved (CC0)')

    context = {'orcid': 'https://identifiers.org/orcid:'}
    for mapping in positive_mappings:
        for prefix in (mapping['source prefix'], mapping['target prefix']):
            if miriam_validator.namespace_embedded(prefix):
                prefix = prefix.upper()
            context[prefix] = f'https://identifiers.org/{prefix}:'
    cx.set_context(context)

    cx.add_network_attribute('version', get_git_hash())
    authors = sorted(set(
        mapping['source']
        for mapping in positive_mappings
        if mapping['source'].startswith('orcid:')
    ))
    cx.add_network_attribute('author', authors, type='list_of_string')

    for mapping in tqdm(positive_mappings, desc='Loading NiceCXBuilder'):
        source = cx.add_node(
            represents=mapping['source name'],
            name=miriam_validator.get_curie(mapping["source prefix"], mapping["source identifier"]),
        )
        target = cx.add_node(
            represents=mapping['target name'],
            name=miriam_validator.get_curie(mapping["target prefix"], mapping["target identifier"]),
        )
        edge = cx.add_edge(
            source=source,
            target=target,
            interaction=mapping['relation'],
        )
        cx.add_edge_attribute(edge, 'type', mapping['type'])
        cx.add_edge_attribute(edge, 'provenance', mapping['source'])

    nice_cx = cx.get_nice_cx()
    nice_cx.update_to(
        uuid=BIOMAPPINGS_NDEX_UUID,
        server=pystow.get_config('ndex', 'server', 'http://public.ndexbio.org'),
        username=pystow.get_config('ndex', 'username', username),
        password=pystow.get_config('ndex', 'password', password),
    )
def get_sssom_df():
    """Get an SSSOM dataframe."""
    import pandas as pd

    rows = []
    prefixes = set()
    columns = [
        "subject_id",
        "predicate_id",
        "object_id",
        "subject_label",
        "object_label",
        "match_type",
        "creator_id",
        "confidence",
        "mapping_tool",
    ]
    for mapping in load_mappings():
        prefixes.add(mapping["source prefix"])
        prefixes.add(mapping["target prefix"])
        rows.append(
            (
                validator.get_curie(mapping["source prefix"], mapping["source identifier"]),
                f'{mapping["relation"]}',
                validator.get_curie(mapping["target prefix"], mapping["target identifier"]),
                mapping["source name"],
                mapping["target name"],
                "HumanCurated",  # match type
                mapping["source"],  # curator CURIE
                None,  # no confidence necessary
                None,  # mapping tool: none necessary for manually curated
            )
        )
    for mapping in load_predictions():
        prefixes.add(mapping["source prefix"])
        prefixes.add(mapping["target prefix"])
        rows.append(
            (
                validator.get_curie(mapping["source prefix"], mapping["source identifier"]),
                f'{mapping["relation"]}',
                validator.get_curie(mapping["target prefix"], mapping["target identifier"]),
                mapping["source name"],
                mapping["target name"],
                "LexicalEquivalenceMatch",  # match type
                None,  # no curator CURIE
                mapping["confidence"],
                mapping["source"],  # mapping tool: source script
            )
        )
    df = pd.DataFrame(rows, columns=columns)
    return prefixes, df
Beispiel #3
0
# -*- coding: utf-8 -*-
"""Validation tests for :mod:`biomappings`."""

import itertools as itt
from collections import Counter

from biomappings import load_false_mappings, load_mappings, load_predictions, load_unsure
from biomappings.resources import mapping_sort_key
from biomappings.utils import MiriamValidator, get_canonical_tuple

mappings = load_mappings()
predictions = load_predictions()
incorrect = load_false_mappings()
unsure = load_unsure()

miriam_validator = MiriamValidator()


def test_valid_mappings():
    """Test the validity of the prefixes and identifiers in the mappings."""
    for mapping in itt.chain(mappings, incorrect, predictions):
        miriam_validator.check_valid_prefix_id(
            mapping["source prefix"],
            mapping["source identifier"],
        )
        miriam_validator.check_valid_prefix_id(
            mapping["target prefix"],
            mapping["target identifier"],
        )

Beispiel #4
0
def ndex(username, password):
    """Upload to NDEx."""
    try:
        from ndex2 import NiceCXBuilder
    except ImportError:
        click.secho("Need to `pip install ndex2` before uploading to NDEx",
                    fg="red")
        return

    miriam_validator = MiriamValidator()
    positive_mappings = load_mappings()
    cx = NiceCXBuilder()
    cx.set_name("Biomappings")
    cx.add_network_attribute(
        "description",
        "Manually curated mappings (skos:exactMatch) between biological entities."
    )
    cx.add_network_attribute("reference",
                             "https://github.com/biomappings/biomappings")
    cx.add_network_attribute("rights", "Waiver-No rights reserved (CC0)")

    context = {"orcid": "https://identifiers.org/orcid:"}
    for mapping in positive_mappings:
        for prefix in (mapping["source prefix"], mapping["target prefix"]):
            if miriam_validator.namespace_embedded(prefix):
                prefix = prefix.upper()
            context[prefix] = f"https://identifiers.org/{prefix}:"
    cx.set_context(context)

    cx.add_network_attribute("version", get_git_hash())
    authors = sorted(
        set(mapping["source"] for mapping in positive_mappings
            if mapping["source"].startswith("orcid:")))
    cx.add_network_attribute("author", authors, type="list_of_string")

    for mapping in tqdm(positive_mappings, desc="Loading NiceCXBuilder"):
        source = cx.add_node(
            represents=mapping["source name"],
            name=miriam_validator.get_curie(mapping["source prefix"],
                                            mapping["source identifier"]),
        )
        target = cx.add_node(
            represents=mapping["target name"],
            name=miriam_validator.get_curie(mapping["target prefix"],
                                            mapping["target identifier"]),
        )
        edge = cx.add_edge(
            source=source,
            target=target,
            interaction=mapping["relation"],
        )
        cx.add_edge_attribute(edge, "type", mapping["type"])
        cx.add_edge_attribute(edge, "provenance", mapping["source"])

    nice_cx = cx.get_nice_cx()
    nice_cx.update_to(
        uuid=BIOMAPPINGS_NDEX_UUID,
        server=pystow.get_config("ndex",
                                 "server",
                                 default="http://public.ndexbio.org"),
        username=pystow.get_config("ndex", "username", passthrough=username),
        password=pystow.get_config("ndex", "password", passthrough=password),
    )