Skip to content

Commit 1a39fe5

Browse files
committed
add md_to_pdf
1 parent 4b3268c commit 1a39fe5

17 files changed

+252
-74
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
**/results/
55
work/
66
**/deseq_out
7+
**/__pycache__
78

89
# Files to ignore
910
docs/overview.pdf

bin/md_to_pdf.py

Whitespace-only changes.
File renamed without changes.
File renamed without changes.
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# RNA-Seq Pipeline Overview
2+
3+
### <div class="job-title">{title}</div>
4+
5+
* __Prepared for__:
6+
7+
{prepared_for}
8+
9+
* __Prepared by__ : {prepared_by}
10+
11+
* __Process Executed on__ : {process_date}
12+
13+
<br>
14+
15+
---
16+
### Data Access
17+
* __Dropbox Folder__: {dropbox_folder}
18+
* __Dropbox URL__: [{dropbox_link}]({dropbox_link})
19+
20+
<br>
21+
22+
#### FASTQ files
23+
```
24+
{fastq_files}
25+
```
26+
27+
<br>
28+
29+
#### Gene Index files
30+
31+
Gene Index based on Wormbase Version: _{wormbase_version}_
32+
33+
---
34+
35+
### RNA Seq Process
36+
37+
<img src="./rna-seq-process-1-700.png" width=700>
38+
39+
### Pipeline Outputs
40+
41+
* MD5 Checksum Report
42+
* FAST QC Report
43+
* Multi QC Report
44+
* Isoform Quantification
45+
* Gene Quantification
46+
* DESeq2 Gene Normalizations (Up, Down, All Expressed) & Visualizations
47+
* WormCat Annotations and Visualizations of gene set enrichment data
48+
49+
### Source Code
50+
51+
The provided tagged repository is available to create reproducible outputs from the RNA-Seq Pipeline.
52+
53+
<div class="blue-background">
54+
55+
<table>
56+
<tr><td><b>Repo</b></td><td><a href="{github_release}">{github_release}</a></td></tr>
57+
<tr><td><b>Source</b></td><td><a href="{github_release}/{github_tag}">{github_release}/{github_tag}</a></td></tr>
58+
</table>
59+
60+
</div>
File renamed without changes.

