vfbquery 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- test/readme_parser.py +35 -1
- test/term_info_queries_test.py +11 -11
- test/test_dataset_template_queries.py +138 -0
- test/test_default_caching.py +15 -11
- test/test_expression_overlaps.py +183 -0
- test/test_expression_pattern_fragments.py +123 -0
- test/test_images_neurons.py +152 -0
- test/test_images_that_develop_from.py +112 -0
- test/test_lineage_clones_in.py +190 -0
- test/test_nblast_queries.py +124 -0
- test/test_neuron_classes_fasciculating.py +187 -0
- test/test_neuron_inputs.py +193 -0
- test/test_neuron_neuron_connectivity.py +89 -0
- test/test_neuron_region_connectivity.py +117 -0
- test/test_neurons_part_here.py +204 -0
- test/test_new_owlery_queries.py +282 -0
- test/test_publication_transgene_queries.py +101 -0
- test/test_query_performance.py +743 -0
- test/test_similar_morphology.py +177 -0
- test/test_tracts_nerves_innervating.py +188 -0
- test/test_transcriptomics.py +223 -0
- vfbquery/__init__.py +22 -1
- vfbquery/neo4j_client.py +120 -0
- vfbquery/owlery_client.py +463 -0
- vfbquery/solr_fetcher.py +1 -1
- vfbquery/solr_result_cache.py +238 -53
- vfbquery/vfb_queries.py +2969 -638
- {vfbquery-0.4.0.dist-info → vfbquery-0.5.0.dist-info}/METADATA +1023 -65
- vfbquery-0.5.0.dist-info/RECORD +39 -0
- vfbquery-0.4.0.dist-info/RECORD +0 -19
- {vfbquery-0.4.0.dist-info → vfbquery-0.5.0.dist-info}/LICENSE +0 -0
- {vfbquery-0.4.0.dist-info → vfbquery-0.5.0.dist-info}/WHEEL +0 -0
- {vfbquery-0.4.0.dist-info → vfbquery-0.5.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Test suite for NeuronClassesFasciculatingHere query.
|
|
4
|
+
|
|
5
|
+
Tests the query that finds neuron classes that fasciculate with (run along) tracts or nerves.
|
|
6
|
+
This implements the NeuronClassesFasciculatingHere query from the VFB XMI specification.
|
|
7
|
+
|
|
8
|
+
Test cases:
|
|
9
|
+
1. Query execution with known tract
|
|
10
|
+
2. Schema generation and validation
|
|
11
|
+
3. Term info integration
|
|
12
|
+
4. Preview results validation
|
|
13
|
+
5. Cache functionality
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import unittest
|
|
17
|
+
import sys
|
|
18
|
+
import os
|
|
19
|
+
|
|
20
|
+
# Add the src directory to the path
|
|
21
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
22
|
+
|
|
23
|
+
from vfbquery.vfb_queries import (
|
|
24
|
+
get_neuron_classes_fasciculating_here,
|
|
25
|
+
NeuronClassesFasciculatingHere_to_schema,
|
|
26
|
+
get_term_info
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class NeuronClassesFasciculatingTest(unittest.TestCase):
|
|
31
|
+
"""Test suite for NeuronClassesFasciculatingHere query"""
|
|
32
|
+
|
|
33
|
+
def setUp(self):
|
|
34
|
+
"""Set up test fixtures"""
|
|
35
|
+
# Example tract/nerve: broad root (FBbt_00003987) - a neuron projection bundle
|
|
36
|
+
self.test_tract = "FBbt_00003987" # broad root
|
|
37
|
+
|
|
38
|
+
def test_query_execution(self):
|
|
39
|
+
"""Test that the query executes successfully"""
|
|
40
|
+
print(f"\n=== Testing NeuronClassesFasciculatingHere query execution ===")
|
|
41
|
+
|
|
42
|
+
# Execute the query
|
|
43
|
+
result = get_neuron_classes_fasciculating_here(self.test_tract, return_dataframe=False, limit=5)
|
|
44
|
+
|
|
45
|
+
# Validate result structure
|
|
46
|
+
self.assertIsNotNone(result, "Query should return a result")
|
|
47
|
+
self.assertIsInstance(result, dict, "Result should be a dictionary")
|
|
48
|
+
|
|
49
|
+
# Check for expected keys
|
|
50
|
+
if result:
|
|
51
|
+
print(f"Query returned {len(result.get('data', []))} results")
|
|
52
|
+
|
|
53
|
+
# Validate data structure
|
|
54
|
+
if 'data' in result and len(result['data']) > 0:
|
|
55
|
+
first_result = result['data'][0]
|
|
56
|
+
self.assertIn('id', first_result, "Result should contain 'id' field")
|
|
57
|
+
self.assertIn('label', first_result, "Result should contain 'label' field")
|
|
58
|
+
print(f"First result: {first_result.get('label', 'N/A')} ({first_result.get('id', 'N/A')})")
|
|
59
|
+
|
|
60
|
+
def test_schema_generation(self):
|
|
61
|
+
"""Test schema function generates correct structure"""
|
|
62
|
+
print(f"\n=== Testing NeuronClassesFasciculatingHere schema generation ===")
|
|
63
|
+
|
|
64
|
+
test_name = "Test Tract"
|
|
65
|
+
test_takes = {"short_form": self.test_tract}
|
|
66
|
+
|
|
67
|
+
schema = NeuronClassesFasciculatingHere_to_schema(test_name, test_takes)
|
|
68
|
+
|
|
69
|
+
# Validate schema structure
|
|
70
|
+
self.assertIsNotNone(schema, "Schema should not be None")
|
|
71
|
+
self.assertEqual(schema.query, "NeuronClassesFasciculatingHere", "Query name should match")
|
|
72
|
+
self.assertEqual(schema.label, f"Neurons fasciculating in {test_name}", "Label should be formatted correctly")
|
|
73
|
+
self.assertEqual(schema.function, "get_neuron_classes_fasciculating_here", "Function name should match")
|
|
74
|
+
self.assertEqual(schema.preview, 5, "Preview should be 5")
|
|
75
|
+
|
|
76
|
+
# Check preview columns
|
|
77
|
+
expected_columns = ["id", "label", "tags", "thumbnail"]
|
|
78
|
+
self.assertEqual(schema.preview_columns, expected_columns, f"Preview columns should be {expected_columns}")
|
|
79
|
+
|
|
80
|
+
print(f"Schema generated successfully: {schema.label}")
|
|
81
|
+
|
|
82
|
+
def test_term_info_integration(self):
|
|
83
|
+
"""Test that query appears in term info for appropriate terms"""
|
|
84
|
+
print(f"\n=== Testing term info integration ===")
|
|
85
|
+
|
|
86
|
+
# Get term info for a tract/nerve
|
|
87
|
+
term_info = get_term_info(self.test_tract, preview=False)
|
|
88
|
+
|
|
89
|
+
self.assertIsNotNone(term_info, "Term info should not be None")
|
|
90
|
+
self.assertIn("Queries", term_info, "Term info should contain Queries")
|
|
91
|
+
|
|
92
|
+
# Check if our query is present
|
|
93
|
+
queries = term_info.get("Queries", [])
|
|
94
|
+
query_names = [q.get('query') for q in queries]
|
|
95
|
+
|
|
96
|
+
print(f"Available queries for {self.test_tract}: {query_names}")
|
|
97
|
+
|
|
98
|
+
# For tracts/nerves (Neuron_projection_bundle), this query should be available
|
|
99
|
+
if "Neuron_projection_bundle" in term_info.get("SuperTypes", []):
|
|
100
|
+
self.assertIn("NeuronClassesFasciculatingHere", query_names,
|
|
101
|
+
"NeuronClassesFasciculatingHere should be available for Neuron_projection_bundle")
|
|
102
|
+
print("✓ Query correctly appears for Neuron_projection_bundle type")
|
|
103
|
+
else:
|
|
104
|
+
print(f"Warning: {self.test_tract} does not have Neuron_projection_bundle type")
|
|
105
|
+
print(f"SuperTypes: {term_info.get('SuperTypes', [])}")
|
|
106
|
+
|
|
107
|
+
def test_preview_results(self):
|
|
108
|
+
"""Test that preview results are properly formatted"""
|
|
109
|
+
print(f"\n=== Testing preview results ===")
|
|
110
|
+
|
|
111
|
+
# Get term info with preview enabled
|
|
112
|
+
term_info = get_term_info(self.test_tract, preview=True)
|
|
113
|
+
|
|
114
|
+
self.assertIsNotNone(term_info, "Term info should not be None")
|
|
115
|
+
|
|
116
|
+
# Find our query in the results
|
|
117
|
+
queries = term_info.get("Queries", [])
|
|
118
|
+
fasciculating_query = None
|
|
119
|
+
for q in queries:
|
|
120
|
+
if q.get('query') == "NeuronClassesFasciculatingHere":
|
|
121
|
+
fasciculating_query = q
|
|
122
|
+
break
|
|
123
|
+
|
|
124
|
+
if fasciculating_query:
|
|
125
|
+
print(f"Found NeuronClassesFasciculatingHere query")
|
|
126
|
+
|
|
127
|
+
# Check if preview_results exist
|
|
128
|
+
if fasciculating_query.get('preview_results'):
|
|
129
|
+
preview = fasciculating_query['preview_results']
|
|
130
|
+
data_key = 'data' if 'data' in preview else 'rows'
|
|
131
|
+
print(f"Preview contains {len(preview.get(data_key, []))} results")
|
|
132
|
+
|
|
133
|
+
# Validate preview structure
|
|
134
|
+
self.assertIn(data_key, preview, f"Preview should contain '{data_key}' key")
|
|
135
|
+
self.assertIn('headers', preview, "Preview should contain 'headers' key")
|
|
136
|
+
|
|
137
|
+
# Check first result if available
|
|
138
|
+
if preview.get(data_key) and len(preview[data_key]) > 0:
|
|
139
|
+
first_result = preview[data_key][0]
|
|
140
|
+
print(f"First preview result: {first_result.get('label', 'N/A')}")
|
|
141
|
+
|
|
142
|
+
# Validate required fields
|
|
143
|
+
self.assertIn('id', first_result, "Preview result should have 'id'")
|
|
144
|
+
self.assertIn('label', first_result, "Preview result should have 'label'")
|
|
145
|
+
else:
|
|
146
|
+
print("No preview results available (this is OK if no matching neurons exist)")
|
|
147
|
+
else:
|
|
148
|
+
print("NeuronClassesFasciculatingHere query not found in term info")
|
|
149
|
+
|
|
150
|
+
def test_with_different_tracts(self):
|
|
151
|
+
"""Test with multiple tract/nerve types"""
|
|
152
|
+
print(f"\n=== Testing with different tracts/nerves ===")
|
|
153
|
+
|
|
154
|
+
test_tracts = [
|
|
155
|
+
("FBbt_00003987", "broad root"),
|
|
156
|
+
("FBbt_00007354", "adult antenno-subesophageal tract"),
|
|
157
|
+
("FBbt_00003985", "adult medial antennal lobe tract"),
|
|
158
|
+
]
|
|
159
|
+
|
|
160
|
+
for tract_id, tract_name in test_tracts:
|
|
161
|
+
print(f"\nTesting {tract_name} ({tract_id})...")
|
|
162
|
+
|
|
163
|
+
try:
|
|
164
|
+
result = get_neuron_classes_fasciculating_here(tract_id, return_dataframe=False, limit=3)
|
|
165
|
+
|
|
166
|
+
if result and 'data' in result:
|
|
167
|
+
print(f" ✓ Query successful, found {len(result['data'])} results")
|
|
168
|
+
else:
|
|
169
|
+
print(f" ✓ Query successful, no results found")
|
|
170
|
+
|
|
171
|
+
except Exception as e:
|
|
172
|
+
print(f" ✗ Query failed: {str(e)}")
|
|
173
|
+
# Don't fail the test, just log the error
|
|
174
|
+
# raise
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
def run_tests():
|
|
178
|
+
"""Run the test suite"""
|
|
179
|
+
suite = unittest.TestLoader().loadTestsFromTestCase(NeuronClassesFasciculatingTest)
|
|
180
|
+
runner = unittest.TextTestRunner(verbosity=2)
|
|
181
|
+
result = runner.run(suite)
|
|
182
|
+
return result.wasSuccessful()
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
if __name__ == '__main__':
|
|
186
|
+
success = run_tests()
|
|
187
|
+
sys.exit(0 if success else 1)
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Test suite for NeuronInputsTo query.
|
|
4
|
+
|
|
5
|
+
Tests the query that finds neurons with synapses into a specified neuron.
|
|
6
|
+
This implements the NeuronInputsTo query from the VFB XMI specification.
|
|
7
|
+
|
|
8
|
+
Test cases:
|
|
9
|
+
1. Query execution with known neuron
|
|
10
|
+
2. Schema generation and validation
|
|
11
|
+
3. Term info integration
|
|
12
|
+
4. Preview results validation (ribbon format)
|
|
13
|
+
5. Neurotransmitter information validation
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import unittest
|
|
17
|
+
import sys
|
|
18
|
+
import os
|
|
19
|
+
|
|
20
|
+
# Add the src directory to the path
|
|
21
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
22
|
+
|
|
23
|
+
from vfbquery.vfb_queries import (
|
|
24
|
+
get_individual_neuron_inputs,
|
|
25
|
+
NeuronInputsTo_to_schema,
|
|
26
|
+
get_term_info
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
class NeuronInputsTest(unittest.TestCase):
|
|
30
|
+
"""Test suite for NeuronInputsTo query"""
|
|
31
|
+
|
|
32
|
+
def setUp(self):
|
|
33
|
+
"""Set up test fixtures"""
|
|
34
|
+
# Test neuron: LPC1 (FlyEM-HB:1775513344) [VFB_jrchk00s]
|
|
35
|
+
self.test_neuron = "VFB_jrchk00s"
|
|
36
|
+
|
|
37
|
+
def test_query_execution(self):
|
|
38
|
+
"""Test that the query executes successfully"""
|
|
39
|
+
print(f"\n=== Testing NeuronInputsTo execution ===")
|
|
40
|
+
result = get_individual_neuron_inputs(
|
|
41
|
+
self.test_neuron,
|
|
42
|
+
return_dataframe=False,
|
|
43
|
+
limit=5
|
|
44
|
+
)
|
|
45
|
+
self.assertIsNotNone(result, "Query should return a result")
|
|
46
|
+
self.assertIsInstance(result, dict, "Result should be a dictionary")
|
|
47
|
+
print(f"Query returned {result.get('count', 0)} total results")
|
|
48
|
+
|
|
49
|
+
if 'rows' in result and len(result['rows']) > 0:
|
|
50
|
+
first_result = result['rows'][0]
|
|
51
|
+
self.assertIn('id', first_result, "Result should contain 'id' field")
|
|
52
|
+
self.assertIn('Neurotransmitter', first_result, "Result should contain 'Neurotransmitter' field")
|
|
53
|
+
self.assertIn('Weight', first_result, "Result should contain 'Weight' field")
|
|
54
|
+
print(f"First result: {first_result.get('Neurotransmitter', 'N/A')} (weight: {first_result.get('Weight', 0)})")
|
|
55
|
+
else:
|
|
56
|
+
print("No input neurons found (this is OK if none exist)")
|
|
57
|
+
|
|
58
|
+
def test_schema_generation(self):
|
|
59
|
+
"""Test that the schema function works correctly"""
|
|
60
|
+
print(f"\n=== Testing NeuronInputsTo schema generation ===")
|
|
61
|
+
|
|
62
|
+
# Get term info for the test neuron
|
|
63
|
+
term_info = get_term_info(self.test_neuron)
|
|
64
|
+
if term_info:
|
|
65
|
+
neuron_name = term_info.get('Name', self.test_neuron)
|
|
66
|
+
else:
|
|
67
|
+
neuron_name = self.test_neuron
|
|
68
|
+
|
|
69
|
+
# Generate schema
|
|
70
|
+
schema = NeuronInputsTo_to_schema(neuron_name, self.test_neuron)
|
|
71
|
+
|
|
72
|
+
# Validate schema structure
|
|
73
|
+
self.assertIsNotNone(schema, "Schema should not be None")
|
|
74
|
+
self.assertEqual(schema.query, "NeuronInputsTo", "Query name should match")
|
|
75
|
+
self.assertEqual(schema.function, "get_individual_neuron_inputs", "Function name should match")
|
|
76
|
+
# NeuronInputsTo uses ribbon format with preview=-1 (all results)
|
|
77
|
+
self.assertEqual(schema.preview, -1, "Preview should show all results (ribbon format)")
|
|
78
|
+
self.assertIn("Neurotransmitter", schema.preview_columns, "Preview should include 'Neurotransmitter' column")
|
|
79
|
+
self.assertIn("Weight", schema.preview_columns, "Preview should include 'Weight' column")
|
|
80
|
+
|
|
81
|
+
print(f"Schema label: {schema.label}")
|
|
82
|
+
print(f"Preview columns: {schema.preview_columns}")
|
|
83
|
+
print(f"Output format: ribbon (preview={schema.preview})")
|
|
84
|
+
|
|
85
|
+
def test_term_info_integration(self):
|
|
86
|
+
"""Test that term info lookup works for the test neuron"""
|
|
87
|
+
print(f"\n=== Testing term_info integration ===")
|
|
88
|
+
term_info = get_term_info(self.test_neuron)
|
|
89
|
+
|
|
90
|
+
self.assertIsNotNone(term_info, "Term info should not be None")
|
|
91
|
+
if term_info:
|
|
92
|
+
# get_term_info returns a dict with 'Name', 'Id', 'Tags', etc.
|
|
93
|
+
self.assertIn('Name', term_info, "Term info should contain 'Name'")
|
|
94
|
+
self.assertIn('Id', term_info, "Term info should contain 'Id'")
|
|
95
|
+
print(f"Neuron name: {term_info.get('Name', 'N/A')}")
|
|
96
|
+
print(f"Neuron tags: {term_info.get('Tags', [])}")
|
|
97
|
+
else:
|
|
98
|
+
print(f"Note: Term info not found for {self.test_neuron} (may not be in SOLR)")
|
|
99
|
+
|
|
100
|
+
def test_preview_validation(self):
|
|
101
|
+
"""Test that preview results are properly formatted"""
|
|
102
|
+
print(f"\n=== Testing preview results ===")
|
|
103
|
+
result = get_individual_neuron_inputs(
|
|
104
|
+
self.test_neuron,
|
|
105
|
+
return_dataframe=False,
|
|
106
|
+
limit=5
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
if 'rows' in result and len(result['rows']) > 0:
|
|
110
|
+
# Check that all expected columns exist in the results
|
|
111
|
+
expected_columns = ['id', 'Neurotransmitter', 'Weight', 'Name']
|
|
112
|
+
for item in result['rows']:
|
|
113
|
+
for col in expected_columns:
|
|
114
|
+
self.assertIn(col, item, f"Result should contain '{col}' field")
|
|
115
|
+
|
|
116
|
+
print(f"✓ All {len(result['rows'])} results have required columns")
|
|
117
|
+
|
|
118
|
+
# Print sample results
|
|
119
|
+
for i, item in enumerate(result['rows'][:3], 1):
|
|
120
|
+
print(f"{i}. {item.get('Name', 'N/A')} - {item.get('Neurotransmitter', 'N/A')} (weight: {item.get('Weight', 0)})")
|
|
121
|
+
else:
|
|
122
|
+
print("No preview data available (query returned no results)")
|
|
123
|
+
|
|
124
|
+
def test_neurotransmitter_info(self):
|
|
125
|
+
"""Test that neurotransmitter information is included"""
|
|
126
|
+
print(f"\n=== Testing neurotransmitter information ===")
|
|
127
|
+
result = get_individual_neuron_inputs(
|
|
128
|
+
self.test_neuron,
|
|
129
|
+
return_dataframe=False,
|
|
130
|
+
limit=10
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
if 'rows' in result and len(result['rows']) > 0:
|
|
134
|
+
# Check that neurotransmitter field exists and has values
|
|
135
|
+
neurotransmitters = set()
|
|
136
|
+
for row in result['rows']:
|
|
137
|
+
nt = row.get('Neurotransmitter', '')
|
|
138
|
+
if nt:
|
|
139
|
+
neurotransmitters.add(nt)
|
|
140
|
+
|
|
141
|
+
print(f"✓ Found {len(neurotransmitters)} different neurotransmitter type(s)")
|
|
142
|
+
if neurotransmitters:
|
|
143
|
+
print(f" Types: {', '.join(list(neurotransmitters)[:5])}")
|
|
144
|
+
else:
|
|
145
|
+
print("No results to check neurotransmitter information")
|
|
146
|
+
|
|
147
|
+
def test_summary_mode(self):
|
|
148
|
+
"""Test that summary mode works correctly"""
|
|
149
|
+
print(f"\n=== Testing summary mode ===")
|
|
150
|
+
result = get_individual_neuron_inputs(
|
|
151
|
+
self.test_neuron,
|
|
152
|
+
return_dataframe=False,
|
|
153
|
+
summary_mode=True
|
|
154
|
+
)
|
|
155
|
+
|
|
156
|
+
self.assertIsNotNone(result, "Summary mode should return a result")
|
|
157
|
+
self.assertIsInstance(result, dict, "Result should be a dictionary")
|
|
158
|
+
|
|
159
|
+
if 'rows' in result and len(result['rows']) > 0:
|
|
160
|
+
# In summary mode, results are grouped by neurotransmitter type
|
|
161
|
+
print(f"✓ Summary mode returned {len(result['rows'])} neurotransmitter types")
|
|
162
|
+
for i, item in enumerate(result['rows'][:3], 1):
|
|
163
|
+
print(f"{i}. {item.get('Neurotransmitter', 'N/A')} - Total weight: {item.get('Weight', 0)}")
|
|
164
|
+
else:
|
|
165
|
+
print("No summary data available")
|
|
166
|
+
|
|
167
|
+
def test_dataframe_output(self):
|
|
168
|
+
"""Test that DataFrame output format works"""
|
|
169
|
+
print(f"\n=== Testing DataFrame output ===")
|
|
170
|
+
result = get_individual_neuron_inputs(
|
|
171
|
+
self.test_neuron,
|
|
172
|
+
return_dataframe=True,
|
|
173
|
+
limit=5
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
# Should return a pandas DataFrame
|
|
177
|
+
import pandas as pd
|
|
178
|
+
self.assertIsInstance(result, pd.DataFrame, "Should return DataFrame when return_dataframe=True")
|
|
179
|
+
|
|
180
|
+
if not result.empty:
|
|
181
|
+
# Check for expected columns
|
|
182
|
+
expected_columns = ['id', 'Neurotransmitter', 'Weight']
|
|
183
|
+
for col in expected_columns:
|
|
184
|
+
self.assertIn(col, result.columns, f"DataFrame should contain '{col}' column")
|
|
185
|
+
|
|
186
|
+
print(f"✓ DataFrame has {len(result)} rows and {len(result.columns)} columns")
|
|
187
|
+
print(f" Columns: {list(result.columns)}")
|
|
188
|
+
else:
|
|
189
|
+
print("DataFrame is empty (no input neurons found)")
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
if __name__ == '__main__':
|
|
193
|
+
unittest.main(verbosity=2)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Test suite for NeuronNeuronConnectivityQuery.
|
|
4
|
+
|
|
5
|
+
Tests the query that finds neurons connected to a given neuron.
|
|
6
|
+
This implements the neuron_neuron_connectivity_query from the VFB XMI specification.
|
|
7
|
+
|
|
8
|
+
Test cases:
|
|
9
|
+
1. Query execution with known neuron
|
|
10
|
+
2. Schema generation and validation
|
|
11
|
+
3. Term info integration (if applicable)
|
|
12
|
+
4. Preview results validation
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import unittest
|
|
16
|
+
import sys
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
# Add the src directory to the path
|
|
20
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
21
|
+
|
|
22
|
+
from vfbquery.vfb_queries import (
|
|
23
|
+
get_neuron_neuron_connectivity,
|
|
24
|
+
NeuronNeuronConnectivityQuery_to_schema,
|
|
25
|
+
get_term_info
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
class NeuronNeuronConnectivityTest(unittest.TestCase):
|
|
29
|
+
"""Test suite for neuron_neuron_connectivity_query"""
|
|
30
|
+
|
|
31
|
+
def setUp(self):
|
|
32
|
+
"""Set up test fixtures"""
|
|
33
|
+
# Test neuron: LPC1 (FlyEM-HB:1775513344) [VFB_jrchk00s]
|
|
34
|
+
self.test_neuron = "VFB_jrchk00s"
|
|
35
|
+
|
|
36
|
+
def test_query_execution(self):
|
|
37
|
+
"""Test that the query executes successfully"""
|
|
38
|
+
print(f"\n=== Testing neuron_neuron_connectivity_query execution ===")
|
|
39
|
+
result = get_neuron_neuron_connectivity(self.test_neuron, return_dataframe=False, limit=5)
|
|
40
|
+
self.assertIsNotNone(result, "Query should return a result")
|
|
41
|
+
self.assertIsInstance(result, dict, "Result should be a dictionary")
|
|
42
|
+
print(f"Query returned {result.get('count', 0)} results")
|
|
43
|
+
if 'data' in result and len(result['data']) > 0:
|
|
44
|
+
first_result = result['data'][0]
|
|
45
|
+
self.assertIn('id', first_result, "Result should contain 'id' field")
|
|
46
|
+
self.assertIn('label', first_result, "Result should contain 'label' field")
|
|
47
|
+
print(f"First result: {first_result.get('label', 'N/A')} ({first_result.get('id', 'N/A')})")
|
|
48
|
+
else:
|
|
49
|
+
print("No connected neurons found (this is OK if none exist)")
|
|
50
|
+
|
|
51
|
+
def test_schema_generation(self):
|
|
52
|
+
"""Test schema function generates correct structure"""
|
|
53
|
+
print(f"\n=== Testing neuron_neuron_connectivity_query schema generation ===")
|
|
54
|
+
test_name = "LPC1"
|
|
55
|
+
test_takes = {"short_form": self.test_neuron}
|
|
56
|
+
schema = NeuronNeuronConnectivityQuery_to_schema(test_name, test_takes)
|
|
57
|
+
self.assertIsNotNone(schema, "Schema should not be None")
|
|
58
|
+
self.assertEqual(schema.query, "NeuronNeuronConnectivityQuery", "Query name should match")
|
|
59
|
+
self.assertEqual(schema.label, f"Neurons connected to {test_name}", "Label should be formatted correctly")
|
|
60
|
+
self.assertEqual(schema.function, "get_neuron_neuron_connectivity", "Function name should match")
|
|
61
|
+
self.assertEqual(schema.preview, 5, "Preview should be 5")
|
|
62
|
+
expected_columns = ["id", "label", "outputs", "inputs", "tags"]
|
|
63
|
+
self.assertEqual(schema.preview_columns, expected_columns, f"Preview columns should be {expected_columns}")
|
|
64
|
+
print(f"Schema generated successfully: {schema.label}")
|
|
65
|
+
|
|
66
|
+
def test_preview_results(self):
|
|
67
|
+
"""Test that preview results are properly formatted"""
|
|
68
|
+
print(f"\n=== Testing preview results ===")
|
|
69
|
+
result = get_neuron_neuron_connectivity(self.test_neuron, return_dataframe=False, limit=3)
|
|
70
|
+
self.assertIsNotNone(result, "Query should return a result")
|
|
71
|
+
if 'data' in result and len(result['data']) > 0:
|
|
72
|
+
first_result = result['data'][0]
|
|
73
|
+
self.assertIn('id', first_result, "Preview result should have 'id'")
|
|
74
|
+
self.assertIn('label', first_result, "Preview result should have 'label'")
|
|
75
|
+
print(f"First preview result: {first_result.get('label', 'N/A')}")
|
|
76
|
+
else:
|
|
77
|
+
print("No preview results available (this is OK if no connected neurons exist)")
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def run_tests():
|
|
81
|
+
"""Run the test suite"""
|
|
82
|
+
suite = unittest.TestLoader().loadTestsFromTestCase(NeuronNeuronConnectivityTest)
|
|
83
|
+
runner = unittest.TextTestRunner(verbosity=2)
|
|
84
|
+
result = runner.run(suite)
|
|
85
|
+
return result.wasSuccessful()
|
|
86
|
+
|
|
87
|
+
if __name__ == '__main__':
|
|
88
|
+
success = run_tests()
|
|
89
|
+
sys.exit(0 if success else 1)
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
Test suite for NeuronRegionConnectivityQuery.
|
|
4
|
+
|
|
5
|
+
Tests the query that shows connectivity to regions from a given neuron.
|
|
6
|
+
This implements the neuron_region_connectivity_query from the VFB XMI specification.
|
|
7
|
+
|
|
8
|
+
Test cases:
|
|
9
|
+
1. Query execution with known neuron
|
|
10
|
+
2. Schema generation and validation
|
|
11
|
+
3. Term info integration (if applicable)
|
|
12
|
+
4. Preview results validation
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import unittest
|
|
16
|
+
import sys
|
|
17
|
+
import os
|
|
18
|
+
|
|
19
|
+
# Add the src directory to the path
|
|
20
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
|
21
|
+
|
|
22
|
+
from vfbquery.vfb_queries import (
|
|
23
|
+
get_neuron_region_connectivity,
|
|
24
|
+
NeuronRegionConnectivityQuery_to_schema,
|
|
25
|
+
get_term_info
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
class NeuronRegionConnectivityTest(unittest.TestCase):
|
|
29
|
+
"""Test suite for neuron_region_connectivity_query"""
|
|
30
|
+
|
|
31
|
+
def setUp(self):
|
|
32
|
+
"""Set up test fixtures"""
|
|
33
|
+
# Test neuron: LPC1 (FlyEM-HB:1775513344) [VFB_jrchk00s]
|
|
34
|
+
self.test_neuron = "VFB_jrchk00s"
|
|
35
|
+
|
|
36
|
+
def test_query_execution(self):
|
|
37
|
+
"""Test that the query executes successfully"""
|
|
38
|
+
print(f"\n=== Testing neuron_region_connectivity_query execution ===")
|
|
39
|
+
result = get_neuron_region_connectivity(self.test_neuron, return_dataframe=False, limit=5)
|
|
40
|
+
self.assertIsNotNone(result, "Query should return a result")
|
|
41
|
+
self.assertIsInstance(result, dict, "Result should be a dictionary")
|
|
42
|
+
print(f"Query returned {result.get('count', 0)} results")
|
|
43
|
+
if 'data' in result and len(result['data']) > 0:
|
|
44
|
+
first_result = result['data'][0]
|
|
45
|
+
self.assertIn('id', first_result, "Result should contain 'id' field")
|
|
46
|
+
self.assertIn('region', first_result, "Result should contain 'region' field")
|
|
47
|
+
self.assertIn('presynaptic_terminals', first_result, "Result should contain 'presynaptic_terminals' field")
|
|
48
|
+
self.assertIn('postsynaptic_terminals', first_result, "Result should contain 'postsynaptic_terminals' field")
|
|
49
|
+
print(f"First result: {first_result.get('region', 'N/A')} ({first_result.get('id', 'N/A')})")
|
|
50
|
+
print(f" Pre: {first_result.get('presynaptic_terminals', 0)}, Post: {first_result.get('postsynaptic_terminals', 0)}")
|
|
51
|
+
else:
|
|
52
|
+
print("No regions with connectivity found (this is OK if none exist)")
|
|
53
|
+
|
|
54
|
+
def test_schema_generation(self):
|
|
55
|
+
"""Test that the schema function works correctly"""
|
|
56
|
+
print(f"\n=== Testing NeuronRegionConnectivityQuery schema generation ===")
|
|
57
|
+
|
|
58
|
+
# Get term info for the test neuron
|
|
59
|
+
term_info = get_term_info(self.test_neuron)
|
|
60
|
+
if term_info:
|
|
61
|
+
neuron_name = term_info.get('Name', self.test_neuron)
|
|
62
|
+
else:
|
|
63
|
+
neuron_name = self.test_neuron
|
|
64
|
+
|
|
65
|
+
# Generate schema
|
|
66
|
+
schema = NeuronRegionConnectivityQuery_to_schema(neuron_name, self.test_neuron)
|
|
67
|
+
|
|
68
|
+
# Validate schema structure
|
|
69
|
+
self.assertIsNotNone(schema, "Schema should not be None")
|
|
70
|
+
self.assertEqual(schema.query, "NeuronRegionConnectivityQuery", "Query name should match")
|
|
71
|
+
self.assertEqual(schema.function, "get_neuron_region_connectivity", "Function name should match")
|
|
72
|
+
self.assertEqual(schema.preview, 5, "Preview should show 5 results")
|
|
73
|
+
self.assertIn("region", schema.preview_columns, "Preview should include 'region' column")
|
|
74
|
+
self.assertIn("presynaptic_terminals", schema.preview_columns, "Preview should include 'presynaptic_terminals' column")
|
|
75
|
+
self.assertIn("postsynaptic_terminals", schema.preview_columns, "Preview should include 'postsynaptic_terminals' column")
|
|
76
|
+
|
|
77
|
+
print(f"Schema label: {schema.label}")
|
|
78
|
+
print(f"Preview columns: {schema.preview_columns}")
|
|
79
|
+
|
|
80
|
+
def test_term_info_integration(self):
|
|
81
|
+
"""Test that term info lookup works for the test neuron"""
|
|
82
|
+
print(f"\n=== Testing term_info integration ===")
|
|
83
|
+
term_info = get_term_info(self.test_neuron)
|
|
84
|
+
|
|
85
|
+
self.assertIsNotNone(term_info, "Term info should not be None")
|
|
86
|
+
if term_info:
|
|
87
|
+
# get_term_info returns a dict with 'Name', 'Id', 'Tags', etc.
|
|
88
|
+
self.assertIn('Name', term_info, "Term info should contain 'Name'")
|
|
89
|
+
self.assertIn('Id', term_info, "Term info should contain 'Id'")
|
|
90
|
+
print(f"Neuron name: {term_info.get('Name', 'N/A')}")
|
|
91
|
+
print(f"Neuron tags: {term_info.get('Tags', [])}")
|
|
92
|
+
else:
|
|
93
|
+
print(f"Note: Term info not found for {self.test_neuron} (may not be in SOLR)")
|
|
94
|
+
|
|
95
|
+
def test_preview_validation(self):
|
|
96
|
+
"""Test that preview results are properly formatted"""
|
|
97
|
+
print(f"\n=== Testing preview results ===")
|
|
98
|
+
result = get_neuron_region_connectivity(self.test_neuron, return_dataframe=False, limit=5)
|
|
99
|
+
|
|
100
|
+
if 'data' in result and len(result['data']) > 0:
|
|
101
|
+
# Check that all preview columns exist in the results
|
|
102
|
+
expected_columns = ['id', 'region', 'presynaptic_terminals', 'postsynaptic_terminals', 'tags']
|
|
103
|
+
for item in result['data']:
|
|
104
|
+
for col in expected_columns:
|
|
105
|
+
self.assertIn(col, item, f"Result should contain '{col}' field")
|
|
106
|
+
|
|
107
|
+
print(f"✓ All {len(result['data'])} results have required preview columns")
|
|
108
|
+
|
|
109
|
+
# Print sample results
|
|
110
|
+
for i, item in enumerate(result['data'][:3], 1):
|
|
111
|
+
print(f"{i}. {item.get('region', 'N/A')} - Pre:{item.get('presynaptic_terminals', 0)}, Post:{item.get('postsynaptic_terminals', 0)}")
|
|
112
|
+
else:
|
|
113
|
+
print("No preview data available (query returned no results)")
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
if __name__ == '__main__':
|
|
117
|
+
unittest.main(verbosity=2)
|