diff --git a/immuneML/presentation/html/DatasetExportHTMLBuilder.py b/immuneML/presentation/html/DatasetExportHTMLBuilder.py index fa78bd342..609f1bbe1 100644 --- a/immuneML/presentation/html/DatasetExportHTMLBuilder.py +++ b/immuneML/presentation/html/DatasetExportHTMLBuilder.py @@ -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 @@ -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 ] } diff --git a/immuneML/presentation/html/ExploratoryAnalysisHTMLBuilder.py b/immuneML/presentation/html/ExploratoryAnalysisHTMLBuilder.py index 6d34e9180..2e5cbf1c9 100644 --- a/immuneML/presentation/html/ExploratoryAnalysisHTMLBuilder.py +++ b/immuneML/presentation/html/ExploratoryAnalysisHTMLBuilder.py @@ -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 diff --git a/immuneML/presentation/html/Util.py b/immuneML/presentation/html/Util.py index 1df3b7823..b8c8dae1e 100644 --- a/immuneML/presentation/html/Util.py +++ b/immuneML/presentation/html/Util.py @@ -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: @@ -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()] + } \ No newline at end of file diff --git a/immuneML/presentation/html/templates/DatasetExport.html b/immuneML/presentation/html/templates/DatasetExport.html index dfabd7bd9..b3aa6aee4 100644 --- a/immuneML/presentation/html/templates/DatasetExport.html +++ b/immuneML/presentation/html/templates/DatasetExport.html @@ -37,14 +37,27 @@

General information

Dataset labels

- The following labels may be used for classification: -
- +

The following label(s) are available for this dataset, and may for example be used for classification:

+ +
+ + + + + + + + + {{#dataset_labels}} + + + + + {{/dataset_labels}} + +
Label nameLabel classes
{{dataset_label_name}}{{dataset_label_classes}}
+ {{#show_preprocessing}}

Preprocessings

The following preprocessing steps have been applied to the dataset: diff --git a/immuneML/presentation/html/templates/ExploratoryAnalysis.html b/immuneML/presentation/html/templates/ExploratoryAnalysis.html index 5a86cd66c..26aea72b2 100644 --- a/immuneML/presentation/html/templates/ExploratoryAnalysis.html +++ b/immuneML/presentation/html/templates/ExploratoryAnalysis.html @@ -38,6 +38,29 @@

General information

+ +

Dataset labels

+

The following label(s) are available for this dataset, and may for example be used for classification:

+ +
+ + + + + + + + + {{#dataset_labels}} + + + + + {{/dataset_labels}} + +
Label nameLabel classes
{{dataset_label_name}}{{dataset_label_classes}}
+
+ {{#show_preprocessing}}

Preprocessings

The following preprocessing steps have been applied to the dataset:

@@ -79,21 +102,22 @@

{{encoding_name}}

{{/show_encoding}} {{#show_labels}}

Analysis labels

+

The following label(s) were used in this specific analysis:

- - + + - {{#labels}} + {{#analysis_labels}} - {{/labels}} + {{/analysis_labels}}
Label nameLabel values (classes)Label nameLabel classes
{{name}} {{values}}
@@ -108,8 +132,8 @@

Report {{name}}

{{/show_info}} {{#output_figures}} -
- {{#name}}

{{name}}

{{/name}} +
+ {{#name}}

{{name}}

{{/name}} {{#is_embed}} {{/is_embed}}