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

v0.10.1 release #201

Merged
merged 4 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) format.

## [0.10.1] - 2024-08-06
### Fixed
- add pipestat summarize and link for pephub backend


## [0.10.0] - 2024-07-18
### Fixed
- allow for bool or boolean in schema [#189](https://github.com/pepkit/pipestat/issues/189)
Expand Down
2 changes: 1 addition & 1 deletion pipestat/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.10.0"
__version__ = "0.10.1"
25 changes: 14 additions & 11 deletions pipestat/backends/pephub_backend/pephubbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ def check_record_exists(

return bool(query_hit["records"])

def count_records(self):
"""
Count rows in a selected table
:return int: number of records
"""

count = self.select_records()["total_size"]
return count

def list_results(
self,
restrict_to: Optional[List[str]] = None,
Expand All @@ -108,7 +117,7 @@ def list_results(
]
)
try:
record = record["records"][0][rid]
record = record["records"][0]
except IndexError:
return []

Expand Down Expand Up @@ -339,7 +348,7 @@ def get_status(self, record_identifier: str) -> Optional[str]:
except RecordNotFoundError:
return None
try:
status = result["records"][0][record_identifier]["status"]
status = result["records"][0]["status"]
except IndexError or KeyError:
status = None

Expand Down Expand Up @@ -433,7 +442,7 @@ def get_operator(op: Literal["eq", "lt", "ge", "gt", "in"]) -> Any:
key = filter_condition["key"]
value = filter_condition["value"]

# Create querry for df based on filter conditions
# Create query for df based on filter conditions
if isinstance(value, list):
filter_expression = f"{key} {retrieved_operator} {value}"
else:
Expand All @@ -451,15 +460,9 @@ def get_operator(op: Literal["eq", "lt", "ge", "gt", "in"]) -> Any:
else:
df = df.query(filter_expression)

print("done")

# Once we have the dataframe (filtered or unfiltered), convert to a dict using the sample_name/record_identifier as the primary key
df2dict = df.set_index("sample_name").transpose().to_dict(orient="dict")
df.rename(columns={"sample_name": "record_identifier"}, inplace=True)

# Must do this to align output structure with that of db_backend and file_backends
records_list = []
for key, value in df2dict.items():
records_list.append({key: value})
records_list = df.to_dict("records")

records_dict = {
"total_size": total_count,
Expand Down
16 changes: 9 additions & 7 deletions pipestat/pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,6 @@ def link(self, link_dir) -> Union[str, None]:
:param str link_dir: path to desired symlink output directory
:return str | None linked_results_path: path to symlink directory or None
"""
if self.cfg["pephub_path"]:
_LOGGER.warning(f"Linking results is not supported for PEPHub backend.")
return None

self.check_multi_results()
linked_results_path = self.backend.link(link_dir=link_dir)
Expand All @@ -923,20 +920,25 @@ def summarize(
looper_samples: Optional[list] = None,
amendment: Optional[str] = None,
portable: Optional[bool] = False,
output_dir: Optional[str] = None,
) -> Union[str, None]:
"""
Builds a browsable html report for reported results.
:param Iterable[str] looper_samples: list of looper Samples from PEP
:param Iterable[str] amendment: name indicating amendment to use, optional
:param bool portable: moves figures and report files to directory for easy sharing
:param str output_dir: overrides output_dir set during pipestatManager creation.
:return str: report_path

"""

if output_dir:
self.cfg[OUTPUT_DIR] = output_dir

if self.cfg["pephub_path"]:
_LOGGER.warning(
f"Summarize not supported for PEPHub backend. Please generate report via PEPHub website."
)
return None
if OUTPUT_DIR not in self.cfg:
_LOGGER.warning(f"Output directory is required for pipestat summarize.")
return None

self.check_multi_results()

Expand Down
11 changes: 8 additions & 3 deletions pipestat/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,14 @@ def __init__(self, prj, portable=False):

results_file_path = getattr(self.prj.backend, "results_file_path", None)
config_path = self.prj.cfg.get("config_path", None)
output_dir = getattr(self.prj.cfg[OUTPUT_DIR], "output_dir", None)
output_dir = self.prj.cfg.get(OUTPUT_DIR, None)
self.output_dir = output_dir or results_file_path or config_path
self.output_dir = os.path.dirname(self.output_dir)

if os.path.isdir(self.output_dir):
pass
else:
self.output_dir = os.path.dirname(self.output_dir)

if not self.portable:
self.reports_dir = os.path.join(self.output_dir, "reports")
else:
Expand Down Expand Up @@ -1367,7 +1372,7 @@ def get_file_for_table(prj, pipeline_name: str, appendix=None, directory=None) -
# TODO make determining the output_dir its own small function since we use the same code in HTML report building.
results_file_path = getattr(prj.backend, "results_file_path", None)
config_path = prj.cfg.get("config_path", None)
output_dir = prj.cfg.get("output_dir", None)
output_dir = prj.cfg.get(OUTPUT_DIR, None)
table_dir = output_dir or results_file_path or config_path
if not os.path.isdir(table_dir):
table_dir = os.path.dirname(table_dir)
Expand Down
32 changes: 28 additions & 4 deletions tests/test_pipestat.py
Original file line number Diff line number Diff line change
Expand Up @@ -2587,7 +2587,7 @@ def test_pephub_backend_retrieve_one(

result = psm.retrieve_one(record_identifier=rec_id)

assert len(result.keys()) == 1
assert len(result.keys()) == 6

def test_pephub_backend_retrieve_many(
self,
Expand Down Expand Up @@ -2687,11 +2687,35 @@ def test_pephub_unsupported_funcs(

assert results is None

psm.link("somedir")
psm.list_recent_results()
psm.summarize()

def test_pephub_unsupported_funcs(
def test_pephub_backend_summarize(
self,
config_file_path,
schema_file_path,
):

with TemporaryDirectory() as d:
temp_dir = d
psm = PipestatManager(pephub_path=PEPHUB_URL, schema_path=schema_file_path)
report_path = psm.summarize(output_dir=d)

assert report_path

def test_pephub_backend_link(
self,
config_file_path,
schema_file_path,
):

with TemporaryDirectory() as d:
temp_dir = d
psm = PipestatManager(pephub_path=PEPHUB_URL, schema_path=schema_file_path)
report_path = psm.link(link_dir=d)

assert report_path

def test_pephub_bad_path(
self,
config_file_path,
schema_file_path,
Expand Down
Loading