Skip to content

Commit df02f3a

Browse files
committed
term_info: restore relationship confidence and reference linkout dropped in the vfb.xmi migration
1 parent efb5094 commit df02f3a

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

src/vfbquery/term_info_queries.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ class MinimalEdgeInfo:
100100
iri: Optional[str] = ""
101101
label: Optional[str] = ""
102102
type: Optional[str] = ""
103+
# Edge-level enrichment carried in the vfb_json term_info (e.g. neurotransmitter
104+
# predictions): confidence_value is a decimal string ("0.84" -> 84%) and
105+
# database_cross_reference is a list of "SITE:accession" strings. These were
106+
# dropped when the term-info migrated off vfb.xmi; declare them so
107+
# dataclass_json stops discarding them and the relationship renderer can show
108+
# the confidence and reference linkout again.
109+
confidence_value: Optional[str] = ""
110+
database_cross_reference: Optional[List[str]] = None
103111

104112

105113
@dataclass_json

src/vfbquery/vfb_queries.py

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,35 @@ def _linkify_citations(text, pub_map, term_id="", field=""):
592592
return linked
593593

594594

595+
def format_edge_xrefs(dxrefs):
596+
"""Render a relationship edge's database_cross_reference list as markdown
597+
linkouts. Entries are 'SITE:accession' (e.g. 'FlyBase:FBrf0259490'); returns
598+
a leading-space parenthesised group so it can be appended to a relationship.
599+
"""
600+
if not dxrefs:
601+
return ""
602+
links = []
603+
for x in dxrefs:
604+
if not x:
605+
continue
606+
if ':' in x:
607+
site, acc = x.split(':', 1)
608+
s = site.lower()
609+
if s == 'flybase':
610+
links.append("[%s](http://flybase.org/reports/%s)" % (x, acc))
611+
elif s == 'doi':
612+
links.append("[%s](https://doi.org/%s)" % (x, acc))
613+
elif s in ('pmid', 'pubmed'):
614+
links.append("[%s](https://www.ncbi.nlm.nih.gov/pubmed/%s)" % (x, acc))
615+
else:
616+
links.append(x)
617+
else:
618+
links.append(x)
619+
if not links:
620+
return ""
621+
return " (" + ", ".join(links) + ")"
622+
623+
595624
def term_info_parse_object(results, short_form):
596625
termInfo = {}
597626
termInfo["SuperTypes"] = []
@@ -701,6 +730,9 @@ def term_info_parse_object(results, short_form):
701730

702731
# Group relationships by relation type and remove duplicates
703732
grouped_relationships = {}
733+
# Edge-level enriched relationships (confidence/reference) are rendered
734+
# individually and prepended, so their per-edge data survives grouping.
735+
enriched_relationships = []
704736
for relationship in vfbTerm.relationships:
705737
if hasattr(relationship.relation, 'short_form') and relationship.relation.short_form:
706738
relation_key = (relationship.relation.label, relationship.relation.short_form)
@@ -750,6 +782,30 @@ def term_info_parse_object(results, short_form):
750782
publication["refs"] = refs
751783
pubs_from_relationships.append(publication)
752784

785+
# Edge-level enrichment (confidence + reference), e.g. neuro-
786+
# transmitter predictions. Per-edge, so do NOT collapse into the
787+
# grouped/deduped relationships -- render each individually with
788+
# its confidence % and reference linkout, matching the pre-VFBquery
789+
# (vfb.xmi) term-info.
790+
cv = getattr(relationship.relation, 'confidence_value', '') or ''
791+
dx = getattr(relationship.relation, 'database_cross_reference', None) or []
792+
if cv or dx:
793+
conf = ''
794+
if cv:
795+
try:
796+
conf = str(int(round(float(cv) * 100))) + '% '
797+
except (ValueError, TypeError):
798+
conf = ''
799+
enriched_relationships.append(
800+
'%s[%s](%s): [%s](%s)%s' % (
801+
conf,
802+
encode_brackets(relation_key[0]), relation_key[1],
803+
encode_brackets(object_key[0]), object_key[1],
804+
format_edge_xrefs(dx),
805+
)
806+
)
807+
continue
808+
753809
if relation_key not in grouped_relationships:
754810
grouped_relationships[relation_key] = set()
755811
grouped_relationships[relation_key].add(object_key)
@@ -765,7 +821,9 @@ def term_info_parse_object(results, short_form):
765821
for object_key in sorted_object_set:
766822
relation_objects.append("[%s](%s)" % (encode_brackets(object_key[0]), object_key[1]))
767823
relationships.append("[%s](%s): %s" % (encode_brackets(relation_key[0]), relation_key[1], ', '.join(relation_objects)))
768-
termInfo["Meta"]["Relationships"] = "; ".join(relationships)
824+
# Enriched (confidence/reference) relationships first, then the plain
825+
# grouped ones -- so the NT confidence line leads, as it did before.
826+
termInfo["Meta"]["Relationships"] = "; ".join(enriched_relationships + relationships)
769827

770828
# New: Add relationship publications to main publications list
771829
if pubs_from_relationships:

0 commit comments

Comments
 (0)