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

Implement completing source counts in HTML assembler #1439

Merged
merged 1 commit into from
Mar 24, 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
22 changes: 20 additions & 2 deletions indra/assemblers/html/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,12 @@ def __init__(self, statements=None, summary_metadata=None,
if not beliefs else standardize_counts(beliefs)
self.source_counts = get_available_source_counts(self.statements,
custom_source_list) \
if source_counts is None else standardize_counts(source_counts)
if source_counts is None \
else complete_source_counts(standardize_counts(source_counts))
self.available_sources = available_sources_stmts(self.statements,
custom_source_list) if \
source_counts is None else available_sources_src_counts(
source_counts, custom_source_list)
source_counts, custom_source_list)
self.sort_by = sort_by
self.curation_dict = {} if curation_dict is None else curation_dict
self.db_rest_url = db_rest_url
Expand Down Expand Up @@ -919,3 +920,20 @@ def overlap(t1, t2):
# Add the last section of text
format_text += text[start_pos:]
return format_text


def complete_source_counts(source_counts):
"""Return source counts that are complete with respect to all sources.

This is necessary because the statement presentation module expects
that all sources that appear in any statement source count appear
in all statement source counts (even if the count is 0).
"""
all_sources = set()
for stmt_source_counts in source_counts.values():
all_sources |= set(stmt_source_counts)
for stmt_source_counts in source_counts.values():
missing_sources = all_sources - set(stmt_source_counts)
for source in missing_sources:
stmt_source_counts[source] = 0
return source_counts
11 changes: 11 additions & 0 deletions indra/tests/test_html_assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,3 +822,14 @@ def test_sort_group_by_agent_pair_custom_function():
assert list(json_model.keys()) == ['Fez-Baz', 'Bar-Baz', 'Fez-Bar']

ha.make_model(grouping_level='agent-pair')


def test_incomplete_source_counts():
stmt1 = make_stmt()
stmt2 = make_stmt()
stmt2.enz.db_refs = {'FPLX': 'XXX'}
stmt2.get_hash(refresh=True)
source_counts = {stmt1.get_hash(): {'reach': 1},
stmt2.get_hash(): {'sparser': 1}}
ha = HtmlAssembler([stmt1, stmt2], source_counts=source_counts)
ha.make_model()
Loading