Skip to content

Commit

Permalink
updated HTML output of DatasetExport and ExploratoryAnalysis
Browse files Browse the repository at this point in the history
  • Loading branch information
LonnekeScheffer committed Nov 8, 2023
1 parent 8a2c1c9 commit f078371
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 58 deletions.
34 changes: 16 additions & 18 deletions immuneML/presentation/html/DatasetExportHTMLBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from immuneML.presentation.TemplateParser import TemplateParser
from immuneML.presentation.html.Util import Util
from immuneML.util.PathBuilder import PathBuilder
from immuneML.util.StringHelper import StringHelper
from immuneML.workflows.instructions.dataset_generation.DatasetExportState import DatasetExportState


Expand Down Expand Up @@ -41,24 +40,23 @@ def make_html_map(state: DatasetExportState, base_path: Path) -> dict:
"full_specs": Util.get_full_specs_path(base_path),
"datasets": [
{
"dataset_name": dataset.name,
"dataset_type": StringHelper.camel_case_to_word_string(type(dataset).__name__),
"dataset_size": f"{dataset.get_example_count()} {type(dataset).__name__.replace('Dataset', 's').lower()}",
"labels": [{"label_name": label} for label in dataset.get_label_names()],
"preprocessing_sequence": [
{
"preprocessing_name": preprocessing.__class__.__name__,
"preprocessing_params": ", ".join([f"{key}: {value}" for key, value in vars(preprocessing).items()])
} for preprocessing in state.preprocessing_sequence
] if state.preprocessing_sequence is not None else [],
"show_preprocessing": state.preprocessing_sequence is not None and len(state.preprocessing_sequence) > 0,
"formats": [
{
"format_name": format_name,
"dataset_download_link": os.path.relpath(path=Util.make_downloadable_zip(state.result_path, state.paths[dataset.name][format_name]),
**Util.make_dataset_html_map(dataset),
**{
"preprocessing_sequence": [
{
"preprocessing_name": preprocessing.__class__.__name__,
"preprocessing_params": ", ".join([f"{key}: {value}" for key, value in vars(preprocessing).items()])
} for preprocessing in state.preprocessing_sequence
] if state.preprocessing_sequence is not None else [],
"show_preprocessing": state.preprocessing_sequence is not None and len(state.preprocessing_sequence) > 0,
"formats": [
{
"format_name": format_name,
"dataset_download_link": os.path.relpath(path=Util.make_downloadable_zip(state.result_path, state.paths[dataset.name][format_name]),
start=base_path)
} for format_name in state.formats
]
} for format_name in state.formats
]
}
} for dataset in state.datasets
]
}
Expand Down
65 changes: 38 additions & 27 deletions immuneML/presentation/html/ExploratoryAnalysisHTMLBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,46 @@ def make_html_map(state: ExploratoryAnalysisState, base_path: Path) -> dict:
"css_style": Util.get_css_content(ExploratoryAnalysisHTMLBuilder.CSS_PATH),
"full_specs": Util.get_full_specs_path(base_path),
'immuneML_version': MLUtil.get_immuneML_version(),
"analyses": [{
"name": name,
"dataset_name": analysis.dataset.name if analysis.dataset.name is not None else analysis.dataset.identifier,
"dataset_type": StringHelper.camel_case_to_word_string(type(analysis.dataset).__name__),
"example_count": analysis.dataset.get_example_count(),
"dataset_size": f"{analysis.dataset.get_example_count()} {type(analysis.dataset).__name__.replace('Dataset', 's').lower()}",
"preprocessing_sequence": [
{
"preprocessing_name": preprocessing.__class__.__name__,
"preprocessing_params": ", ".join(
[f"{key}: {value}" for key, value in vars(preprocessing).items()])
} for preprocessing in analysis.preprocessing_sequence
] if analysis.preprocessing_sequence is not None else [],
"show_preprocessing": analysis.preprocessing_sequence is not None and len(analysis.preprocessing_sequence) > 0,
"show_labels": analysis.label_config is not None and len(analysis.label_config.get_labels_by_name()) > 0,
"labels": [{"name": label.name, "values": str(label.values)[1:-1]}
for label in analysis.label_config.get_label_objects()] if analysis.label_config else None,
"encoding_key": analysis.encoder.name if analysis.encoder is not None else None,
"encoding_name": StringHelper.camel_case_to_word_string(type(analysis.encoder).__name__) if analysis.encoder is not None
else None,
"encoding_params": [{"param_name": key, "param_value": str(value)} for key, value in vars(analysis.encoder).items()] if analysis.encoder is not None else None,
"show_encoding": analysis.encoder is not None,
"report": Util.to_dict_recursive(Util.update_report_paths(analysis.report_result, base_path), base_path)
} for name, analysis in state.exploratory_analysis_units.items()]
"analyses": [
{
**Util.make_dataset_html_map(analysis.dataset),
**{
"name": name,
"preprocessing_sequence": [
{
"preprocessing_name": preprocessing.__class__.__name__,
"preprocessing_params": ", ".join(
[f"{key}: {value}" for key, value in vars(preprocessing).items()])
} for preprocessing in analysis.preprocessing_sequence
] if analysis.preprocessing_sequence is not None else [],
"show_preprocessing": analysis.preprocessing_sequence is not None and len(
analysis.preprocessing_sequence) > 0,
"show_labels": analysis.label_config is not None and len(
analysis.label_config.get_labels_by_name()) > 0,
"analysis_labels": [{"name": label.name, "values": str(label.values)[1:-1]}
for label in
analysis.label_config.get_label_objects()] if analysis.label_config else None,
"encoding_key": analysis.encoder.name if analysis.encoder is not None else None,
"encoding_name": StringHelper.camel_case_to_word_string(
type(analysis.encoder).__name__) if analysis.encoder is not None
else None,
"encoding_params": [{"param_name": key, "param_value": str(value)} for key, value in
vars(analysis.encoder).items()] if analysis.encoder is not None else None,
"show_encoding": analysis.encoder is not None,
"report": Util.to_dict_recursive(Util.update_report_paths(analysis.report_result, base_path),
base_path) if analysis.report_result is not None else None
}
} for name, analysis in state.exploratory_analysis_units.items()]
}

