Skip to content

Commit 628f4ee

Browse files
committed
Update xrefs handling to use dictionary access and add existence check
1 parent 118727b commit 628f4ee

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

vfbterms.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,15 @@ def format_synonyms(term):
189189

190190
def format_xrefs(term):
191191
refs = []
192-
for xref in term.xrefs:
193-
# Check if xref is a string or dictionary
194-
if isinstance(xref, dict):
195-
icon = ' <i class="fa fa-external-link"></i>' if xref.get("site", {}).get("icon") == "link" else ''
196-
refs.append(f'- <a href="{xref["link_base"]}{xref["accession"]}" target="_blank">{xref["site"]["label"]}</a>{icon}')
197-
else:
198-
# Handle string xrefs or log them for debugging
199-
print(f"Unexpected xref format: {xref}")
192+
if "xrefs" in term: # Check if xrefs exists in the dictionary
193+
for xref in term["xrefs"]: # Access xrefs using dictionary notation
194+
# Check if xref is a string or dictionary
195+
if isinstance(xref, dict):
196+
icon = ' <i class="fa fa-external-link"></i>' if xref.get("site", {}).get("icon") == "link" else ''
197+
refs.append(f'- <a href="{xref["link_base"]}{xref["accession"]}" target="_blank">{xref["site"]["label"]}</a>{icon}')
198+
else:
199+
# Handle string xrefs or log them for debugging
200+
print(f"Unexpected xref format: {xref}")
200201
return '\n'.join(refs) if refs else 'None'
201202

202203
def format_references(term):

0 commit comments

Comments
 (0)