Skip to content

Commit 347e3fb

Browse files
committed
Add Technique field to TermInfoOutputSchema and update term_info_parse_object logic
1 parent 6f302fb commit 347e3fb

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

src/test/test_examples_diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def main():
173173
failed = True
174174
continue
175175

176-
expected_keys = ['IsIndividual', 'IsClass', 'Images', 'Examples', 'Domains', 'Licenses', 'Publications', 'Synonyms']
176+
expected_keys = ['IsIndividual', 'IsClass', 'Images', 'Examples', 'Domains', 'Licenses', 'Publications', 'Synonyms', 'Technique']
177177
for key in expected_keys:
178178
if key not in result:
179179
print(f'{Fore.RED}Missing key: {key}{Style.RESET_ALL}')

src/vfbquery/vfb_queries.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ class TermInfoOutputSchema(Schema):
302302
Licenses = fields.Dict(keys=fields.Integer(), values=fields.Nested(LicenseSchema()), required=False, allow_none=True)
303303
Publications = fields.List(fields.Dict(keys=fields.String(), values=fields.Field()), required=False)
304304
Synonyms = fields.List(fields.Dict(keys=fields.String(), values=fields.Field()), required=False, allow_none=True)
305+
Technique = fields.List(fields.String(), required=False, allow_none=True)
305306

306307
@post_load
307308
def make_term_info(self, data, **kwargs):
@@ -409,6 +410,7 @@ def term_info_parse_object(results, short_form):
409410
termInfo["Licenses"] = {}
410411
termInfo["Publications"] = []
411412
termInfo["IsPaintedDomain"] = False
413+
termInfo["Technique"] = []
412414

413415
if results.hits > 0 and results.docs and len(results.docs) > 0:
414416
termInfo["Meta"] = {}
@@ -467,6 +469,7 @@ def term_info_parse_object(results, short_form):
467469
if hasattr(vfbTerm, 'relationships') and vfbTerm.relationships and len(vfbTerm.relationships) > 0:
468470
relationships = []
469471
pubs_from_relationships = [] # New: Collect publication references from relationships
472+
techniques = set() # Collect imaging techniques from relationships
470473

471474
# Group relationships by relation type and remove duplicates
472475
grouped_relationships = {}
@@ -487,6 +490,17 @@ def term_info_parse_object(results, short_form):
487490

488491
object_key = (relationship.object.label, getattr(relationship.object, 'short_form', ''))
489492

493+
# Collect imaging techniques from relationships
494+
relation_id = None
495+
if hasattr(relationship.relation, 'short_form') and relationship.relation.short_form:
496+
relation_id = relationship.relation.short_form
497+
elif hasattr(relationship.relation, 'iri') and relationship.relation.iri:
498+
relation_id = relationship.relation.iri.split('/')[-1]
499+
500+
if relation_id == 'OBI_0000312': # is_specified_output_of
501+
if hasattr(relationship.object, 'label') and relationship.object.label:
502+
techniques.add(relationship.object.label)
503+
490504
# New: Extract publications from this relationship if they exist
491505
if hasattr(relationship, 'pubs') and relationship.pubs:
492506
for pub in relationship.pubs:
@@ -537,15 +551,24 @@ def term_info_parse_object(results, short_form):
537551
termInfo["Publications"].append(pub)
538552
existing_pub_short_forms.add(pub.get("short_form", ""))
539553

554+
# Add techniques from relationships to termInfo for Individuals
555+
if termInfo["IsIndividual"] and techniques:
556+
termInfo["Technique"].extend(techniques)
557+
termInfo["Technique"] = sorted(list(set(termInfo["Technique"])))
558+
540559
# If the term has anatomy channel images, retrieve the images and associated information
541560
if vfbTerm.anatomy_channel_image and len(vfbTerm.anatomy_channel_image) > 0:
542561
images = {}
562+
techniques = set()
543563
for image in vfbTerm.anatomy_channel_image:
544564
# Check if this is a computer graphic image (painted domain)
545-
if hasattr(image, 'channel_image') and hasattr(image.channel_image, 'image') and hasattr(image.channel_image.image, 'imaging_technique'):
546-
technique = image.channel_image.image.imaging_technique
565+
if hasattr(image, 'channel_image') and hasattr(image.channel_image, 'imaging_technique'):
566+
technique = image.channel_image.imaging_technique
547567
if hasattr(technique, 'symbol') and technique.symbol and 'computer' in technique.symbol.lower():
548568
termInfo["IsPaintedDomain"] = True
569+
# Collect technique for Individual terms
570+
if hasattr(technique, 'label') and technique.label:
571+
techniques.add(technique.label)
549572

