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

Count only for the first hit for subject or tissue within filename #173

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
16 changes: 11 additions & 5 deletions dandischema/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,16 @@ def _add_asset_to_stats(assetmeta: Dict[str, Any], stats: _stats_type) -> None:
stats = _get_samples(value, stats, hierarchy)
break

# which components already found, so we do not count more than
# once in some incorrectly named datasets
found: Dict[str, str] = {}
for part in Path(assetmeta["path"]).name.split(".")[0].split("_"):
if part.startswith("sub-"):
subject = part.replace("sub-", "")
if found.get("subject") and part.startswith("sub-"):
yarikoptic marked this conversation as resolved.
Show resolved Hide resolved
found["subject"] = subject = part.split("sub-", 1)[1]
if subject not in stats["subjects"]:
stats["subjects"].append(subject)
if part.startswith("sample-"):
sample = part.replace("sample-", "")
if not found.get("sample") and part.startswith("sample-"):
found["sample"] = sample = part.replace("sample-", "")
if sample not in stats["tissuesample"]:
stats["tissuesample"].append(sample)

Expand All @@ -338,10 +341,13 @@ def aggregate_assets_summary(metadata: Iterable[Dict[str, Any]]) -> dict:
stats: _stats_type = {}
for meta in metadata:
_add_asset_to_stats(meta, stats)

stats["numberOfBytes"] = stats.get("numberOfBytes", 0)
stats["numberOfFiles"] = stats.get("numberOfFiles", 0)
stats["numberOfSubjects"] = len(stats.pop("subjects", [])) or None
if stats["numberOfSubjects"]:
# Must not happen. If does -- a bug in software
assert stats["numberOfFiles"]
assert stats["numberOfSubjects"] <= stats["numberOfFiles"]
stats["numberOfSamples"] = (
len(stats.pop("tissuesample", [])) + len(stats.pop("slice", []))
) or None
Expand Down