Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for querying for direct vs inferred associations, other fixes for ui #408

Merged
merged 3 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 92 additions & 63 deletions ontobio/golr/golr_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,11 @@ def __init__(self,
object=None,
objects=None,
subject_direct=False,
object_direct=False,
subject_taxon=None,
subject_taxon_direct=False,
object_taxon=None,
object_taxon_direct=False,
invert_subject_object=None,
evidence=None,
exclude_automatic_assertions=False,
Expand Down Expand Up @@ -884,57 +887,60 @@ def __init__(self,


"""
self.subject_category=subject_category
self.object_category=object_category
self.relation=relation
self.relationship_type=relationship_type
self.subject_or_object_ids=subject_or_object_ids
self.subject_or_object_category=subject_or_object_category
self.subject=subject
self.subjects=subjects
self.object=object
self.objects=objects
self.subject_direct=subject_direct
self.subject_taxon=subject_taxon
self.object_taxon=object_taxon
self.invert_subject_object=invert_subject_object
self.evidence=evidence
self.exclude_automatic_assertions=exclude_automatic_assertions
self.id=id
self.q=q
self.use_compact_associations=use_compact_associations
self.include_raw=include_raw
self.field_mapping=field_mapping
self.solr=solr
self.subject_category = subject_category
self.object_category = object_category
self.relation = relation
self.relationship_type = relationship_type
self.subject_or_object_ids = subject_or_object_ids
self.subject_or_object_category = subject_or_object_category
self.subject = subject
self.subjects = subjects
self.subject_direct = subject_direct
self.object = object
self.objects = objects
self.object_direct = object_direct
self.subject_taxon = subject_taxon
self.subject_taxon_direct = subject_taxon_direct
self.object_taxon = object_taxon
self.object_taxon_direct = object_taxon_direct
self.invert_subject_object = invert_subject_object
self.evidence = evidence
self.exclude_automatic_assertions = exclude_automatic_assertions
self.id = id
self.q = q
self.use_compact_associations = use_compact_associations
self.include_raw = include_raw
self.field_mapping = field_mapping
self.solr = solr
self.config = config
self.select_fields=select_fields
self.fetch_objects=fetch_objects
self.fetch_subjects=fetch_subjects
self.fq=fq if fq is not None else {}
self.select_fields = select_fields
self.fetch_objects = fetch_objects
self.fetch_subjects = fetch_subjects
self.fq = fq if fq is not None else {}
self.slim = slim if slim is not None else []
self.json_facet=json_facet
self.iterate=iterate
self.map_identifiers=map_identifiers
self.facet_fields=facet_fields
self.facet_field_limits=facet_field_limits
self.facet_limit=facet_limit
self.facet_mincount=facet_mincount
self.facet_pivot_fields=facet_pivot_fields
self.stats=stats
self.stats_field=stats_field
self.facet=facet
self.pivot_subject_object=pivot_subject_object
self.unselect_evidence=unselect_evidence
self.max_rows=100000
self.rows=rows
self.start=start
self.json_facet = json_facet
self.iterate = iterate
self.map_identifiers = map_identifiers
self.facet_fields = facet_fields
self.facet_field_limits = facet_field_limits
self.facet_limit = facet_limit
self.facet_mincount = facet_mincount
self.facet_pivot_fields = facet_pivot_fields
self.stats = stats
self.stats_field = stats_field
self.facet = facet
self.pivot_subject_object = pivot_subject_object
self.unselect_evidence = unselect_evidence
self.max_rows = 100000
self.rows = rows
self.start = start
self.homology_type = homology_type
self.url = url
# test if client explicitly passes a URL; do not override
self.is_explicit_url = url is not None
self.non_null_fields=non_null_fields
self.association_type=association_type
self.sort=sort
self.non_null_fields = non_null_fields
self.association_type = association_type
self.sort = sort

self.user_agent = get_user_agent(modules=[requests, pysolr], caller_name=__name__)
if user_agent is not None:
Expand Down Expand Up @@ -994,18 +1000,22 @@ def solr_params(self):
#if subject is not None and subject.startswith('MGI:MGI:'):
# logging.info('Unhacking MGI ID presumably from GO:'+str(subject))
# subject = subject.replace("MGI:MGI:","MGI")
subject=self.subject
subject = self.subject
if subject is not None:
subject = self.make_canonical_identifier(subject)
subjects=self.subjects
subjects = self.subjects
if subjects is not None:
subjects = [self.make_canonical_identifier(s) for s in subjects]

subject_direct = self.subject_direct

# temporary: for querying go solr, map fields. TODO
object_category=self.object_category
object_category = self.object_category
logging.info("Object category: {}".format(object_category))

object=self.object
object = self.object
objects = self.objects
object_direct = self.object_direct
if object_category is None and object is not None and object.startswith('GO:'):
# Infer category
object_category = 'function'
Expand Down Expand Up @@ -1041,8 +1051,9 @@ def solr_params(self):
object = cc

## subject params
subject_taxon=self.subject_taxon
subject_category=self.subject_category
subject_taxon = self.subject_taxon
subject_taxon_direct = self.subject_taxon_direct
subject_category = self.subject_category

# heuristic procedure to guess unspecified subject_category
if subject_category is None and subject is not None:
Expand All @@ -1067,13 +1078,16 @@ def solr_params(self):

## taxon of object of triple
object_taxon=self.object_taxon
object_taxon_direct = self.object_taxon_direct

# typically information is stored one-way, e.g. model-disease;
# sometimes we want associations from perspective of object
if self.invert_subject_object:
(subject,object) = (object,subject)
(subject_category,object_category) = (object_category,subject_category)
(subject_taxon,object_taxon) = (object_taxon,subject_taxon)
(subject, object) = (object,subject)
(subject_category, object_category) = (object_category,subject_category)
(subject_taxon, object_taxon) = (object_taxon,subject_taxon)
(object_direct, subject_direct) = (subject_direct, object_direct)
(object_taxon_direct, subject_taxon_direct) = (subject_taxon_direct, object_taxon_direct)

## facet fields
facet_fields=self.facet_fields
Expand All @@ -1096,24 +1110,32 @@ def solr_params(self):
if object_category is not None:
fq['object_category'] = object_category


if object is not None:
# TODO: make configurable whether to use closure
fq['object_closure'] = object
if subject is not None:
# note: by including subject closure by default,
# we automaticaly get equivalent nodes
if self.subject_direct:
fq['subject'] = subject
if subject_direct:
fq['subject_eq'] = subject
else:
fq['subject_closure'] = subject
if subjects is not None:
# lists are assumed to be disjunctive
if self.subject_direct:
if subject_direct:
fq['subject'] = subjects
else:
fq['subject_closure'] = subjects

if object is not None:
if object_direct:
fq['object_eq'] = object
else:
fq['object_closure'] = object
if objects is not None:
# lists are assumed to be disjunctive
if object_direct:
fq['object_eq'] = objects
else:
fq['object_eq'] = objects

objects=self.objects
if objects is not None:
# lists are assumed to be disjunctive
Expand All @@ -1122,9 +1144,16 @@ def solr_params(self):
if relation is not None:
fq['relation_closure'] = relation
if subject_taxon is not None:
fq['subject_taxon_closure'] = subject_taxon
if subject_taxon_direct:
fq['subject_taxon'] = subject_taxon
else:
fq['subject_taxon_closure'] = subject_taxon
if object_taxon is not None:
fq['object_taxon_closure'] = object_taxon
if object_taxon_direct:
fq['object_taxon'] = object_taxon
else:
fq['object_taxon_closure'] = object_taxon

if self.id is not None:
fq['id'] = self.id
if self.evidence is not None:
Expand Down
8 changes: 3 additions & 5 deletions ontobio/sim/api/owlsim2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def search_by_attribute_set(
'limit': limit,
'target': namespace_filter
}
return requests.get(owlsim_url, params=params, timeout=TIMEOUT).json()
return requests.post(owlsim_url, data=params, timeout=TIMEOUT).json()


@cache.memoize()
Expand All @@ -71,9 +71,7 @@ def compare_attribute_sets(
'b': profile_b,
}

print(requests.get(owlsim_url, params=params, timeout=TIMEOUT).json())

return requests.get(owlsim_url, params=params, timeout=TIMEOUT).json()
return requests.post(owlsim_url, data=params, timeout=TIMEOUT).json()


@cache.memoize()
Expand All @@ -100,7 +98,7 @@ def get_attribute_information_profile(
'a': profile,
'r': categories
}
return requests.get(owlsim_url, params=params, timeout=TIMEOUT).json()
return requests.post(owlsim_url, data=params, timeout=TIMEOUT).json()


@cache.memoize()
Expand Down
4 changes: 3 additions & 1 deletion ontobio/util/scigraph_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_scigraph_nodes(id_list)-> Iterator[Dict]:
"""
scigraph = RemoteScigraphOntology('scigraph:data')

chunks = [id_list[i:i + 400] for i in range(0, len(list(id_list)), 400)]
chunks = [id_list[i:i + 100] for i in range(0, len(list(id_list)), 100)]
for chunk in chunks:
params = {
'id': chunk,
Expand Down Expand Up @@ -95,6 +95,8 @@ def get_id_type_map(id_list: Iterable[str]) -> Dict[str, List[str]]:
for node in get_scigraph_nodes(id_list):
type_map[node['id']] = [typ.lower() for typ in node['meta']['types']
if typ not in filter_out_types]
if not type_map[node['id']]:
type_map[node['id']] = ['Node']

return type_map

Expand Down