Skip to content

Commit

Permalink
Refact (#2)
Browse files Browse the repository at this point in the history
* update dependencies

* updates for pylint

* rearrange imports and remove field name

* update repository link

* refact argument parser

* downgrade python version

* update test files

---------

Co-authored-by: Anita Caron <[email protected]>
  • Loading branch information
Anita Caron and anitacaron authored Jan 12, 2024
1 parent 6d1ea52 commit 3738195
Show file tree
Hide file tree
Showing 8 changed files with 4,935 additions and 29 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ description = "This package validates a list of relationships between two terms
authors = ["Anita Caron <[email protected]>"]
readme = "README.md"
packages = [{include = "relation_validator", from="src"}]
repository = "https://github.com/anitacaron/relation-validator"
repository = "https://github.com/INCATools/relation-validator"

[tool.poetry.dependencies]
python = "^3.9"
python = "^3.8"
pyaml = "^21.10.1"
ruamel-yaml = "^0.17.21"
oaklib = "^0.5.20"
Expand Down
17 changes: 7 additions & 10 deletions src/relation_validator/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
"""
Command-line application for the lib
"""
import argparse
import pathlib

Expand All @@ -7,8 +10,7 @@
def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(
help='Available dosdp actions',
dest='action'
help="Available relation-validator actions",
)

parser_validate = subparsers.add_parser(
Expand All @@ -19,19 +21,18 @@ def main():
parser_validate.add_argument(
"-i",
"--input",
action="store",
type=pathlib.Path,
required=True,
help="yaml file with config"
)
parser_validate.add_argument(
"-o",
"--output",
action="store",
type=pathlib.Path,
required=True,
help="csv output filename"
)
parser_validate.set_defaults(func=validate)

parser_ont_versions = subparsers.add_parser(
name="ontologies_version",
Expand All @@ -41,18 +42,14 @@ def main():
parser_ont_versions.add_argument(
"-o",
"--output",
action="store",
type=pathlib.Path,
required=True,
help="json output filename"
)
parser_ont_versions.set_defaults(func=ontologies_version)

args = parser.parse_args()

if args.action == "validate":
validate(str(args.input), str(args.output))
elif args.action == "ontologies_version":
ontologies_version(args.output)
args.func(args)


if __name__ == "__main__":
Expand Down
24 changes: 13 additions & 11 deletions src/relation_validator/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{pairs}
}}
?subject {property} ?object .
# LIMIT
"""


Expand Down Expand Up @@ -115,18 +116,18 @@ def get_config(entry) -> dict:
"""
Parse config file
"""
if entry.endswith('.yaml') or entry.endswith('.yml'):
config = os.path.abspath(entry)
ryaml = YAML(typ='safe')
with open(config, "r", encoding="utf-8") as f:
try:
config = ryaml.load(f)
except YAMLError:
logging.info("Failed to load config: %s", config)
return config
if entry.suffix not in (".yaml" or ".yml"):
logging.error("Given path has unsupported file extension.")
return {}

logging.error("Given path has unsupported file extension.")
return False
config = os.path.abspath(entry)
ryaml = YAML(typ="safe")
with open(config, "r", encoding="utf-8") as f:
try:
config = ryaml.load(f)
except YAMLError:
logging.info("Failed to load config: %s", config)
return config


def get_prefixes(text, prefix_map):
Expand All @@ -148,6 +149,7 @@ def get_ontologies_version():
QUERY_VERSION = """
?ontology a owl:Ontology .
OPTIONAL { ?ontology owl:versionIRI ?version . }
# LIMIT
"""

response = query_ubergraph(QUERY_VERSION)
Expand Down
13 changes: 8 additions & 5 deletions src/relation_validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
split_terms, verify_relationship)


def validate(config, filename):
def validate(args):
"""
Validate process
"""
config = get_config(config)
config = get_config(args.input)
if not config:
return exit

data = pd.read_csv(config["filename"])
terms_pairs = get_pairs(data)

Expand All @@ -23,13 +26,13 @@ def validate(config, filename):
data[["s", "o"]].apply(tuple, 1).isin(zip(terms_s, terms_o))
]

rows_nv.to_csv(filename, index=False)
rows_nv.to_csv(args.output, index=False)


def ontologies_version(filename):
def ontologies_version(args):
"""
Get ontologies' version
"""
ont_version = get_ontologies_version()
with open(filename, 'w', encoding='utf-8') as f:
with open(args.output, "w", encoding="utf-8") as f:
json.dump(ont_version, f, ensure_ascii=False, indent=2)
2,393 changes: 2,393 additions & 0 deletions tests/ref-organ-relations.csv

Large diffs are not rendered by default.

233 changes: 233 additions & 0 deletions tests/test-ont-versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,233 @@
[
{
"ontology": "aism/aism-base.owl",
"version": "aism/releases/2023-04-14/aism-base.owl"
},
{
"ontology": "bspo.owl",
"version": "bspo/releases/2023-05-27/bspo.owl"
},
{
"ontology": "cl/cl-base.owl",
"version": "cl/releases/2024-01-04/cl-base.owl"
},
{
"ontology": "cob/cob-base.owl",
"version": "cob/releases/2023-05-12/cob-base.owl"
},
{
"ontology": "cob/components/cob-to-external.owl",
"version": "cob/releases/2023-05-12/components/cob-to-external.owl"
},
{
"ontology": "colao/colao-base.owl",
"version": "colao/releases/2023-04-08/colao-base.owl"
},
{
"ontology": "dpo/dpo-base.owl",
"version": "dpo/releases/2023-12-08/dpo-base.owl"
},
{
"ontology": "eco/eco-base.owl",
"version": "eco/releases/2023-09-03/eco-base.owl"
},
{
"ontology": "iao.owl",
"version": "iao/2022-11-07/iao.owl"
},
{
"ontology": "ecto/ecto-base.owl",
"version": "ecto/releases/2023-02-14/ecto-base.owl"
},
{
"ontology": "emapa.owl",
"version": "emapa/releases/2023-11-14/emapa.owl"
},
{
"ontology": "envo/envo-base.owl",
"version": "envo/releases/2023-02-13/envo-base.owl"
},
{
"ontology": "fbbt/fbbt-base.owl",
"version": "fbbt/releases/2023-12-07/fbbt-base.owl"
},
{
"ontology": "fbcv/fbcv-base.owl",
"version": "fbcv/releases/2023-12-08/fbcv-base.owl"
},
{
"ontology": "fbdv/fbdv-base.owl",
"version": "fbdv/releases/2023-12-07/fbdv-base.owl"
},
{
"ontology": "fypo/fypo-base.owl",
"version": "fypo/releases/2023-12-29/fypo-base.owl"
},
{
"ontology": "go/extensions/go-bfo-bridge.owl"
},
{
"ontology": "go/go-base.owl",
"version": "go/releases/2023-11-15/go-base.owl"
},
{
"ontology": "hp/hp-base.owl",
"version": "hp/releases/2023-10-09/hp-base.owl"
},
{
"ontology": "lepao/lepao-base.owl",
"version": "lepao/releases/2023-02-18/lepao-base.owl"
},
{
"ontology": "ma.owl",
"version": "ma/releases/2017-02-07/ma.owl"
},
{
"ontology": "maxo/maxo-base.owl",
"version": "maxo/releases/2023-12-01/maxo-base.owl"
},
{
"ontology": "mi.owl"
},
{
"ontology": "mmo.owl",
"version": "mmo/2.123/mmo.owl"
},
{
"ontology": "mondo/mondo-base.owl",
"version": "mondo/releases/2024-01-03/mondo-base.owl"
},
{
"ontology": "ncbitaxon.owl",
"version": "ncbitaxon/2023-12-12/ncbitaxon.owl"
},
{
"ontology": "ncit.owl",
"version": "ncit/releases/2023-10-19/ncit.owl"
},
{
"ontology": "mp/mp-base.owl",
"version": "mp/releases/2023-12-19/mp-base.owl"
},
{
"ontology": "nbo/nbo-base.owl",
"version": "nbo/releases/2023-07-04/nbo-base.owl"
},
{
"ontology": "oba/oba-base.owl",
"version": "oba/releases/2023-12-07/oba-base.owl"
},
{
"ontology": "obi/obi-base.owl",
"version": "obi/2023-09-20/obi-base.owl"
},
{
"ontology": "pato/pato-base.owl",
"version": "pato/releases/2023-05-18/pato-base.owl"
},
{
"ontology": "pcl/pcl-base.owl",
"version": "pcl/releases/2024-01-04/pcl-base.owl"
},
{
"ontology": "pco/pco-base.owl",
"version": "pco/releases/2021-05-03/pco-base.owl"
},
{
"ontology": "ro/ro-base.owl",
"version": "ro/releases/2023-08-18/ro-base.owl"
},
{
"ontology": "so.owl",
"version": "so/2021-11-22/so.owl"
},
{
"ontology": "uberon/bridge/cl-bridge-to-caro.owl",
"version": "uberon/releases/2023-12-08/bridge/cl-bridge-to-caro.owl"
},
{
"ontology": "uberon/bridge/cl-bridge-to-fbbt.owl",
"version": "uberon/releases/2023-12-08/bridge/cl-bridge-to-fbbt.owl"
},
{
"ontology": "uberon/bridge/uberon-bridge-to-caro.owl",
"version": "uberon/releases/2023-12-08/bridge/uberon-bridge-to-caro.owl"
},
{
"ontology": "uberon/bridge/uberon-bridge-to-fbbt.owl",
"version": "uberon/releases/2023-12-08/bridge/uberon-bridge-to-fbbt.owl"
},
{
"ontology": "uberon/uberon-base.owl",
"version": "uberon/releases/2023-12-08/uberon-base.owl"
},
{
"ontology": "wbbt/wbbt-base.owl",
"version": "wbbt/releases/2024-01-04/wbbt-base.owl"
},
{
"ontology": "wbls/wbls-base.owl",
"version": "wbls/releases/2023-09-26/wbls-base.owl"
},
{
"ontology": "wbphenotype/wbphenotype-base.owl",
"version": "wbphenotype/releases/2023-09-26/wbphenotype-base.owl"
},
{
"ontology": "zfa/zfa-base.owl",
"version": "zfa/releases/2022-12-09/zfa-base.owl"
},
{
"ontology": "https://w3id.org/orcidio/orcidio.owl"
},
{
"ontology": "pr/pr-asserted.owl",
"version": "pr/68.0/pr-asserted.owl"
},
{
"ontology": "po.owl",
"version": "po/releases/2023-07-13/po.owl"
},
{
"ontology": "https://raw.githubusercontent.com/PlantPhenoOntology/ppo/master/ppo.owl",
"version": "https://raw.githubusercontent.com/PlantPhenoOntology/ppo/master/releases/2018-10-26/ppo.owl"
},
{
"ontology": "apo.owl",
"version": "apo/releases/2023-12-07/apo.owl"
},
{
"ontology": "mmusdv.owl"
},
{
"ontology": "foodon.owl",
"version": "foodon/releases/2023-05-03/foodon.owl"
},
{
"ontology": "to.owl",
"version": "to/releases/2023-07-17/to.owl"
},
{
"ontology": "peco.owl",
"version": "peco/releases/2023-11-10/peco.owl"
},
{
"ontology": "mro.owl",
"version": "mro/2023-12-21/mro.owl"
},
{
"ontology": "hao.owl",
"version": "hao/2023-06-01/hao.owl"
},
{
"ontology": "clao.owl",
"version": "clao/releases/2021-09-27/clao.owl"
},
{
"ontology": "oarcs.owl",
"version": "hao/2019-04-18/hao.owl"
},
{
"ontology": "http://translator.renci.org/ubergraph-axioms.ofn"
}
]
2 changes: 1 addition & 1 deletion tests/test-parser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ relationships:
connected_to: RO:0001025
has_soma_location: RO:0002100

filename: tests/review_file.csv
filename: tests/ref-organ-relations.csv
Loading

0 comments on commit 3738195

Please sign in to comment.