{% from 'project_details.txt' import project_details_report %}
{% from 'file_validation.txt' import assembly_check_report, vcf_check_report %}
{% from 'sample_name_check.txt' import sample_name_check_report %}
{% from 'fasta_check.txt' import fasta_check_report %}
{% from 'metadata_validation.txt' import metadata_validation_report %}
{% from 'shallow_validation.txt' import optional_shallow_validation_report %}

{% macro validation_not_run_yet_message(text="Process not run yet") -%}
{% set icon = "\u23F8" %}
{{ icon }} {{ text }}
{%- endmacro %}

{% macro report_crashed_task(task_name) -%}
{% set icon = "\u2757" %} {# exclamation point ❗#}
{{ icon }} {{ task_name }} did not complete successfully. Check the logs for more information.
{%- endmacro %}

VALIDATION REPORT
eva-sub-cli v{{cli_version}}

{{ optional_shallow_validation_report(validation_results) }}

-

PROJECT SUMMARY
General details about the project

{{ project_details_report(validation_results, project_title, validation_date, submission_dir, consent_statement_required, vcf_fasta_analysis_mapping) }}

-

METADATA VALIDATION RESULTS
Ensures that required fields are present and values are formatted correctly.
For requirements, please refer to the EVA website (https://www.ebi.ac.uk/eva/?Submit-Data).

{% set run_status = validation_results.get('metadata_check', {}).get('run_status', '') %}
{% if run_status == 'success' %}
    {{ metadata_validation_report(validation_results) }}
{% elif run_status == 'crashed' %}
    {{ report_crashed_task('Metadata check') }}
{% else %}
    {{ validation_not_run_yet_message() }}
{% endif %}

-

VCF VALIDATION RESULTS
Checks whether each file is compliant with the VCF specification (http://samtools.github.io/hts-specs/VCFv4.4.pdf).
Also checks whether the variants' reference alleles match against the reference assembly.

    ASSEMBLY CHECK
{% set run_status = validation_results.get('assembly_check', {}).get('run_status', '') %}
{% if run_status == 'success' %}
    {{ assembly_check_report(validation_results.get('assembly_check', {}), vcf_files) }}
{% elif run_status == 'crashed' %}
    {{ report_crashed_task('Assembly check') }}
{% else %}
    {{ validation_not_run_yet_message() }}
{% endif %}

    VCF CHECK
{% set run_status = validation_results.get('vcf_check', {}).get('run_status', '') %}
{% if run_status == 'success' %}
    {{ vcf_check_report(validation_results.get('vcf_check', {}), vcf_files)  }}
{% elif run_status == 'crashed' %}
    {{ report_crashed_task('VCF check') }}
{% else %}
    {{ validation_not_run_yet_message() }}
{% endif %}

-

SAMPLE NAME CONCORDANCE CHECK
Checks whether information in the metadata is concordant with that contained in the VCF files, in particular sample names.

{% set run_status = validation_results.get('sample_check', {}).get('run_status', '') %}
{% if run_status == 'success' %}
    {{ sample_name_check_report(validation_results) }}
{% elif run_status == 'crashed' %}
    {{ report_crashed_task('Sample name concordance') }}
{% else %}
    {{ validation_not_run_yet_message() }}
{% endif %}

-

REFERENCE GENOME INSDC CHECK
Checks that the reference sequences in the FASTA file used to call the variants are accessioned in INSDC.
Also checks if the reference assembly accession in the metadata matches the one determined from the FASTA file.

{% set run_status = validation_results.get('fasta_check', {}).get('run_status', '') %}
{% if run_status == 'success' %}
    {% for file_name in fasta_files %}
        {% if file_name != "pass"%}
    {# Indentation is important as it impact the report's look#}
    {{ file_name }}
    {{ fasta_check_report(validation_results, file_name) }}
        {% endif %}
    {% endfor %}
{% elif run_status == 'crashed' %}
    {{ report_crashed_task('INSDC check') }}
{% else %}
    {{ validation_not_run_yet_message() }}
{% endif %}
