From 39af7770e4b6a74c276930b46fdc8ede64e9d859 Mon Sep 17 00:00:00 2001 From: dosumis Date: Thu, 5 Sep 2024 08:03:14 +0100 Subject: [PATCH] New version pub query Updates cros --- src/vfb_connect/cross_server_tools.py | 40 ++++++++++++------- .../test/cross_server_tools_test.py | 5 +++ 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/src/vfb_connect/cross_server_tools.py b/src/vfb_connect/cross_server_tools.py index 6fbbaed7..61116a2c 100644 --- a/src/vfb_connect/cross_server_tools.py +++ b/src/vfb_connect/cross_server_tools.py @@ -718,33 +718,43 @@ def get_neuron_pubs(self, neuron, include_subclasses=True, include_nlp=False, """Get publications about a neuron type - :param neuron: An name, symbol, or ID of a neuron type + :param neuron: A name, symbol, or ID of a neuron type :param include_subclasses: Include references for subclasses (subtypes) of this neuron type, default: True :param include_nlp: Include experimental matches from natural language processing. Default = False - :param query_by_label: query using the label, symbol or ID of a neuron. + :param query_by_label: query using the label, symbol or ID of a neuron. Default: True :param verbose: Return underlying cypher query for debugging """ if query_by_label: neuron = self.lookup_id(dequote(neuron)) + cypher_ql = [] if include_subclasses: - cypher_q = "MATCH (n:Neuron)<-[:SUBCLASSOF*0..]-() " + cypher_ql.append("MATCH (n:Neuron:Class)<-[:SUBCLASSOF*0..]-(:Class:Neuron)-[r:has_reference]->(pub:Individual)") else: - cypher_q = "MATCH (n:Neuron) " - cypher_q += """WHERE n.short_form = '%s' - MATCH (n)-[r:has_reference]-(pub) - WHERE pub.title is not null """ % neuron + cypher_ql.append("MATCH (n:Class:Neuron)-[r:has_reference]->(pub:Individual) ") + cypher_ql.append("WHERE n.short_form = '%s' AND pub.title is not null " % neuron) if not include_nlp: - cypher_q += "AND NOT (r.typ = 'nlp') " - cypher_q += """WITH collect ({ type: r.typ, miniref: pub.miniref[0], PMID: pub.PMID[0], DOI: pub.DOI[0], FlyBase: pub.FlyBase, title: pub.title[0]}) as pubs1, n - MATCH (ep:Expression_pattern:Class)<-[ar:part_of]-(anoni:Individual)-[:INSTANCEOF]->(n) - MATCH (pub:pub { short_form: ar.pub[0]}) - WITH pubs1, collect({ type: 'expression', miniref: pub.miniref[0], PMID: pub.PMID[0], DOI: pub.DOI[0], FlyBase: pub.FlyBase }) as pubs2 - RETURN pubs1 + pubs2 as all_pubs""" + cypher_ql.append("AND NOT (r.typ = 'nlp') ") + cypher_ql.append("""RETURN distinct r.typ as source, ([]+pub.miniref)[0] as miniref, + ([]+pub.PMID)[0] as PMID, ([]+pub.DOI)[0] as DOI, ([]+pub.title)[0] as title""") + cypher_ql.append("UNION ALL ") + if include_subclasses: + cypher_ql.append("MATCH (n:Neuron:Class)<-[:SUBCLASSOF*0..]-(:Class:Neuron)") + else: + cypher_ql.append("MATCH (n:Neuron:Class)") + cypher_ql.append("""-[:INSTANCEOF]-(anoni:Individual)-[ar:part_of]->(ep:Expression_pattern:Class) + WHERE n.short_form = '%s' AND exists(ar.pub)""" % neuron) + cypher_ql.append("MATCH (pub:pub { short_form : ar.pub[0]}) ") + cypher_ql.append("""RETURN DISTINCT 'exp' as source, ([]+pub.miniref)[0] as miniref, + ([]+pub.PMID)[0] as PMID, ([]+pub.DOI)[0] as DOI, ([]+pub.title)[0] as title""") + cypher_q = ' \n'.join(cypher_ql) + print(cypher_q) if verbose else None r = self.nc.commit_list([cypher_q]) + if not r: + warnings.warn("No results returned") + return False dc = dict_cursor(r) - print(cypher_q) if verbose else None - return pd.DataFrame.from_records(dc[0]['all_pubs']) + return pd.DataFrame.from_records(dc) # Wrapped neo_query_wrapper methods def get_datasets(self, summary=True, return_dataframe=True): diff --git a/src/vfb_connect/test/cross_server_tools_test.py b/src/vfb_connect/test/cross_server_tools_test.py index 67566e1e..6b5cface 100644 --- a/src/vfb_connect/test/cross_server_tools_test.py +++ b/src/vfb_connect/test/cross_server_tools_test.py @@ -131,6 +131,11 @@ def test_nt_receptors_in_downstream_neurons(self): bar = self.vc.get_nt_receptors_in_downstream_neurons(upstream_type='Dm8', downstream_type='Dm9', weight=10, return_dataframe=False) print(bar) self.assertTrue(len(bar) > 9) + + def test_get_neuron_pubs(self): + fu = self.vc.get_neuron_pubs('Kenyon cell') + self.assertTrue(len(fu)> 9) + class VfbTermTests(unittest.TestCase): def setUp(self):