550573
record = {}
551574
record["id"] = image.anatomy.short_form
@@ -567,19 +590,27 @@ def term_info_parse_object(results, short_form):
567590
images[template_key] = sorted(images[template_key], key=lambda x: x["id"], reverse=True)
568591

569592
termInfo["Examples"] = images
593+
# Add techniques to termInfo for Individuals
594+
if termInfo["IsIndividual"] and techniques:
595+
termInfo["Technique"].extend(techniques)
596+
termInfo["Technique"] = sorted(list(set(termInfo["Technique"])))
570597
# add a query to `queries` list for listing all available images
571598
q = ListAllAvailableImages_to_schema(termInfo["Name"], {"short_form":vfbTerm.term.core.short_form})
572599
queries.append(q)
573600

574601
# If the term has channel images but not anatomy channel images, create thumbnails from channel images.
575602
if vfbTerm.channel_image and len(vfbTerm.channel_image) > 0:
576603
images = {}
604+
techniques = set()
577605
for image in vfbTerm.channel_image:
578606
# Check if this is a computer graphic image (painted domain)
579-
if hasattr(image, 'image') and hasattr(image.image, 'imaging_technique'):
580-
technique = image.image.imaging_technique
607+
if hasattr(image, 'imaging_technique'):
608+
technique = image.imaging_technique
581609
if hasattr(technique, 'symbol') and technique.symbol and 'computer' in technique.symbol.lower():
582610
termInfo["IsPaintedDomain"] = True
611+
# Collect technique for Individual terms
612+
if hasattr(technique, 'label') and technique.label:
613+
techniques.add(technique.label)
583614

584615
record = {}
585616
record["id"] = vfbTerm.term.core.short_form
@@ -602,6 +633,10 @@ def term_info_parse_object(results, short_form):
602633

603634
# Add the thumbnails to the term info
604635
termInfo["Images"] = images
636+
# Add techniques to termInfo for Individuals
637+
if termInfo["IsIndividual"] and techniques:
638+
termInfo["Technique"].extend(techniques)
639+
termInfo["Technique"] = sorted(list(set(termInfo["Technique"])))
605640

606641
if vfbTerm.dataset_license and len(vfbTerm.dataset_license) > 0:
607642
licenses = {}
@@ -901,20 +936,20 @@ def term_info_parse_object(results, short_form):
901936
queries.append(q)
902937

903938
# For individuals that are painted domains of anatomical regions, add parent class queries
904-
if termInfo["IsIndividual"] and termInfo["IsPaintedDomain"]:
939+
if termInfo["IsIndividual"] and termInfo["Technique"] and any('computer' in t.lower() for t in termInfo["Technique"]):
905940
anatomical_classes = []
906941

907942
# Check parents
908943
if vfbTerm.parents:
909944
for parent in vfbTerm.parents:
910-
if parent.types and "Class" in parent.types:
945+
if parent.types and "Class" in parent.types and "Anatomy" in parent.types:
911946
anatomical_classes.append(parent)
912947

913948
# Check relationships for anatomical classes
914949
if vfbTerm.relationships:
915950
for rel in vfbTerm.relationships:
916951
if hasattr(rel, 'object') and rel.object and hasattr(rel.object, 'types') and rel.object.types:
917-
if "Class" in rel.object.types:
952+
if "Class" in rel.object.types and "Anatomy" in rel.object.types:
918953
anatomical_classes.append(rel.object)
919954

920955
# Remove duplicates based on short_form

0 commit comments

Comments
 (0)