bin/overview_report.py

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import subprocess
5+
import json
6+
import sys
7+
import os
8+
import markdown
9+
from markdown_include.include import MarkdownInclude
10+
from weasyprint import HTML
11+
12+
13+
REPORT_TEMPLATE_FILE="overview_report_template.md"
14+
15+
16+
def get_dropbox_link(remote_location):
17+
# rclone command to get dropbox link
18+
command = f'rclone link remote:"{remote_location}"'
19+
20+
try:
21+
output = subprocess.check_output(command, shell=True, text=True)
22+
dropbox_link = output.strip()
23+
return dropbox_link
24+
except subprocess.CalledProcessError as e:
25+
return f"Error: {str(e)}"
26+
27+
def get_fastq_names(remote_location):
28+
# rclone command to get fastq files
29+
command = f'rclone lsl remote:"{remote_location}" --human-readable|grep .fq.gz|sed "s/\.000000000//"'
30+
31+
try:
32+
output = subprocess.check_output(command, shell=True, text=True)
33+
return output
34+
except subprocess.CalledProcessError as e:
35+
return f"Error: {str(e)}"
36+
37+
38+
def generate_markdown_from_json(json_file):
39+
# Read JSON data from file
40+
with open(json_file, 'r') as file:
41+
json_data = json.load(file)
42+
43+
with open(REPORT_TEMPLATE_FILE, 'r') as file:
44+
report_template = file.read()
45+
46+
# Extract values from JSON data
47+
title = json_data['title']
48+
process_date = json_data['process_date']
49+
prepared_by = json_data['prepared_by']
50+
prepared_for = ""
51+
for person in json_data['prepared_for']:
52+
prepared_for += f" * {person} \n"
53+
54+
dropbox_folder = json_data['dropbox_folder']
55+
dropbox_link = get_dropbox_link(dropbox_folder)
56+
fastq_files = get_fastq_names(dropbox_folder)
57+
wormbase_version = json_data['wormbase_version']
58+
github_release = json_data['GitHub_release']
59+
github_tag = json_data['GitHub_tag']
60+
61+
markdown_content = report_template.format(title=title,
62+
process_date=process_date,
63+
prepared_by=prepared_by,
64+
prepared_for=prepared_for,
65+
dropbox_folder=dropbox_folder,
66+
dropbox_link=dropbox_link,
67+
fastq_files=fastq_files,
68+
wormbase_version=wormbase_version,
69+
github_release=github_release,
70+
github_tag=github_tag)
71+
72+
# Write Markdown content to output file
73+
with open('overview_report.md', 'w') as file:
74+
file.write(markdown_content)
75+
76+
print("Markdown file generated successfully.")
77+
78+
def convert_to_html(markdown_file_name, css_file_name):
79+
with open(markdown_file_name, mode="r", encoding="utf-8") as markdown_file:
80+
with open(css_file_name, mode="r", encoding="utf-8") as css_file:
81+
markdown_input = markdown_file.read()
82+
css_input = css_file.read()
83+
84+
markdown_path = os.path.dirname(markdown_file_name)
85+
markdown_include = MarkdownInclude(configs={"base_path": markdown_path})
86+
html = markdown.markdown(
87+
markdown_input, extensions=["extra", markdown_include, "meta", "tables"]
88+
)
89+
90+
return f"""
91+
<html>
92+
<head>
93+
<style>{css_input}</style>
94+
</head>
95+
<body>{html}</body>
96+
</html>
97+
"""
98+
99+
def convert_to_pdf(markdown_file_name, css_file_name):
100+
file_name = os.path.splitext(markdown_file_name)[0]
101+
html_string = convert_to_html(markdown_file_name, css_file_name)
102+
103+
with open(
104+
file_name + ".html", "w", encoding="utf-8", errors="xmlcharrefreplace"
105+
) as output_file:
106+
output_file.write(html_string)
107+
108+
markdown_path = os.path.dirname(markdown_file_name)
109+
html = HTML(string=html_string, base_url=markdown_path)
110+
html.write_pdf(file_name + ".pdf")
111+
112+
113+
def main():
114+
parser = argparse.ArgumentParser()
115+
parser.add_argument('-c', '--report-config', help='JSON Config file for report')
116+
#parser.add_argument('-o', '--output-path', help='The outpout path for the report')
117+
args = parser.parse_args()
118+
cmd_line_msg = "overview_report.py --report-config [<report.json>] --output-path [<base_directory>]"
119+
120+
if not args.report_config:
121+
print(cmd_line_msg)
122+
print("JSON Config is missing.")
123+
return
124+
125+
# if not args.output_path:
126+
# print(cmd_line_msg)
127+
# print("Ouput path is missing.")
128+
# return
129+
130+
generate_markdown_from_json(args.report_config)
131+
convert_to_pdf('overview_report.md','overview_report_template.css')
132+
133+
if __name__ == '__main__':
134+
main()
135+

docs/overview.md

-74
This file was deleted.

modules/de-seq-tools/main.nf

+2
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,5 @@ process CHECK_MD5 {
115115
path "md5_report.html"
116116

117117
}
118+
119+

modules/fastqc/main.nf

+18
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,21 @@ process FASTQC_SINGLE {
3636
"""
3737
}
3838

39+
process OVERVIEW_REPORT {
40+
container 'danhumassmed/qc-tools:1.0.1'
41+
publishDir params.outdir, mode:'copy'
42+
43+
input:
44+
path report_config
45+
46+
script:
47+
"""
48+
cp -r ${launchDir}/bin/md_to_pdf/* .
49+
${launchDir}/bin/overview_report.py --report-config "${report_config}"
50+
"""
51+
52+
output:
53+
path "overview_report.pdf"
54+
55+
}
56+
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env nextflow
2+
3+
// nextflow run pipelines/alex_byrne/06-overview-report-alex.nf -bg -N [email protected]
4+
5+
6+
nextflow.enable.dsl = 2
7+
8+
/*
9+
* RNA SEQ Pipeline
10+
*/
11+
12+
params.report_config = "${projectDir}/data/Experiment1/experiment1.json"
13+
params.outdir = "${projectDir}/results"
14+
15+
16+
log.info """\
17+
R N A S E Q - N F P I P E L I N E
18+
===================================
19+
report_config : ${params.report_config}
20+
outdir : ${params.outdir}
21+
"""
22+
23+
// import modules
24+
include { OVERVIEW_REPORT } from "${launchDir}/modules/fastqc"
25+
26+
/*
27+
* main script flow
28+
*/
29+
workflow {
30+
report_config_ch = channel.fromPath( params.report_config, checkIfExists: true )
31+
OVERVIEW_REPORT( report_config_ch )
32+
}
33+
34+
workflow.onComplete {
35+
log.info ( workflow.success ? "\nDone! Open the following report in your browser --> ${params.outdir}/overview_report.pdf\n" : "Oops .. something went wrong" )
36+
}

0 commit comments

Comments
 (0)