Ejemplo n.º 1
0
def test_get_subclasses_no_xref():
    """This HP has no subclasses and it has no xrefs. So just itself should be returne
    as an entry, and xrefs should be an empty list"""
    ubergraph = UberGraph()
    iri = 'HP:0020154'
    subs = ubergraph.get_subclasses_and_xrefs(iri)
    assert len(subs) == 1
    xrefs = list(subs.values())[0]
    assert isinstance(xrefs, list)
    assert len(xrefs) == 0
Ejemplo n.º 2
0
def test_get_subclasses_exact():
    """Check out that we can get subclasses, along with labels and the exact matches for them
    Starting with Ciliophora infectious disease which has one subclass"""
    ubergraph = UberGraph()
    iri = 'MONDO:0005704'
    subs = ubergraph.get_subclasses_and_exacts(iri)
    assert len(subs) == 2
    for k, v in subs.items():
        print(k)
        print(v)
Ejemplo n.º 3
0
def test_get_sub_exact_no_exact():
    """If a class doesn't have any exact matches, do we still get it?"""
    ubergraph = UberGraph()
    #this should have 3 subclasses.  One of them (MONDO:0022643) has no exact matches
    iri = 'MONDO:0002355'
    subs = ubergraph.get_subclasses_and_exacts(iri)
    assert len(subs) == 4  #self gets returned too
    k = ('MONDO:0022643', 'carcinoma of the vocal tract')
    assert k in subs
    assert len(subs[k]) == 0
    print(subs)
Ejemplo n.º 4
0
def test_get_subclasses_xref():
    """check that we get both direct and indirect subclasses of a node.
    We're using chemoreceptor cell to test, which has 4 direct children,
    2 of which have children, for 12 total descendents.  The query also
    returns the input in the output, so that's 13 total"""
    ubergraph = UberGraph()
    iri = 'CL:0000206'
    subs = ubergraph.get_subclasses_and_xrefs(iri)
    assert len(subs) == 13
    xrefs = subs[('CL:0000207', 'olfactory receptor cell')]
    assert len(xrefs) == 3
Ejemplo n.º 5
0
def build_pr_uniprot_relationships(outfile, ignore_list=[]):
    """Given an IRI create a list of sets.  Each set is a set of equivalent LabeledIDs, and there
    is a set for each subclass of the input iri.  Write these lists to concord files, indexed by the prefix"""
    iri = 'PR:000000001'
    uber = UberGraph()
    pro_res = uber.get_subclasses_and_xrefs(iri)
    with open(outfile, 'w') as concfile:
        for k, v in pro_res.items():
            for x in v:
                if Text.get_curie(x) not in ignore_list:
                    if k.startswith('PR'):
                        concfile.write(f'{k}\txref\t{x}\n')
Ejemplo n.º 6
0
def test_get_subclasses():
    """check that we get both direct and indirect subclasses of a node.
    We're using chemoreceptor cell to test, which has 4 direct children,
    2 of which have children, for 12 total descendents.  The query also
    returns the input in the output, so that's 13 total"""
    ubergraph = UberGraph()
    iri = 'CL:0000206'
    subs = ubergraph.get_subclasses_of(iri)
    assert len(subs) == 13
    for sub in subs:
        assert 'descendent' in sub
        assert sub['descendent'].startswith('CL')
        assert 'descendentLabel' in sub
Ejemplo n.º 7
0
def pull_uber_labels(expected):
    uber = UberGraph()
    labels = uber.get_all_labels()
    ldict = defaultdict(set)
    for unit in labels:
        iri = unit['iri']
        p = iri.split(':')[0]
        ldict[p].add((unit['iri'], unit['label']))
    for p in ldict:
        if p not in ['http', 'ro'] and not p.startswith('t') and not '#' in p:
            fname = make_local_name('labels', subpath=p)
            with open(fname, 'w') as outf:
                for unit in ldict[p]:
                    outf.write(f'{unit[0]}\t{unit[1]}\n')
Ejemplo n.º 8
0
def pull_uber_synonyms(expected):
    uber = UberGraph()
    labels = uber.get_all_synonyms()
    ldict = defaultdict(set)
    for unit in labels:
        iri = unit[0]
        p = iri.split(':')[0]
        ldict[p].add(unit)
    #There are some of the ontologies that we don't get synonyms for.   But this makes snakemake unhappy so
    # we are going to make some zero-length files for it
    for p in expected:
        if p not in ['http', 'ro'] and not p.startswith('t') and not '#' in p:
            fname = make_local_name('synonyms', subpath=p)
            with open(fname, 'w') as outf:
                for unit in ldict[p]:
                    outf.write(f'{unit[0]}\t{unit[1]}\t{unit[2]}\n')
Ejemplo n.º 9
0
def write_obo_ids(irisandtypes, outfile, order, exclude=[]):
    uber = UberGraph()
    iris_to_types = defaultdict(set)
    for iri, ntype in irisandtypes:
        uberres = uber.get_subclasses_of(iri)
        for k in uberres:
            iris_to_types[k['descendent']].add(ntype)
    excludes = []
    for excluded_iri in exclude:
        excludes += uber.get_subclasses_of(excluded_iri)
    excluded_iris = set([k['descendent'] for k in excludes])
    prefix = Text.get_curie(iri)
    with open(outfile, 'w') as idfile:
        for kd, typeset in iris_to_types.items():
            if kd not in excluded_iris and kd.startswith(prefix):
                l = list(typeset)
                l.sort(key=lambda k: order.index(k))
                idfile.write(f'{kd}\t{l[0]}\n')