Skip to content

Commit

Permalink
Ran formatter and minor code cleanup (#737)
Browse files Browse the repository at this point in the history
* Refactor diff markdown title

* code clean-up

* formatted

* reverted relationships to mappings
  • Loading branch information
hrshdhgd authored Apr 9, 2024
1 parent 41c1d95 commit 0a734a8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 35 deletions.
8 changes: 0 additions & 8 deletions src/oaklib/implementations/amigo/amigo_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ def subset_members(self, subset: SUBSET_CURIE, **kwargs) -> Iterable[CURIE]:
for doc in results:
yield doc[ANNOTATION_CLASS]


def associations(
self,
subjects: Iterable[CURIE] = None,
Expand Down Expand Up @@ -348,7 +347,6 @@ def association_counts(
solr, fq, facet_field=ff, rows=0, facet_limit=limit, min_facet_count=min_facet_count
)


# def association_pairwise_coassociations(
# self,
# curies1: Iterable[CURIE],
Expand Down Expand Up @@ -389,8 +387,6 @@ def association_counts(
# yield ff[i], ff[i + 1]
#



def association_subject_counts(
self,
subjects: Iterable[CURIE] = None,
Expand Down Expand Up @@ -446,10 +442,6 @@ def relationships(
self._cache_nodes(nodes, [s, p, o])
yield s, p, o





def basic_search(
self, search_term: str, config: Optional[SearchConfiguration] = None
) -> Iterable[CURIE]:
Expand Down
9 changes: 6 additions & 3 deletions src/oaklib/interfaces/association_provider_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ def association_pairwise_coassociations(
curies1 = list(curies1)
curies2 = list(curies2)
logging.info(f"Finding co-associations between {curies1} and {curies2}")
assocmap = {c: list(self.associations(objects=[c], **kwargs)) for c in set(curies1+curies2)}
assocmap = {
c: list(self.associations(objects=[c], **kwargs)) for c in set(curies1 + curies2)
}
assocmap1 = {c: assocmap[c] for c in curies1}
assocmap2 = {c: assocmap[c] for c in curies2}
for c1 in curies1:
Expand All @@ -389,8 +391,9 @@ def association_pairwise_coassociations(
number_subject_unique_to_entity2=len(elements2.difference(elements1)),
)
if coassoc.number_subjects_in_union:
coassoc.proportion_subjects_in_common = (coassoc.number_subjects_in_common /
coassoc.number_subjects_in_union)
coassoc.proportion_subjects_in_common = (
coassoc.number_subjects_in_common / coassoc.number_subjects_in_union
)
if include_entities:
coassoc.subjects_in_common = list(common)
coassoc.associations_for_subjects_in_common = assocs_to_common
Expand Down
4 changes: 3 additions & 1 deletion src/oaklib/utilities/lexical/synonymizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def apply_synonymizer_to_terms(
if qualifier is None or qualifier == "":
if rule.in_place or scope_pred == "definition":
# preserves the original synonym type
qualifier = pred_to_qual.get(scope_pred, scope_pred).lower()
qualifier = pred_to_qual.get(
scope_pred, scope_pred
).lower()
else:
qualifier = "exact"
n += 1
Expand Down
32 changes: 12 additions & 20 deletions src/oaklib/utilities/writers/change_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Change Handler Class."""

from dataclasses import dataclass
from typing import Dict
from typing import Dict, List

from kgcl_schema.datamodel.kgcl import Change

Expand All @@ -12,30 +12,22 @@ def __init__(self, oi, file):
self.file = file
self.oi = oi

def write_markdown_collapsible(self, title, content_lines):
# Start with the details tag for a collapsible section
def write_markdown_collapsible(self, title: str, content_lines: List[str]) -> None:
self.file.write(f"<details>\n<summary>{title}</summary>\n\n")

# Write the content lines within the collapsible section
content = "\n".join(content_lines)
self.file.write(content + "\n\n")

# Close the details tag
self.file.write("\n".join(content_lines) + "\n\n")
self.file.write("</details>\n\n")

def write_markdown_table(self, title, header, rows):
# Create the table header and separator lines
markdown_rows = [
header,
"|".join(["----"] * len(header.split("|")[1:-1])) + "|",
]

# Add the table rows
markdown_rows.extend(rows)

# Write the table as a collapsible section
def write_markdown_table(self, title: str, header: str, rows: List[str]) -> None:
separator = "|".join(["----"] * len(header.split("|")[1:-1])) + "|"
markdown_rows = [header, separator] + rows
self.write_markdown_collapsible(title, markdown_rows)

def handle_generic_change(
self, value: List[object], title: str, header: str, row_format: str
) -> None:
rows = [row_format.format(change=change) for change in value]
self.write_markdown_table(f"{title}: {len(rows)}", header, rows)

def handle_new_synonym(self, value):
# Create rows for the table
rows = [
Expand Down
3 changes: 1 addition & 2 deletions tests/test_utilities/test_synonymizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ def test_synonymizer(rule, input, expected):
"the plasma membrane and nucleus, but including other subcellular structures.' "
"to 'All of the contents of a cell excluding the plasma membrane and "
"NUCLEUS, but including other subcellular structures.'"
)
],
),
Expand All @@ -105,7 +104,7 @@ def test_synonymizer(rule, input, expected):
],
)
def test_syonymizer_on_terms(ruleset, include_all, terms, expected):
#adapter = get_adapter(f"simpleobo:{TEST_SIMPLE_ONT}")
# adapter = get_adapter(f"simpleobo:{TEST_SIMPLE_ONT}")
adapter = get_adapter(f"{TEST_SIMPLE_ONT}")
if isinstance(ruleset, Synonymizer):
ruleset = RuleSet(rules=[ruleset])
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ deps =
ruff
skip_install = true
commands =
black src/ tests/
black src/ tests/ --exclude src\/oaklib\/datamodels\/.*\.py
ruff --fix src/ tests/
description = Run linters.

Expand Down

0 comments on commit 0a734a8

Please sign in to comment.