Skip to content

Commit 0bfe186

Browse files
authored
Merge pull request #513 from iQuxLE/obojson_transform_tsv_enable_synonyms
hacky fix to let kgx transforrm obojson -> tsv || to enable synonym properties by default
2 parents b50f1c8 + b45e2a4 commit 0bfe186

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

kgx/cli/cli_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ def prepare_input_args(
993993
filename = args["filename"]
994994
if not filename.startswith(output_directory):
995995
o["args"] = os.path.join(output_directory, filename)
996+
996997
return input_args
997998

998999

@@ -1083,6 +1084,7 @@ def prepare_output_args(
10831084
output_args["property_types"] = source_property_types
10841085
else:
10851086
raise ValueError(f"type {output_format} not yet supported for output")
1087+
10861088
return output_args
10871089

10881090

kgx/sink/tsv_sink.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@
1212
)
1313

1414

15-
DEFAULT_NODE_COLUMNS = {"id", "name", "category", "description", "provided_by"}
15+
DEFAULT_NODE_COLUMNS = {
16+
"id",
17+
"name",
18+
"category",
19+
"description",
20+
"provided_by",
21+
"synonym",
22+
"exact_synonym",
23+
"related_synonym",
24+
"narrow_synonym",
25+
"broad_synonym"
26+
}
1627
DEFAULT_EDGE_COLUMNS = {
1728
"id",
1829
"subject",
@@ -166,7 +177,7 @@ def _order_node_columns(cols: Set) -> OrderedSet:
166177
"""
167178
node_columns = cols.copy()
168179
core_columns = OrderedSet(
169-
["id", "category", "name", "description", "xref", "provided_by", "synonym"]
180+
["id", "category", "name", "description", "xref", "provided_by", "synonym", "exact_synonym", "broad_synonym", "narrow_synonym", "related_synonym"]
170181
)
171182
ordered_columns = OrderedSet()
172183
for c in core_columns:

kgx/source/obograph_source.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,17 @@ def read_node(self, node: Dict) -> Optional[Tuple[str, Dict]]:
123123
if "synonym" in node_properties:
124124
fixed_node["synonym"] = node_properties["synonym"]
125125

126-
if "exact_synonyms" in node_properties:
127-
fixed_node["exact_synonyms"] = node_properties["exact_synonyms"]
126+
if "exact_synonym" in node_properties:
127+
fixed_node["exact_synonym"] = node_properties["exact_synonym"]
128128

129-
if "related_synonyms" in node_properties:
130-
fixed_node["related_synonyms"] = node_properties["related_synonyms"]
129+
if "related_synonym" in node_properties:
130+
fixed_node["related_synonym"] = node_properties["related_synonym"]
131131

132-
if "narrow_synonyms" in node_properties:
133-
fixed_node["narrow_synonyms"] = node_properties["narrow_synonyms"]
132+
if "narrow_synonym" in node_properties:
133+
fixed_node["narrow_synonym"] = node_properties["narrow_synonym"]
134134

135-
if "broad_synonyms" in node_properties:
136-
fixed_node["broad_synonyms"] = node_properties["broad_synonyms"]
135+
if "broad_synonym" in node_properties:
136+
fixed_node["broad_synonym"] = node_properties["broad_synonym"]
137137

138138
if "xrefs" in node_properties:
139139
fixed_node["xref"] = node_properties["xrefs"]
@@ -346,10 +346,10 @@ def parse_meta(self, node: str, meta: Dict) -> Dict:
346346
if "synonyms" in meta:
347347
# parse 'synonyms' as 'synonym'
348348
properties["synonym"] = [s["val"] for s in meta["synonyms"] if "val" in s]
349-
properties["exact_synonyms"] = [x['val'] for x in meta["synonyms"] if "pred" in x and x["pred"] == "hasExactSynonym" ]
350-
properties["related_synonyms"] = [x['val'] for x in meta["synonyms"] if "pred" in x and x["pred"] == "hasRelatedSynonym" ]
351-
properties["broad_synonyms"] = [x['val'] for x in meta["synonyms"] if "pred" in x and x["pred"] == "hasBroadSynonym" ]
352-
properties["narrow_synonyms"] = [x['val'] for x in meta["synonyms"] if "pred" in x and x["pred"] == "hasNarrowSynonym" ]
349+
properties["exact_synonym"] = [x['val'] for x in meta["synonyms"] if "pred" in x and x["pred"] == "hasExactSynonym" ]
350+
properties["related_synonym"] = [x['val'] for x in meta["synonyms"] if "pred" in x and x["pred"] == "hasRelatedSynonym" ]
351+
properties["broad_synonym"] = [x['val'] for x in meta["synonyms"] if "pred" in x and x["pred"] == "hasBroadSynonym" ]
352+
properties["narrow_synonym"] = [x['val'] for x in meta["synonyms"] if "pred" in x and x["pred"] == "hasNarrowSynonym" ]
353353

354354
if "xrefs" in meta:
355355
# parse 'xrefs' as 'xrefs'

kgx/utils/rdf_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
"predicate": False,
3737
"description": False,
3838
"synonym": True,
39+
"exact_synonym": True,
40+
"narrow_synonym": True,
41+
"relation_synonym": True,
42+
"broad_synonym": True,
3943
"in_taxon": False,
4044
"same_as": True,
4145
"name": False,

tests/unit/test_source/test_obograph_source.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def test_read_obograph1():
4444
assert "plasmid binding" in n1["synonym"]
4545

4646
# related and narrow synonym
47-
assert n1["related_synonyms"] == ['structure-specific DNA binding','structure specific DNA binding','microtubule/chromatin interaction']
48-
assert n1["narrow_synonyms"] == ['plasmid binding']
47+
assert n1["related_synonym"] == ['structure-specific DNA binding','structure specific DNA binding','microtubule/chromatin interaction']
48+
assert n1["narrow_synonym"] == ['plasmid binding']
4949

5050
n2 = nodes["GO:0005575"]
5151
assert n2["id"] == "GO:0005575"
@@ -61,11 +61,11 @@ def test_read_obograph1():
6161

6262
# just for exact synonym
6363
n3 = nodes["GO:0005975"]
64-
assert n3["exact_synonyms"] == ['carbohydrate metabolism']
64+
assert n3["exact_synonym"] == ['carbohydrate metabolism']
6565

6666
# brad_synonym
6767
n5 = nodes["GO:0003924"]
68-
assert n5['broad_synonyms'][0].startswith('hydrolase activity')
68+
assert n5['broad_synonym'][0].startswith('hydrolase activity')
6969

7070

7171
def test_read_jsonl2():

0 commit comments

Comments
 (0)