This repository was archived by the owner on Jul 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Create lexmatch using oaklib
#44
Open
hrshdhgd
wants to merge
8
commits into
master
Choose a base branch
from
issue-43
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9dc0f14
Update .gitignore
hrshdhgd b9c6bbd
code for oaklib
hrshdhgd 1f7b3db
updated gitignore
hrshdhgd 02a1533
Update src/ontology/metadata/upheno.sssom.config.yml
hrshdhgd c09e27f
Update src/ontology/metadata/upheno.sssom.config.yml
hrshdhgd 6c0f665
Update src/ontology/metadata/upheno.sssom.config.yml
hrshdhgd bac28e1
Update src/ontology/metadata/upheno.sssom.config.yml
hrshdhgd ac3dd75
chnaged mappings location based on comment
hrshdhgd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| rules: | ||
| - description: default | ||
| postconditions: | ||
| predicate_id: skos:closeMatch | ||
| weight: 0.0 | ||
|
|
||
| - description: exact to exact | ||
| preconditions: | ||
| subject_match_field_one_of: | ||
| - oio:hasExactSynonym | ||
| - rdfs:label | ||
| - skos:prefLabel | ||
| object_match_field_one_of: | ||
| - oio:hasExactSynonym | ||
| - rdfs:label | ||
| - skos:prefLabel | ||
| postconditions: | ||
| predicate_id: skos:exactMatch | ||
| weight: 2.0 | ||
|
|
||
| - description: >- | ||
| label to label; note this is additive with the exact to exact rule, | ||
| so the score just represents an additional small boost | ||
| preconditions: | ||
| subject_match_field_one_of: | ||
| - rdfs:label | ||
| object_match_field_one_of: | ||
| - rdfs:label | ||
| postconditions: | ||
| predicate_id: skos:exactMatch | ||
| weight: 0.5 | ||
|
|
||
| - description: xref match | ||
| preconditions: | ||
| subject_match_field_one_of: | ||
| - oio:hasDbXref | ||
| - skos:exactMatch | ||
| object_match_field_one_of: | ||
| - oio:hasDbXref | ||
| - skos:exactMatch | ||
| postconditions: | ||
| predicate_id: skos:exactMatch | ||
| weight: 4.0 | ||
|
|
||
| - preconditions: | ||
| subject_match_field_one_of: | ||
| - oio:hasExactSynonym | ||
| - rdfs:label | ||
| object_match_field_one_of: | ||
| - oio:hasBroadSynonym | ||
| postconditions: | ||
| predicate_id: skos:broadMatch | ||
| weight: 2.0 | ||
|
|
||
| - preconditions: | ||
| subject_match_field_one_of: | ||
| - oio:hasExactSynonym | ||
| - rdfs:label | ||
| object_match_field_one_of: | ||
| - oio:hasNarrowSynonym | ||
| postconditions: | ||
| predicate_id: skos:narrowMatch | ||
| weight: 2.0 | ||
|
|
||
| - synonymizer: | ||
| the_rule: Remove parentheses bound info from the label. | ||
| match: r'\([^)]*\)' | ||
| match_scope: "*" | ||
| replacement: "" | ||
|
|
||
| - synonymizer: | ||
| the_rule: Remove box brackets bound info from the label. | ||
| match: r'\[[^)]*\]' | ||
| match_scope: "*" | ||
| replacement: "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| curie_map: | ||
| MP: http://purl.obolibrary.org/obo/MP_ | ||
| HP: http://purl.obolibrary.org/obo/HP_ | ||
| WBPhenotype: http://purl.obolibrary.org/obo/WBPhenotype_ | ||
| XPO: http://purl.obolibrary.org/obo/XPO_ | ||
| PLANP: http://purl.obolibrary.org/obo/PLANP_ | ||
| ZP: http://purl.obolibrary.org/obo/ZP_ | ||
| DPO: http://purl.obolibrary.org/obo/FBcv_ | ||
| FYPO: http://purl.obolibrary.org/obo/FYPO_ | ||
| DDPHENO: http://purl.obolibrary.org/obo/DDPHENO_ | ||
| phipo: http://purl.obolibrary.org/obo/PHIPO_ | ||
| MGPO: http://purl.obolibrary.org/obo/MGPO_ | ||
| APO: http://purl.obolibrary.org/obo/APO_ | ||
| subject_prefixes: | ||
| - MP | ||
| - HP | ||
| - WBPhenotype | ||
| - XPO | ||
| - PLANP | ||
| - ZP | ||
| - FBcv | ||
| - FYPO | ||
| - DDPHENO | ||
| - PHIPO | ||
| - MGPO | ||
| - APO | ||
|
|
||
| relations: | ||
| - skos:exactMatch | ||
| - skos:broadMatch | ||
| - skos:narrowMatch | ||
| - skos:closeMatch | ||
| - skos:relatedMatch | ||
|
|
||
| global_metadata: | ||
| subject_source: http://purl.obolibrary.org/obo/upheno_all_with_relations.owl | ||
| license: "https://creativecommons.org/publicdomain/zero/1.0/" | ||
| mapping_date: "2017-09-20" | ||
| mapping_set_id: http://purl.obolibrary.org/obo/upheno/mappings/upheno-all-lexmatch.sssom.tsv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import logging | ||
| from pathlib import Path | ||
| from oaklib.resource import OntologyResource | ||
| from oaklib.implementations.sqldb.sql_implementation import SqlImplementation | ||
| from oaklib.utilities.lexical.lexical_indexer import ( | ||
| create_lexical_index, | ||
| lexical_index_to_sssom, | ||
| load_mapping_rules, | ||
| save_lexical_index, | ||
| load_lexical_index | ||
| ) | ||
| import sys | ||
| import click | ||
| import yaml | ||
|
|
||
| from sssom.constants import SUBJECT_ID, OBJECT_ID | ||
| from sssom.util import filter_prefixes | ||
| from sssom.parsers import parse_sssom_table | ||
| from sssom.writers import write_table | ||
| from sssom.io import get_metadata_and_prefix_map, filter_file | ||
|
|
||
| SRC = Path(__file__).resolve().parents[1] | ||
| ONTOLOGY_DIR = SRC / "ontology" | ||
| OUT_INDEX_DB = ONTOLOGY_DIR / "tmp/upheno.db.lexical.yaml" | ||
| TEMP_DIR = ONTOLOGY_DIR / "tmp" | ||
|
|
||
| input_argument = click.argument("input", required=True, type=click.Path()) | ||
| output_option = click.option( | ||
| "-o", | ||
| "--output", | ||
| help="Path for output file.", | ||
| default=sys.stdout, | ||
| ) | ||
|
|
||
|
|
||
| @click.group() | ||
| @click.option("-v", "--verbose", count=True) | ||
| @click.option("-q", "--quiet") | ||
| def main(verbose: int, quiet: bool): | ||
| """Run the SSSOM CLI.""" | ||
| logger = logging.getLogger() | ||
| if verbose >= 2: | ||
| logger.setLevel(level=logging.DEBUG) | ||
| elif verbose == 1: | ||
| logger.setLevel(level=logging.INFO) | ||
| else: | ||
| logger.setLevel(level=logging.WARNING) | ||
| if quiet: | ||
| logger.setLevel(level=logging.ERROR) | ||
|
|
||
|
|
||
| @main.command() | ||
| @input_argument | ||
| @click.option( | ||
| "-c", | ||
| "--config", | ||
| help="YAML file containing metadata.", | ||
| ) | ||
| @click.option( | ||
| "-r", | ||
| "--rules", | ||
| help="Ruleset for mapping.", | ||
| ) | ||
| @click.option( | ||
| "--recreate/--no-recreate", | ||
| default=True, | ||
| show_default=True, | ||
| help="if true and lexical index is specified, always recreate, otherwise load from index", | ||
| ) | ||
| @output_option | ||
| def run(input: str, config: str, rules: str, recreate:bool, output: str): | ||
| # Implemented `meta` param in `lexical_index_to_sssom` | ||
|
|
||
| meta = get_metadata_and_prefix_map(config) | ||
| with open(config, "r") as f: | ||
| yml = yaml.safe_load(f) | ||
|
|
||
| prefix_of_interest = yml["subject_prefixes"] | ||
|
|
||
| resource = OntologyResource(slug=f"sqlite:///{Path(input).absolute()}") | ||
| oi = SqlImplementation(resource=resource) | ||
| ruleset = load_mapping_rules(rules) | ||
| syn_rules = [x.synonymizer for x in ruleset.rules if x.synonymizer] | ||
| if not recreate and Path(OUT_INDEX_DB).exists(): | ||
| lexical_index = load_lexical_index(OUT_INDEX_DB) | ||
| else: | ||
| lexical_index = create_lexical_index(oi=oi, synonym_rules=syn_rules) | ||
| save_lexical_index(lexical_index, OUT_INDEX_DB) | ||
|
|
||
| if rules: | ||
| msdf = lexical_index_to_sssom( | ||
| oi, lexical_index, ruleset=load_mapping_rules(rules), meta=meta | ||
| ) | ||
| else: | ||
| msdf = lexical_index_to_sssom(oi, lexical_index, meta=meta) | ||
|
|
||
| msdf.df = filter_prefixes( | ||
| df=msdf.df, filter_prefixes=prefix_of_interest, features=[SUBJECT_ID, OBJECT_ID] | ||
| ) | ||
| with open(str(Path(output)), "w", encoding="utf8") as f: | ||
| write_table(msdf, f) | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.