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

feat: General report chls #72

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
Draft
1 change: 1 addition & 0 deletions .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ jobs:
default-branch: main
extra-files:
- workflow/templates/cnv_html_report/index.html
- workflow/templates/general_html_report/index.html
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ reports/
site/
logs/
results/
tailwindcss
*.min.css
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
workflow/templates/assets/css/main.css
1 change: 1 addition & 0 deletions .tests/integration/Snakefile_module
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ from hydra_genetics.utils.misc import get_module_snakefile
rule all:
input:
"reports/cnv_html_report/NA12878_N.pathology.cnv_report.html",
"reports/general_html_report/NA12878_N.general_report.html",


module reports:
Expand Down
5 changes: 5 additions & 0 deletions .tests/integration/config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
output: "../../config/output_files.yaml"
general_report: "../../config/general_report.yaml"
resources: "resources.yaml"
samples: "samples.tsv"
units: "units.tsv"
Expand All @@ -9,6 +10,10 @@ reference:
cnv_html_report:
cytobands: true

general_html_report:
final_directory_depth: 2


merge_cnv_json:
annotations:
- config/amp_genes.bed
Expand Down
62 changes: 62 additions & 0 deletions .tests/integration/config/NA12878_N.general_report.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"sample": "NA12878",
"analysis_date": "2023-11-17",
"pipeline": {
"name": "Twist Solid",
"version": "0.9.0",
"uri": "https://github.com/genomic-medicine-sweden/Twist_Solid/tree/v0.9.0"
},
"file_links": [
{
"name": "CNV HTML report",
"description": "HTML report summarising the results of the CNV analysis",
"uri": "results/cnv/NA12878_N.pathology.cnv_report.html"
}
],
"results": [
{
"name": "TMB",
"type": "single_value",
"description": "Tumor mutational burden",
"value": 12
},
{
"name": "Result 2",
"type": "table",
"description": "A table of results",
"value": [
{
"column1": "row1",
"column2": "value1"
},
{
"column1": "row2",
"column2": "value2"
},
{
"column2": "value3",
"column1": "row3"
}
]
},
{
"name": "Image result",
"type": "image",
"description": "An image",
"value": "https://placehold.co/600x400/png"
},
{
"name": "Local image",
"type": "image",
"description": "A local image from a path relative to the analysis directory",
"value": "test_data/NA12878_N.png"
},
{
"name": "QC",
"type": "multiqc",
"description": "QC data from MultiQC with the other samples in the sampe run included for context",
"sections": ["table"],
"value": "qc/multiqc/multiqc_DNA_data/multiqc_data.json"
}
]
}
Binary file added .tests/integration/test_data/NA12878_N.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions .tests/unit/test_general_html_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import pathlib
import pytest
import sys

sys.path.insert(0, str(pathlib.Path(__file__).parents[2]))

from workflow.scripts.general_html_report import *


def test_valid_table():
table = [
{
"col1": "val1",
"col2": 1,
},
{
"col1": "val2",
"col2": 2,
},
{
"col1": "val3",
"col2": 3,
},
]

assert validate_table_data(table)


def test_empty_table():
with pytest.raises(ValueError, match="empty table"):
validate_table_data([])


def test_unequal_columns():
table = [
{
"col1": "val1",
"col2": 1,
},
{
"col1": "val2",
"col3": 2,
},
{
"col1": "val3",
"col2": 3,
},
]

with pytest.raises(
ValueError,
match="expected columns 'col1', 'col2' in row 2, found 'col1', 'col3'",
):
validate_table_data(table)


def test_missing_columns():
table = [
{
"col1": "val1",
"col2": 1,
},
{
"col1": "val2",
},
{
"col1": "val3",
"col2": 3,
},
]

with pytest.raises(ValueError, match="expected 2 columns in row 2, found 1"):
validate_table_data(table)


def test_fix_relative_uri():
assert fix_relative_uri("http://www.google.com", depth=2) == "http://www.google.com"
assert fix_relative_uri("https://www.google.com", depth=2) == "https://www.google.com"
assert fix_relative_uri("docker://hydra-genetics/picard", depth=2) == "docker://hydra-genetics/picard"
assert fix_relative_uri("/path/to/a/file.txt", depth=2) == "/path/to/a/file.txt"
assert fix_relative_uri("path/to/a/file.txt", depth=2) == "../../path/to/a/file.txt"
4 changes: 4 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
output: "config/output_files.yaml"
general_report: "config/general_report.yaml"
resources: "config/resources.yaml"
samples: "samples.tsv"
units: "units.tsv"
Expand All @@ -14,6 +15,9 @@ cnv_html_report:
cytobands: false
show_table: true

general_html_report:
final_directory_depth: 2