for analysis in html_map["analyses"]:
analysis["show_tables"] = len(analysis["report"]["output_tables"]) > 0 if "output_tables" in analysis["report"] else False
analysis["show_text"] = len(analysis["report"]["output_text"]) > 0 if "output_text" in analysis["report"] else False
analysis["show_info"] = analysis["report"]["info"] is not None and len(analysis["report"]["info"]) > 0 if "info" in analysis["report"] else False
if analysis["report"] is not None:
analysis["show_tables"] = len(analysis["report"]["output_tables"]) > 0 if "output_tables" in analysis["report"] else False
analysis["show_text"] = len(analysis["report"]["output_text"]) > 0 if "output_text" in analysis["report"] else False
analysis["show_info"] = analysis["report"]["info"] is not None and len(analysis["report"]["info"]) > 0 if "info" in analysis["report"] else False
else:
analysis["show_tables"] = False
analysis["show_text"] = False
analysis["show_info"] = False

return html_map
11 changes: 11 additions & 0 deletions immuneML/presentation/html/Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from immuneML.reports.ReportOutput import ReportOutput
from immuneML.reports.ReportResult import ReportResult
from immuneML.util.PathBuilder import PathBuilder
from immuneML.util.StringHelper import StringHelper


class Util:
Expand Down Expand Up @@ -115,3 +116,13 @@ def update_report_paths(report_result: ReportResult, path: Path) -> ReportResult
f"and it will not be moved to HTML output folder.")

return report_result

@staticmethod
def make_dataset_html_map(dataset):
return {"dataset_name": dataset.name,
"dataset_type": StringHelper.camel_case_to_word_string(type(dataset).__name__),
"dataset_size": f"{dataset.get_example_count()} {type(dataset).__name__.replace('Dataset', 's').lower()}",
"dataset_labels": [{"dataset_label_name": label_name,
"dataset_label_classes": ", ".join(str(class_name) for class_name in dataset.labels[label_name])}
for label_name in dataset.get_label_names()]
}
27 changes: 20 additions & 7 deletions immuneML/presentation/html/templates/DatasetExport.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,27 @@ <h4>General information</h4>
</table>
</div>
<h4>Dataset labels</h4>
The following labels may be used for classification:
<div>
<ul>
{{#labels}}
<li>{{label_name}}</li>
{{/labels}}
</ul>
<p>The following label(s) are available for this dataset, and may for example be used for classification:</p>

<div class="table-container">
<table>
<thead>
<tr>
<th><b>Label name</b></th>
<th><b>Label classes</b></th>
</tr>
</thead>
<tbody>
{{#dataset_labels}}
<tr>
<td>{{dataset_label_name}}</td>
<td>{{dataset_label_classes}}</td>
</tr>
{{/dataset_labels}}
</tbody>
</table>
</div>

{{#show_preprocessing}}
<h4>Preprocessings</h4>
The following preprocessing steps have been applied to the dataset:
Expand Down
36 changes: 30 additions & 6 deletions immuneML/presentation/html/templates/ExploratoryAnalysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ <h4>General information</h4>
</tr>
</table>
</div>

<h4>Dataset labels</h4>
<p>The following label(s) are available for this dataset, and may for example be used for classification:</p>

<div class="table-container">
<table>
<thead>
<tr>
<th><b>Label name</b></th>
<th><b>Label classes</b></th>
</tr>
</thead>
<tbody>
{{#dataset_labels}}
<tr>
<td>{{dataset_label_name}}</td>
<td>{{dataset_label_classes}}</td>
</tr>
{{/dataset_labels}}
</tbody>
</table>
</div>

{{#show_preprocessing}}
<h4>Preprocessings</h4>
<p>The following preprocessing steps have been applied to the dataset:</p>
Expand Down Expand Up @@ -79,21 +102,22 @@ <h4>{{encoding_name}}</h4>
{{/show_encoding}}
{{#show_labels}}
<h3>Analysis labels</h3>
<p>The following label(s) were used in this specific analysis:</p>
<div class="table-container">
<table>
<thead>
<tr>
<th>Label name</th>
<th>Label values (classes)</th>
<th><b>Label name</b></th>
<th><b>Label classes</b></th>
</tr>
</thead>
<tbody>
{{#labels}}
{{#analysis_labels}}
<tr>
<td>{{name}}</td>
<td>{{values}}</td>
</tr>
{{/labels}}
{{/analysis_labels}}
</tbody>
</table>
</div>
Expand All @@ -108,8 +132,8 @@ <h3>Report {{name}}</h3>
{{/show_info}}

{{#output_figures}}
<div class="center padded">
{{#name}}<p>{{name}}</p>{{/name}}
<div>
{{#name}}<h4>{{name}}</h4>{{/name}}
{{#is_embed}}
<embed src="{{path}}">
{{/is_embed}}
Expand Down

0 comments on commit f078371

Please sign in to comment.