Skip to content

Commit bd5dc24

Browse files
Copilottanghaibao
andcommitted
Address code review nitpicks: improve code clarity and efficiency
Co-authored-by: tanghaibao <[email protected]>
1 parent c8eab3c commit bd5dc24

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

docs/descendants_with_relationships_example.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,19 @@
5050
print("-" * 70)
5151

5252
# Get descendants for ALL GO terms in the DAG
53+
# Extract godag.values() once for efficiency
54+
goterms = godag.values()
5355

5456
# Option A: is_a only
55-
go2descendants_isa = get_go2descendants(godag.values(), relationships=None)
57+
go2descendants_isa = get_go2descendants(goterms, relationships=None)
5658
print(f" is_a only: {sorted(go2descendants_isa.get(GO_ID, set()))}")
5759

5860
# Option B: is_a + ALL relationships
59-
go2descendants_all = get_go2descendants(godag.values(), relationships=True)
61+
go2descendants_all = get_go2descendants(goterms, relationships=True)
6062
print(f" is_a + all relations: {sorted(go2descendants_all.get(GO_ID, set()))}")
6163

6264
# Option C: is_a + SELECTED relationships (e.g., only part_of)
63-
go2descendants_partof = get_go2descendants(godag.values(), relationships={'part_of'})
65+
go2descendants_partof = get_go2descendants(goterms, relationships={'part_of'})
6466
print(f" is_a + part_of only: {sorted(go2descendants_partof.get(GO_ID, set()))}")
6567

6668
# ============================================================================

notebooks/children_and_descendants.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,10 @@
8989
"source": [
9090
"from goatools.godag.go_tasks import get_go2children\n",
9191
"\n",
92-
"optional_relationships = {'part_of'}\n",
92+
"optional_relationships = {\"part_of\"}\n",
93+
"# Note: GODag inherits from dict, so we pass godag directly\n",
9394
"go2children_partof = get_go2children(godag, optional_relationships)\n",
94-
"print('{GO} children (is_a + part_of): {C}'.format(\n",
95+
"print(\"{GO} children (is_a + part_of): {C}\".format(\n",
9596
" GO=GO_ID,\n",
9697
" C=go2children_partof.get(GO_ID, set())))"
9798
]

0 commit comments

Comments
 (0)