Skip to content

Commit

Permalink
Release 1.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dosumis committed Mar 2, 2021
1 parent 85890ea commit 0bd0b35
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
49 changes: 36 additions & 13 deletions build/lib/vfb_connect/cross_server_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ def gen_short_form(iri):
iri: An iri string"""
return re.split('/|#', iri)[-1]

def dequote(string):
qm = re.match("^'(.+)'$", string)
if qm:
return qm.group(1)
else:
return string


class VfbConnect:
"""API wrapper class. By default this wraps connections to the more basal API endpoints (OWL, Neo4j).
Expand Down Expand Up @@ -51,6 +58,18 @@ def __init__(self, neo_endpoint=get_default_servers()['neo_endpoint'],
self.vfb_base = "https://v2.virtualflybrain.org/org.geppetto.frontend/geppetto?id="


def lookup_id(self, key, return_short_form=True):
if key in self.lookup.keys():
out = self.lookup[key]
if return_short_form:
return out.replace(':', '_')
else:
return out
else:
raise ValueError("Unrecognised value: %s" % str(key))



def get_terms_by_region(self, region, cells_only=False, verbose=False, query_by_label=True, summary=True):
"""Generate JSON reports for all terms relevant to
annotating some specific region,
Expand Down Expand Up @@ -163,34 +182,38 @@ def get_neurons_upstream_of(self, neuron, weight, classification=None, query_by_
def get_connected_neurons_by_type(self, upstream_type, downstream_type, weight, query_by_label=True,
return_dataframe=True):
"""Get all synaptic connections between individual neurons of `upstream_type` and `dowstream_type` where
each of these types is the name of a neuron class/type in VFB."""
each synapse count >= `weight`. Warning: Does not support Class Expressions."""

# Note - chose not to do this with class expressions to avoid poor performance and blowing up results.
# This might be confusing tough, given behavior of other, similar methods.
# Might be better to refactor to work out if query is class expression or class & funnel query method
# accordingly.

qprop = 'short_form'
if query_by_label:
qprop = 'label'
# upstream_instances = self.oc.get_instances(upstream_type, query_by_label=query_by_label)
cypher_query = "MATCH (up:Class:Neuron)<-[:SUBCLASSOF|INSTANCEOF*..]-(n1:Neuron:Individual)-[r:synapsed_to]->" \
"(n2:Neuron:Individual)-[:SUBCLASSOF|INSTANCEOF*..]->(down:Class:Neuron)"
cypher_query += "WHERE r.weight[0] > %d " % weight
cypher_query += 'AND up.%s = "%s" and down.%s = "%s" ' % (qprop, upstream_type, qprop, downstream_type)
cypher_query += "MATCH (c1)<-[:INSTANCEOF]-(n1), (c2)<-[:INSTANCEOF]-(n2)" \
upstream_type = self.lookup_id(dequote(upstream_type))
downstream_type = self.lookup_id(dequote(downstream_type))
# upstream_instances = self.oc.get_instances(upstream_type, query_by_label=query_by_label)

cypher_query = "MATCH (up:Class:Neuron)<-[:SUBCLASSOF|INSTANCEOF*..10]-(n1:Neuron:Individual) " \
'WHERE up.short_form = "%s" ' % upstream_type
cypher_query += "MATCH (n1)-[r:synapsed_to]->(n2:Neuron:Individual) " \
"WHERE r.weight[0] >= %d " % weight
cypher_query += "MATCH (n2)-[:SUBCLASSOF|INSTANCEOF*..10]->(down:Class:Neuron) " \
'WHERE down.short_form = "%s" ' % downstream_type
cypher_query += "MATCH (c1:Class)<-[:INSTANCEOF]-(n1), (c2:Class)<-[:INSTANCEOF]-(n2) " \
"OPTIONAL MATCH (n1)-[r1:database_cross_reference]->(s1:Site) " \
"WHERE exists(s1.is_data_source) AND s1.is_data_source = True " \
"OPTIONAL MATCH (n2)-[r2:database_cross_reference]->(s2:Site) " \
"WHERE exists(s1.is_data_source) AND s2.is_data_source = True " \
"RETURN n1.short_form as upstream_neuron_id, n1.label as upstream_neuron_name, " \
"r.weight[0] as weight, " \
"n2.short_form as downstream_neuron_id, n2.label as downstream_neuron_name, " \
"apoc.text.join(collect(c1.label),'|') AS upstream_class, " \
"apoc.text.join(collect(c2.label),'|') as downstream_class, " \
"r.weight[0] as weight, n2.short_form as downstream_neuron_id, " \
"n2.label as downstream_neuron_name, " \
"apoc.text.join(collect(distinct c1.label),'|') AS upstream_class, " \
"apoc.text.join(collect(distinct c2.label),'|') as downstream_class, " \
"s1.short_form AS up_data_source, r1.accession[0] as up_accession," \
"s2.short_form AS down_source, r2.accession[0] AS down_accession"

# print(cypher_query)
r = self.nc.commit_list([cypher_query])
dc = dict_cursor(r)
if return_dataframe:
Expand Down
Binary file added dist/vfb_connect-1.2.5-py3-none-any.whl
Binary file not shown.
Binary file added dist/vfb_connect-1.2.5.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
long_description = f.read()

setup(name='vfb_connect', # Required
version='v1.2.4', # Required
version='v1.2.5', # Required
packages=find_packages(where='src'),
package_dir={'': 'src'},
py_modules=[path.splitext(path.basename(path))[0] for path in glob.glob('src/*.py')],
Expand Down
2 changes: 1 addition & 1 deletion src/vfb_connect.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: vfb-connect
Version: 1.2.4
Version: 1.2.5
Summary: Wrapper for querying VirtualFlyBrain servers.
Home-page: https://github.com/VirtualFlyBrain/VFB_connect
Author: David Osumi-Sutherland
Expand Down

0 comments on commit 0bd0b35

Please sign in to comment.