Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow comparison to be used from command line #97

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions src/fbc_curation/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from fbc_curation import EXAMPLE_DIR
from fbc_curation.frog import CuratorConstants, FrogReport

import sys

logger = log.get_logger(__name__)

Expand Down Expand Up @@ -61,6 +62,33 @@ def read_reports_from_omex(omex_path: Path) -> Dict[str, Dict[str, FrogReport]]:

return model_reports

@staticmethod
def read_reports_from_paths(report_paths: List[Path]) -> Dict[str, Dict[str, FrogReport]]:
"""Read all reports from TSVs.

Returns dictionary of {model_location: ...}

"""
reports: List[FrogReport] = []

for directory in report_paths:
reports.append(FrogReport.from_tsv(directory))

# get model reports per model
model_reports: Dict[str, Dict[str, FrogReport]] = {}
for report in reports:
model_location = report.metadata.model_location
d = model_reports.get(model_location, {})
frog_id = report.metadata.frog_id
d[frog_id] = report
model_reports[model_location] = d

info = {loc: list(item.keys()) for loc, item in model_reports.items()}
logger.info(f"Reports:\n{info}")

return model_reports


# TODO: implement comparison result and return results

@staticmethod
Expand Down Expand Up @@ -161,11 +189,20 @@ def compare_reports(reports: Dict[str, FrogReport]) -> bool:
console.rule(style="white")
return bool(all_equal)


import sys
if __name__ == "__main__":
# Read results and compare
omex_path = EXAMPLE_DIR / "frogs" / "e_coli_core_FROG.omex"
model_reports = FrogComparison.read_reports_from_omex(omex_path=omex_path)
if len(sys.argv) < 3:
# if no arg is given behave as before
omex_path = EXAMPLE_DIR / "frogs" / "e_coli_core_FROG.omex"
model_reports = FrogComparison.read_reports_from_omex(omex_path=omex_path)
else:
# otherwise build reports from given paths
model_reports = FrogComparison.read_reports_from_paths(
[Path(p) for p in sys.argv[1:]]
)

# then process as before
for model_location, reports in model_reports.items():
print(model_location)
FrogComparison.compare_reports(reports)