Skip to content

Commit

Permalink
Merge branch 'master' into synapses
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbie1977 authored Sep 5, 2024
2 parents ad7b108 + d1dcfd4 commit dd80afe
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/vfb_connect/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .cross_server_tools import VfbConnect

# Create an instance of VfbConnect and make it available directly
vfb = VfbConnect()
vfb = VfbConnect(vfb_launch=True)

__all__ = ['vfb', 'VfbConnect']
7 changes: 5 additions & 2 deletions src/vfb_connect/cross_server_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self, neo_endpoint=get_default_servers()['neo_endpoint'],

print("\033[32mSession Established!\033[0m")
print("")
print("\033[33mType \033[35mvfb. \033[33mand press \033[35mtab\033[33m to see available queries. You can run help against any query e.g. \033[35mhelp(vfb.terms)\033[0m")
print("\033[33mType \033[35mvfb. \033[33mand press \033[35mtab\033[33m to see available queries. You can run help against any query e.g. \033[35mhelp(vfb.terms)\033[0m") if vfb_launch else None

def __dir__(self):
return [attr for attr in list(self.__dict__.keys()) if not attr.startswith('_')] + [attr for attr in dir(self.__class__) if not attr.startswith('_') and not attr.startswith('add_')]
Expand Down Expand Up @@ -852,6 +852,9 @@ def xref_2_vfb_id(self, acc=None, db='', id_type='', reverse_return=False, retur
else:
new_acc.append(xref)
acc = new_acc
if isinstance(acc, list) and all(isinstance(x, int) for x in acc):
acc = [str(x) for x in acc]
print(f"Converted to strings: {acc}") if verbose else None
if db in VFB_DBS_2_SYMBOLS.keys():
db = VFB_DBS_2_SYMBOLS[db]
if db not in self.get_dbs():
Expand Down Expand Up @@ -1418,7 +1421,7 @@ def generate_lab_colors(self, num_colors, min_distance=100, verbose=False):
rgb_colors = []

# Select the first color
lab_tree = KDTree([(0, 0, 0)]) # Start tree with black
lab_tree = KDTree([(255,255,255),(0, 0, 0)]) # Start tree with black and white

# Pick colors that are far apart from each other and from black
for lab in lab_colors[0:]:
Expand Down
9 changes: 8 additions & 1 deletion src/vfb_connect/neo/query_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
from inspect import getfullargspec
from string import Template
from time import sleep
from xml.sax import saxutils
import pandas as pd
import pkg_resources
Expand Down Expand Up @@ -609,7 +610,13 @@ def _get_Cached_TermInfo(self, short_forms: iter, summary=True, return_dataframe
short_forms = list(chain.from_iterable(short_forms)) if any(isinstance(i, list) for i in short_forms) else short_forms
print(f"Checking cache for results: short_forms={short_forms}") if verbose else None
print(f"Looking for {len(short_forms)} results.") if verbose else None
results = self._serialize_solr_output(vfb_solr.search('*', **{'fl': 'term_info','df': 'id', 'defType': 'edismax', 'q.op': 'OR','rows': len(short_forms)+10,'fq':'{!terms f=id}'+ ','.join(short_forms)}))
try:
result = vfb_solr.search('*', **{'fl': 'term_info','df': 'id', 'defType': 'edismax', 'q.op': 'OR','rows': len(short_forms)+10,'fq':'{!terms f=id}'+ ','.join(short_forms)})
except Exception as e:
print(f"\033[33mWarning:\033[0m Cache query failed. Error: {e}")
sleep(15) # Sleep for 15 seconds to avoid overloading the server
return self._get_Cached_TermInfo(short_forms, summary=summary, return_dataframe=return_dataframe, verbose=verbose)
results = self._serialize_solr_output(result)
print(f"Got {len(results)} results.") if verbose else None
if len(short_forms) != len(results):
print(f"Warning: Cache didn't return all results. Got {len(results)} out of {len(short_forms)}") if verbose else None
Expand Down
10 changes: 8 additions & 2 deletions src/vfb_connect/owl/owlery_query_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from time import sleep
import requests
import re
import json
Expand Down Expand Up @@ -70,11 +71,16 @@ def query(self, query_type, return_type,
if query_by_label:
query = self.labels_2_ids(query)
if verbose:
print("Running query: " + query)
print("Running query: " + query)
payload = {'object': query, 'prefixes': json.dumps(self.curies),
'direct': direct}
# print(payload)
r = requests.get(url=owl_endpoint, params=payload)
try:
r = requests.get(url=owl_endpoint, params=payload)
except requests.exceptions.RequestException as e:
print("\033[31mConnection Error:\033[0m " + str(e))
sleep(15)
return query(query_type, return_type, query, query_by_label, direct, verbose)
if verbose:
print("Query URL: " + r.url)
if r.status_code == 200:
Expand Down
3 changes: 1 addition & 2 deletions src/vfb_connect/schema/vfb_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ def __init__(self, id=None, term: Optional[Term] = None, related_terms: Optional
from vfb_connect import vfb
self.vfb = vfb
self.debug = verbose
self._return_type = self.vfb._return_type # Default to global version but can be set to id, name (list) or full (VFBTerms)
self._return_type = self.vfb._return_type if hasattr(self.vfb, '_return_type') else "full"
if id is not None:
if isinstance(id, list):
id = id[0]
Expand Down Expand Up @@ -1681,7 +1681,6 @@ def __init__(self, id=None, term: Optional[Term] = None, related_terms: Optional
self._instances = None
self._instances_ids = None
self._instances_names = None
self._return_type = self.vfb._return_type # Default to global version but can be set to id, name (list) or full (VFBTerms)
self._skeleton = None
self._mesh = None
self._volume = None
Expand Down

0 comments on commit dd80afe

Please sign in to comment.