Skip to content

Commit 02cab5f

Browse files
committed
Adding term build tests
1 parent f3d0a8f commit 02cab5f

File tree

3 files changed

+224
-60
lines changed

3 files changed

+224
-60
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Test VFB Terms Generation
2+
3+
on:
4+
push:
5+
paths:
6+
- 'vfbterms.py'
7+
- '.github/workflows/test_vfbterms.yml'
8+
pull_request:
9+
paths:
10+
- 'vfbterms.py'
11+
- '.github/workflows/test_vfbterms.yml'
12+
workflow_dispatch:
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v4
22+
with:
23+
python-version: '3.9'
24+
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install vfb-connect pandas
29+
30+
- name: Run medulla test
31+
run: |
32+
python3 vfbterms.py
33+
34+
- name: Archive test results
35+
if: always()
36+
uses: actions/upload-artifact@v3
37+
with:
38+
name: test-results
39+
path: |
40+
FBbt_00003748_v*.md
41+
retention-days: 7

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
public/*
22
.DS_Store
3+
/.venv

vfbterms.py

Lines changed: 182 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
#!/usr/bin/env python3
2+
13
import sys
24
from os import listdir, chdir
35
from os.path import isfile, join
6+
import os
7+
import warnings
8+
9+
# Suppress the urllib3 warning about OpenSSL
10+
warnings.filterwarnings('ignore', category=Warning)
11+
12+
# Set environment variable to skip GUI dependencies
13+
os.environ['VFB_SKIP_GUI'] = '1'
14+
415
from vfb_connect.cross_server_tools import VfbConnect
516
import re
617

@@ -296,72 +307,183 @@ def wrapStringInHTMLMac(term):
296307
print(whole)
297308
f.close()
298309

299-
mypath = sys.argv[1]
300-
print("Updating all files in " + mypath)
301-
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
302-
303-
chdir(mypath + 'fbbt/')
304-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'FBbt' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
305-
chdir(mypath + 'fbbi/')
306-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'FBbi' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
307-
chdir(mypath + 'fbcv/')
308-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'FBcv' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
309-
chdir(mypath + 'fbdv/')
310-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'FBdv' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
311-
chdir(mypath + 'vfb/')
312-
vfb = vc.nc.commit_list(["MATCH (n:Individual) WHERE n.short_form starts with 'VFB_' AND NOT n.short_form starts with 'VFB_internal' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0]
313-
save_terms(vfb)
314-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'VFBexp_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
315-
316-
# TODO: replace once VFBconnect pub queries added
317-
#save_terms(vc.nc.commit_list(["MATCH (n:pub) with n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
318-
319-
chdir(mypath + '../datasets/')
320-
321-
save_terms(vc.nc.commit_list(["MATCH (n:DataSet) with n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
322-
323-
chdir(mypath + 'go/')
324-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'GO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
325-
326-
chdir(mypath + 'so/')
327-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'SO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
328-
329-
chdir(mypath + 'ioa/')
330-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'IAO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
331-
332-
chdir(mypath + 'geno/')
333-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'GENO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
334-
335-
chdir(mypath + 'pato/')
336-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'PATO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
337-
338-
chdir(mypath + 'pco/')
339-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'PCO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
340-
341-
chdir(mypath + 'uberon/')
342-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'UBERON_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
310+
def test_medulla_page():
311+
"""Test full term page creation for medulla using actual VFB connection"""
312+
expected_content = """---
313+
title: "medulla [FBbt_00003748]"
314+
linkTitle: "medulla"
315+
tags: [Entity,Adult,Anatomy,Class,Nervous_system,Synaptic_neuropil,Synaptic_neuropil_domain,FBbt]
316+
content: [term]
317+
date: {current_date}
318+
images: []
319+
description: >
320+
The second optic neuropil, sandwiched between the lamina and the lobula complex. It is divided into 10 layers: 1-6 make up the outer (distal) medulla, the seventh (or serpentine) layer exhibits a distinct architecture and layers 8-10 make up the inner (proximal) medulla (Ito et al., 2014).
321+
weight: 10000
322+
sitemap_exclude: true
323+
canonicalUrl: "https://www.virtualflybrain.org/term/medulla-fbbt_00003748/"
324+
---
343325
344-
chdir(mypath + 'ro/')
345-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'RO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
326+
{note}
346327
347-
chdir(mypath + 'obi/')
348-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'OBI_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
328+
[Open **medulla** in **VFB**](https://v2.virtualflybrain.org/org.geppetto.frontend/geppetto?id=FBbt_00003748)
349329
350-
chdir(mypath + 'ncbitaxon/')
351-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'NCBITaxon_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
330+
## Term Information
352331
353-
chdir(mypath + 'zp/')
354-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'ZP_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
332+
- **ID**: FBbt_00003748
333+
- **Name**: medulla
334+
- **Definition**: The second optic neuropil, sandwiched between the lamina and the lobula complex. It is divided into 10 layers: 1-6 make up the outer (distal) medulla, the seventh (or serpentine) layer exhibits a distinct architecture and layers 8-10 make up the inner (proximal) medulla (Ito et al., 2014).
335+
- **Type**: Entity, Adult, Anatomy, Class, Nervous_system, Synaptic_neuropil, Synaptic_neuropil_domain
355336
356-
chdir(mypath + 'wbphenotype/')
357-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'WBPhenotype_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
337+
## Classification
338+
- [synaptic neuropil domain](https://www.virtualflybrain.org/term/synaptic-neuropil-domain-fbbt_00040007) <span class="label types"><span class="label label-Synaptic_neuropil">Synaptic neuropil</span> <span class="label label-Nervous_system">Nervous system</span></span>
358339
359-
chdir(mypath + 'caro/')
360-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'CARO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
340+
## Relationships
341+
- develops from [medulla anlage](https://www.virtualflybrain.org/term/medulla-anlage-fbbt_00001935) <span class="label types"><span class="label label-Nervous_system">Nervous system</span> <span class="label label-Larva">Larva</span></span>
361342
362-
chdir(mypath + 'bfo/')
363-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'BFO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
343+
## Cross References
344+
- [![Insect Brain DB](https://insectbraindb.org/app/assets/images/Megalopta_frontal.png) Insect Brain DB](https://insectbraindb.org/app/structures/38)
345+
- [medulla on Insect Brain DB](https://insectbraindb.org/app/structures/38)"""
364346

365-
chdir(mypath + 'flybase/')
366-
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'FB' AND NOT n.short_form contains '_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
347+
# Get actual medulla data
348+
print("Fetching medulla data from VFB...")
349+
terms = vc.neo_query_wrapper.get_TermInfo(["FBbt_00003748"])
350+
351+
if terms.empty:
352+
print("ERROR: Could not fetch medulla data")
353+
return False
354+
355+
# Generate actual content
356+
print("Generating medulla page...")
357+
import tempfile
358+
import os
359+
360+
# Create temporary directory for test
361+
with tempfile.TemporaryDirectory() as tmpdir:
362+
os.chdir(tmpdir)
363+
364+
# Process the term
365+
for _, row in terms.iterrows():
366+
term_data = {
367+
"term": {
368+
"core": {
369+
"short_form": row.get("short_form", ""),
370+
"label": row.get("label", ""),
371+
"types": row.get("types", []),
372+
"iri": row.get("iri", ""),
373+
"symbol": row.get("symbol", "")
374+
},
375+
"description": [row.get("description", "")],
376+
"comment": [row.get("comment", "")]
377+
},
378+
"parents": row.get("parents", []),
379+
"relationships": row.get("relationships", []),
380+
"xrefs": row.get("xrefs", []),
381+
"pub_syn": row.get("pub_syn", []),
382+
"def_pubs": row.get("def_pubs", [])
383+
}
384+
wrapStringInHTMLMac(term_data)
385+
386+
# Read generated file
387+
filename = f"FBbt_00003748_v{version}.md"
388+
if os.path.exists(filename):
389+
with open(filename, 'r') as f:
390+
actual_content = f.read()
391+
392+
# Compare content (ignoring date which will change)
393+
import datetime
394+
expected_with_date = expected_content.format(
395+
current_date=datetime.datetime.today().strftime("%Y-%m-%d"),
396+
note=note
397+
)
398+
399+
if actual_content.strip() == expected_with_date.strip():
400+
print("✓ Test passed: Generated content matches expected")
401+
return True
402+
else:
403+
print("✗ Test failed: Content mismatch")
404+
print("\nExpected content:")
405+
print(expected_with_date)
406+
print("\nActual content:")
407+
print(actual_content)
408+
return False
409+
else:
410+
print(f"✗ Test failed: File {filename} was not created")
411+
return False
412+
413+
if __name__ == "__main__":
414+
if len(sys.argv) > 1:
415+
mypath = sys.argv[1]
416+
print("Updating all files in " + mypath)
417+
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
418+
419+
chdir(mypath + 'fbbt/')
420+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'FBbt' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
421+
chdir(mypath + 'fbbi/')
422+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'FBbi' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
423+
chdir(mypath + 'fbcv/')
424+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'FBcv' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
425+
chdir(mypath + 'fbdv/')
426+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'FBdv' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
427+
chdir(mypath + 'vfb/')
428+
vfb = vc.nc.commit_list(["MATCH (n:Individual) WHERE n.short_form starts with 'VFB_' AND NOT n.short_form starts with 'VFB_internal' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0]
429+
save_terms(vfb)
430+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'VFBexp_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
431+
432+
# TODO: replace once VFBconnect pub queries added
433+
#save_terms(vc.nc.commit_list(["MATCH (n:pub) with n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
434+
435+
chdir(mypath + '../datasets/')
436+
437+
save_terms(vc.nc.commit_list(["MATCH (n:DataSet) with n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
438+
439+
chdir(mypath + 'go/')
440+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'GO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
441+
442+
chdir(mypath + 'so/')
443+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'SO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
444+
445+
chdir(mypath + 'ioa/')
446+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'IAO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
447+
448+
chdir(mypath + 'geno/')
449+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'GENO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
450+
451+
chdir(mypath + 'pato/')
452+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'PATO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
453+
454+
chdir(mypath + 'pco/')
455+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'PCO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
456+
457+
chdir(mypath + 'uberon/')
458+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'UBERON_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
459+
460+
chdir(mypath + 'ro/')
461+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'RO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
462+
463+
chdir(mypath + 'obi/')
464+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'OBI_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
465+
466+
chdir(mypath + 'ncbitaxon/')
467+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'NCBITaxon_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
468+
469+
chdir(mypath + 'zp/')
470+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'ZP_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
471+
472+
chdir(mypath + 'wbphenotype/')
473+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'WBPhenotype_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
474+
475+
chdir(mypath + 'caro/')
476+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'CARO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
477+
478+
chdir(mypath + 'bfo/')
479+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'BFO_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
480+
481+
chdir(mypath + 'flybase/')
482+
save_terms(vc.nc.commit_list(["MATCH (n:Class) WHERE n.short_form starts with 'FB' AND NOT n.short_form contains '_' WITH n.short_form as id ORDER BY id ASC RETURN collect(distinct id) as ids"])[0]['data'][0]['row'][0])
483+
484+
else:
485+
print("Testing medulla page generation...")
486+
success = test_medulla_page()
487+
if not success:
488+
sys.exit(1)
367489

0 commit comments

Comments
 (0)