merge_cnv_json:
annotations:
cytobands:
Expand Down
6 changes: 6 additions & 0 deletions config/general_report.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
files:
- name: CNV report
type: file_link
description: Link to CNV HTML report
input: results/dna/cnv/{sample}_{type}/{sample}_{type}.pathology_purecn.cnv.html
nav_header: CNV
7 changes: 7 additions & 0 deletions config/output_files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@ files:
- name: "CNV HTML report"
input: "reports/cnv_html_report/{sample}_{type}.pathology.cnv_report.html"
output: "results/cnv/{sample}_{type}.pathology.cnv_report.html"
types:
- T
- name: "General Report"
input: "reports/general_html_report/{sample}_{type}.general_report.html"
output: "results/dna/reports/{sample}_{type}.general_report.html"
types:
- T
File renamed without changes.
22 changes: 22 additions & 0 deletions docs/softwares.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,25 @@ Merge JSON files from multiple CNV callers and add annotations and other sample
#### Resources settings (`resources.yaml`)

#RESOURCESSCHEMA__merge_cnv_json#

## general_html_report

Generate a general HTML report for a single sample.

### :snake: Rule

#SNAKEMAKE_RULE_SOURCE__general_html_report__general_html_report#

#### :left_right_arrow: input / output files

#SNAKEMAKE_RULE_TABLE__general_html_report__general_html_report#

### :wrench: Configuration

#### Software settings (`config.yaml`)

#CONFIGSCHEMA__general_html_report#

#### Resources settings (`resources.yaml`)

#RESOURCESSCHEMA__general_html_report#
30 changes: 30 additions & 0 deletions docs/tailwind.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Tailwind CSS

All reports in this repository share a single CSS file by default, and the content of this file is managed by [Tailwind](https://tailwindcss.com). This is a CSS framework that works with a very large number of minimal classes, which makes the styling very flexible without you having to write a single line of CSS. Since only the classes that are actually being used are included, the size of the resulting file can be kept down.

## Setup

Tailwind is available through [npm](https://www.npmjs.com/package/tailwindcss), but since there are no other Node.js dependencies in this project, it is recommended that you install the [standalone CLI tool](https://tailwindcss.com/blog/standalone-cli) instead. The binaries for various systems are [hosted on Github](https://github.com/tailwindlabs/tailwindcss/releases). Here is how to install on Linux:

```bash
curl -sLO https://github.com/tailwindlabs/tailwindcss/releases/download/v3.3.6/tailwindcss-linux-x64
chmod +x tailwindcss-linux-x64
mv tailwindcss-linux-x64 tailwindcss
```

Preferrably move this binary to a directory in your `$PATH`. Depending on the platform, the installation procedure might look different.

## Usage

The Tailwind configuration can be found in `tailwind.config.js`. By default, it will look for classes in all HTML and JS files in the `workflow/templates` directory. When actively working on a template, it is recommended that Tailwind is set to watch files for changes and edit the CSS file as it goes:

```bash
tailwindcss \
-i ./workflow/templates/assets/css/tailwind.css \
-o ./workflow/templates/assets/css/main.css \
--watch
```

In the example above, `./workflow/templates/assets/css/tailwind.css` is the input css file, and `./workflow/templates/assets/css/main.css` is the output css file which is used in the each template. This approach will make certain that each and every Tailwind class in use is available in the generated CSS file, and at the same time remove any unused classes.

When including this file in a template, it is recommended that it is minified. In order to keep the git history clean, the minified CSS should not be committed to the repo, but rather be something that is generated by the script of each individual report. <!-- TODO: add a reference to an example, as soon as there is one -->
2 changes: 2 additions & 0 deletions mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ nav:
- Introduction: intro.md
- Reports: reports.md
- Softwares: softwares.md
- Development:
- Tailwind CSS: tailwind.md

theme: readthedocs
extra_css: [extra.css]
Expand Down
8 changes: 8 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["workflow/templates/**/*.{html,js}"],
theme: {
extend: {},
},
plugins: [],
};
1 change: 1 addition & 0 deletions workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __license__ = "GPL-3"

# Include pipeline specific rules
include: "rules/common.smk"
include: "rules/general_html_report.smk"
include: "rules/cnv_html_report.smk"


Expand Down
9 changes: 8 additions & 1 deletion workflow/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import yaml
from snakemake.io import Wildcards
from snakemake.utils import validate
from snakemake.utils import min_version

from datetime import datetime
from hydra_genetics.utils.resources import load_resources
from hydra_genetics.utils.samples import *
from hydra_genetics.utils.units import *
Expand Down Expand Up @@ -45,6 +45,7 @@ units = (

validate(units, schema="../schemas/units.schema.yaml")


with open(config["output"]) as output:
if config["output"].endswith("json"):
output_spec = json.load(output)
Expand All @@ -53,6 +54,12 @@ with open(config["output"]) as output:

validate(output_spec, schema="../schemas/output_files.schema.yaml")

with open(config["general_report"]) as f:
if f.name.endswith(".yaml"):
general_report = yaml.safe_load(f)

validate(general_report, "../schemas/general_report.schema.yaml")


### Set wildcard constraints
wildcard_constraints:
Expand Down
Loading
Loading