Skip to content

Commit a3df469

Browse files
committed
Refactor code structure for improved readability and maintainability
1 parent 2e8da90 commit a3df469

3 files changed

Lines changed: 2808 additions & 0 deletions

File tree

update_instances_templates.py

Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
import ast
2+
3+
# Read the current test_results.py
4+
with open('test_results.py', 'r') as f:
5+
content = f.read()
6+
7+
# Parse the results list
8+
tree = ast.parse(content)
9+
results_assign = None
10+
for node in ast.walk(tree):
11+
if isinstance(node, ast.Assign) and len(node.targets) == 1 and isinstance(node.targets[0], ast.Name) and node.targets[0].id == 'results':
12+
results_assign = node
13+
break
14+
15+
if not results_assign:
16+
raise ValueError("Could not find results assignment")
17+
18+
# Get the current results list
19+
current_results = ast.literal_eval(ast.unparse(results_assign.value))
20+
21+
# New instances data (from the diff test output for example #4)
22+
new_instances = {
23+
"headers": {
24+
"id": {
25+
"title": "Add",
26+
"type": "selection_id",
27+
"order": -1
28+
},
29+
"label": {
30+
"title": "Name",
31+
"type": "markdown",
32+
"order": 0,
33+
"sort": {
34+
"0": "Asc"
35+
}
36+
},
37+
"parent": {
38+
"title": "Parent Type",
39+
"type": "markdown",
40+
"order": 1
41+
},
42+
"template": {
43+
"title": "Template",
44+
"type": "markdown",
45+
"order": 4
46+
},
47+
"tags": {
48+
"title": "Gross Types",
49+
"type": "tags",
50+
"order": 3
51+
},
52+
"source": {
53+
"title": "Data Source",
54+
"type": "markdown",
55+
"order": 5
56+
},
57+
"source_id": {
58+
"title": "Data Source",
59+
"type": "markdown",
60+
"order": 6
61+
},
62+
"dataset": {
63+
"title": "Dataset",
64+
"type": "markdown",
65+
"order": 7
66+
},
67+
"license": {
68+
"title": "License",
69+
"type": "markdown",
70+
"order": 8
71+
},
72+
"thumbnail": {
73+
"title": "Thumbnail",
74+
"type": "markdown",
75+
"order": 9
76+
}
77+
},
78+
"rows": [
79+
{
80+
"id": "VFB_00102107",
81+
"label": "[ME on JRC2018Unisex adult brain](VFB_00102107)",
82+
"tags": "Nervous_system|Adult|Visual_system|Synaptic_neuropil_domain",
83+
"parent": "[medulla](FBbt_00003748)",
84+
"source": "",
85+
"source_id": "",
86+
"template": "[JRC2018U](VFB_00101567)",
87+
"dataset": "[JRC 2018 templates & ROIs](JRC2018)",
88+
"license": "",
89+
"thumbnail": "[![ME on JRC2018Unisex adult brain aligned to JRC2018U](https://www.virtualflybrain.org/data/VFB/i/0010/2107/VFB_00101567/thumbnail.png \"ME on JRC2018Unisex adult brain aligned to JRC2018U\")](VFB_00101567,VFB_00102107)"
90+
},
91+
{
92+
"id": "VFB_00101385",
93+
"label": "[ME(R) on JRC_FlyEM_Hemibrain](VFB_00101385)",
94+
"tags": "Nervous_system|Adult|Visual_system|Synaptic_neuropil_domain",
95+
"parent": "[medulla](FBbt_00003748)",
96+
"source": "",
97+
"source_id": "",
98+
"template": "[JRCFIB2018Fum](VFB_00101384)",
99+
"dataset": "[JRC_FlyEM_Hemibrain painted domains](Xu2020roi)",
100+
"license": "",
101+
"thumbnail": "[![ME(R) on JRC_FlyEM_Hemibrain aligned to JRCFIB2018Fum](https://www.virtualflybrain.org/data/VFB/i/0010/1385/VFB_00101384/thumbnail.png \"ME(R) on JRC_FlyEM_Hemibrain aligned to JRCFIB2018Fum\")](VFB_00101384,VFB_00101385)"
102+
},
103+
{
104+
"id": "VFB_00030810",
105+
"label": "[medulla on adult brain template Ito2014](VFB_00030810)",
106+
"tags": "Nervous_system|Visual_system|Adult|Synaptic_neuropil_domain",
107+
"parent": "[medulla](FBbt_00003748)",
108+
"source": "",
109+
"source_id": "",
110+
"template": "[adult brain template Ito2014](VFB_00030786)",
111+
"dataset": "[BrainName neuropils and tracts - Ito half-brain](BrainName_Ito_half_brain)",
112+
"license": "",
113+
"thumbnail": "[![medulla on adult brain template Ito2014 aligned to adult brain template Ito2014](https://www.virtualflybrain.org/data/VFB/i/0003/0810/VFB_00030786/thumbnail.png \"medulla on adult brain template Ito2014 aligned to adult brain template Ito2014\")](VFB_00030786,VFB_00030810)"
114+
},
115+
{
116+
"id": "VFB_00030624",
117+
"label": "[medulla on adult brain template JFRC2](VFB_00030624)",
118+
"tags": "Nervous_system|Visual_system|Adult|Synaptic_neuropil_domain",
119+
"parent": "[medulla](FBbt_00003748)",
120+
"source": "",
121+
"source_id": "",
122+
"template": "[JFRC2](VFB_00017894)",
123+
"dataset": "[BrainName neuropils on adult brain JFRC2 (Jenett, Shinomya)](JenettShinomya_BrainName)",
124+
"license": "",
125+
"thumbnail": "[![medulla on adult brain template JFRC2 aligned to JFRC2](https://www.virtualflybrain.org/data/VFB/i/0003/0624/VFB_00017894/thumbnail.png \"medulla on adult brain template JFRC2 aligned to JFRC2\")](VFB_00017894,VFB_00030624)"
126+
}
127+
],
128+
"count": 4
129+
}
130+
131+
# New templates data (from the diff test output for example #5)
132+
new_templates = {
133+
"headers": {
134+
"id": {
135+
"title": "Add",
136+
"type": "selection_id",
137+
"order": -1
138+
},
139+
"order": {
140+
"title": "Order",
141+
"type": "numeric",
142+
"order": 1,
143+
"sort": {
144+
"0": "Asc"
145+
}
146+
},
147+
"name": {
148+
"title": "Name",
149+
"type": "markdown",
150+
"order": 1,
151+
"sort": {
152+
"1": "Asc"
153+
}
154+
},
155+
"tags": {
156+
"title": "Tags",
157+
"type": "tags",
158+
"order": 2
159+
},
160+
"thumbnail": {
161+
"title": "Thumbnail",
162+
"type": "markdown",
163+
"order": 9
164+
},
165+
"dataset": {
166+
"title": "Dataset",
167+
"type": "metadata",
168+
"order": 3
169+
},
170+
"license": {
171+
"title": "License",
172+
"type": "metadata",
173+
"order": 4
174+
}
175+
},
176+
"rows": [
177+
{
178+
"id": "VFB_00200000",
179+
"order": 2,
180+
"name": "[JRCVNC2018U](VFB_00200000)",
181+
"tags": "Nervous_system|Adult|Ganglion",
182+
"thumbnail": "[![JRCVNC2018U](http://www.virtualflybrain.org/data/VFB/i/0020/0000/VFB_00200000/thumbnail.png 'JRCVNC2018U')](VFB_00200000)",
183+
"dataset": "[JRC 2018 templates & ROIs](JRC2018)",
184+
"license": "[CC-BY-NC-SA](VFBlicense_CC_BY_NC_SA_4_0)"
185+
},
186+
{
187+
"id": "VFB_00120000",
188+
"order": 10,
189+
"name": "[Adult T1 Leg (Kuan2020)](VFB_00120000)",
190+
"tags": "Adult|Anatomy",
191+
"thumbnail": "[![Adult T1 Leg (Kuan2020)](http://www.virtualflybrain.org/data/VFB/i/0012/0000/VFB_00120000/thumbnail.png 'Adult T1 Leg (Kuan2020)')](VFB_00120000)",
192+
"dataset": "[Millimeter-scale imaging of a Drosophila leg at single-neuron resolution](Kuan2020)",
193+
"license": "[CC_BY](VFBlicense_CC_BY_4_0)"
194+
},
195+
{
196+
"id": "VFB_00110000",
197+
"order": 9,
198+
"name": "[Adult Head (McKellar2020)](VFB_00110000)",
199+
"tags": "Adult|Anatomy",
200+
"thumbnail": "[![Adult Head (McKellar2020)](http://www.virtualflybrain.org/data/VFB/i/0011/0000/VFB_00110000/thumbnail.png 'Adult Head (McKellar2020)')](VFB_00110000)",
201+
"dataset": "[GAL4 lines from McKellar et al., 2020](McKellar2020)",
202+
"license": "[CC_BY_SA](VFBlicense_CC_BY_SA_4_0)"
203+
},
204+
{
205+
"id": "VFB_00101567",
206+
"order": 1,
207+
"name": "[JRC2018U](VFB_00101567)",
208+
"tags": "Nervous_system|Adult",
209+
"thumbnail": "[![JRC2018U](http://www.virtualflybrain.org/data/VFB/i/0010/1567/VFB_00101567/thumbnail.png 'JRC2018U')](VFB_00101567)",
210+
"dataset": "[JRC 2018 templates & ROIs](JRC2018)",
211+
"license": "[CC-BY-NC-SA](VFBlicense_CC_BY_NC_SA_4_0)"
212+
},
213+
{
214+
"id": "VFB_00101384",
215+
"order": 4,
216+
"name": "[JRCFIB2018Fum](VFB_00101384)",
217+
"tags": "Nervous_system|Adult",
218+
"thumbnail": "[![JRCFIB2018Fum](http://www.virtualflybrain.org/data/VFB/i/0010/1384/VFB_00101384/thumbnail.png 'JRCFIB2018Fum')](VFB_00101384)",
219+
"dataset": "[JRC_FlyEM_Hemibrain painted domains](Xu2020roi)",
220+
"license": "[CC_BY](VFBlicense_CC_BY_4_0)"
221+
},
222+
{
223+
"id": "VFB_00100000",
224+
"order": 7,
225+
"name": "[COURT2018VNS](VFB_00100000)",
226+
"tags": "Nervous_system|Adult|Ganglion",
227+
"thumbnail": "[![COURT2018VNS](http://www.virtualflybrain.org/data/VFB/i/0010/0000/VFB_00100000/thumbnail.png 'COURT2018VNS')](VFB_00100000)",
228+
"dataset": "[Adult VNS neuropils (Court2017)](Court2017)",
229+
"license": "[CC_BY_SA](VFBlicense_CC_BY_SA_4_0)"
230+
},
231+
{
232+
"id": "VFB_00050000",
233+
"order": 5,
234+
"name": "[L1 larval CNS ssTEM - Cardona/Janelia](VFB_00050000)",
235+
"tags": "Nervous_system|Larva",
236+
"thumbnail": "[![L1 larval CNS ssTEM - Cardona/Janelia](http://www.virtualflybrain.org/data/VFB/i/0005/0000/VFB_00050000/thumbnail.png 'L1 larval CNS ssTEM - Cardona/Janelia')](VFB_00050000)",
237+
"dataset": "[larval hugin neurons - EM (Schlegel2016)](Schlegel2016), [Neurons involved in larval fast escape response - EM (Ohyama2016)](Ohyama2015)",
238+
"license": "[CC_BY](VFBlicense_CC_BY_4_0), [CC_BY_SA](VFBlicense_CC_BY_SA_4_0)"
239+
},
240+
{
241+
"id": "VFB_00049000",
242+
"order": 6,
243+
"name": "[L3 CNS template - Wood2018](VFB_00049000)",
244+
"tags": "Nervous_system|Larva",
245+
"thumbnail": "[![L3 CNS template - Wood2018](http://www.virtualflybrain.org/data/VFB/i/0004/9000/VFB_00049000/thumbnail.png 'L3 CNS template - Wood2018')](VFB_00049000)",
246+
"dataset": "[L3 Larval CNS Template (Truman2016)](Truman2016)",
247+
"license": "[CC_BY_SA](VFBlicense_CC_BY_SA_4_0)"
248+
},
249+
{
250+
"id": "VFB_00030786",
251+
"order": 8,
252+
"name": "[adult brain template Ito2014](VFB_00030786)",
253+
"tags": "Nervous_system|Adult",
254+
"thumbnail": "[![adult brain template Ito2014](http://www.virtualflybrain.org/data/VFB/i/0003/0786/VFB_00030786/thumbnail.png 'adult brain template Ito2014')](VFB_00030786)",
255+
"dataset": "[BrainName neuropils and tracts - Ito half-brain](BrainName_Ito_half_brain)",
256+
"license": "[CC_BY_SA](VFBlicense_CC_BY_SA_4_0)"
257+
},
258+
{
259+
"id": "VFB_00017894",
260+
"order": 3,
261+
"name": "[JFRC2](VFB_00017894)",
262+
"tags": "Nervous_system|Adult",
263+
"thumbnail": "[![JFRC2](http://www.virtualflybrain.org/data/VFB/i/0001/7894/VFB_00017894/thumbnail.png 'JFRC2')](VFB_00017894)",
264+
"dataset": "[FlyLight - GMR GAL4 collection (Jenett2012)](Jenett2012)",
265+
"license": "[CC-BY-NC-SA](VFBlicense_CC_BY_NC_SA_4_0)"
266+
}
267+
],
268+
"count": 10
269+
}
270+
271+
# Update the results
272+
current_results[3] = new_instances
273+
current_results[4] = new_templates
274+
275+
# Write back to file
276+
import pprint
277+
with open('test_results.py', 'w') as f:
278+
f.write('results = ')
279+
f.write(pprint.pformat(current_results, width=120))
280+
f.write('\n')
281+
282+
print("Updated test_results.py with new instances and templates data.")

0 commit comments

Comments
 (0)