diff --git a/nanoplotter/plot.py b/nanoplotter/plot.py
index d4b90d7..61cbc1b 100644
--- a/nanoplotter/plot.py
+++ b/nanoplotter/plot.py
@@ -3,9 +3,15 @@
from io import BytesIO
from urllib.parse import quote as urlquote
import sys
-from kaleido.scopes.plotly import PlotlyScope
import logging
+# bring in kaleido and ensure Chrome is installed
+import kaleido
+# this will download a small headless Chrome build the first time you run it
+kaleido.get_chrome_sync()
+
+from kaleido import write_fig_sync
+
class Plot(object):
"""A Plot object is defined by a path to the output file and the title of the plot."""
@@ -27,12 +33,10 @@ def encode(self):
return self.encode1()
def encode1(self):
- """Return the base64 encoding of the figure file and insert in html image tag."""
data_uri = b64encode(open(self.path, "rb").read()).decode("utf-8").replace("\n", "")
return ''.format(data_uri)
def encode2(self):
- """Return the base64 encoding of the fig attribute and insert in html image tag."""
buf = BytesIO()
self.fig.savefig(buf, format="png", bbox_inches="tight", dpi=100)
buf.seek(0)
@@ -40,7 +44,7 @@ def encode2(self):
return ''.format(urlquote(string))
def save(self, settings):
- if not(self.only_report):
+ if not self.only_report:
if self.html:
with open(self.path, "w") as html_out:
html_out.write(self.html)
@@ -52,12 +56,10 @@ def save(self, settings):
p = os.path.splitext(self.path)[0] + ".png"
if os.path.exists(p):
os.remove(p)
-
logging.warning("No static plots are saved due to some kaleido problem:")
logging.warning(e)
elif self.fig:
- # if settings["format"] is a list, save the figure in all formats
if isinstance(settings["format"], list):
for fmt in settings["format"]:
self.fig.savefig(
@@ -66,7 +68,11 @@ def save(self, settings):
bbox_inches="tight",
)
else:
- self.fig.savefig(fname=self.path, format=settings["format"], bbox_inches="tight")
+ self.fig.savefig(
+ fname=self.path,
+ format=settings["format"],
+ bbox_inches="tight",
+ )
else:
sys.exit("No method to save plot object: no html or fig defined.")
@@ -77,9 +83,14 @@ def show(self):
sys.stderr.write(".show not implemented for Plot instance without fig attribute!")
def save_static(self, figformat):
- scope = PlotlyScope()
- with open(self.path.replace("html", figformat), "wb") as f:
- f.write(scope.transform(self.fig, format=figformat))
- logging.info(
- f"Saved {self.path.replace('.html', '')} as {figformat} (or png for --legacy)"
- )
+ """
+ Export a Plotly figure via Kaleido v1’s write_fig_sync.
+ """
+ output_path = self.path.replace(".html", f".{figformat}")
+ try:
+ write_fig_sync(self.fig, path=output_path)
+ logging.info(f"Saved {output_path} as {figformat}")
+ except Exception as e:
+ logging.warning("No static plots are saved due to some kaleido problem:")
+ logging.warning(e)
+
diff --git a/scripts/agm_test.sh b/scripts/agm_test.sh
new file mode 100644
index 0000000..ef2b4cd
--- /dev/null
+++ b/scripts/agm_test.sh
@@ -0,0 +1,16 @@
+#! /bin/bash
+
+#SBATCH --time=04-00:00:00
+#SBATCH --partition=defq
+#SBATCH --mail-user=myemail@email.org
+#SBATCH --mail-type=BEGIN,END,FAIL
+#SBATCH --ntasks-per-node=64
+#SBATCH --mem=128GB
+#SBATCH --nodes=1
+#SBATCH --job-name=nplot
+#SBATCH --comment=nplot
+
+source /path/to/nanoplot_env/bin/activate
+
+# test fresh nanoplot with kaleido update
+NanoPlot --fastq /path/to/test_file.fastq.gz --verbose --minqual 4 --color red -o scripts/agm_tests
diff --git a/scripts/agm_tests/LengthvsQualityScatterPlot_dot.html b/scripts/agm_tests/LengthvsQualityScatterPlot_dot.html
new file mode 100644
index 0000000..c976fa5
--- /dev/null
+++ b/scripts/agm_tests/LengthvsQualityScatterPlot_dot.html
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/scripts/agm_tests/LengthvsQualityScatterPlot_dot.png b/scripts/agm_tests/LengthvsQualityScatterPlot_dot.png
new file mode 100644
index 0000000..08c19a2
Binary files /dev/null and b/scripts/agm_tests/LengthvsQualityScatterPlot_dot.png differ
diff --git a/scripts/agm_tests/LengthvsQualityScatterPlot_kde.html b/scripts/agm_tests/LengthvsQualityScatterPlot_kde.html
new file mode 100644
index 0000000..de5ccef
--- /dev/null
+++ b/scripts/agm_tests/LengthvsQualityScatterPlot_kde.html
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/scripts/agm_tests/LengthvsQualityScatterPlot_kde.png b/scripts/agm_tests/LengthvsQualityScatterPlot_kde.png
new file mode 100644
index 0000000..1420914
Binary files /dev/null and b/scripts/agm_tests/LengthvsQualityScatterPlot_kde.png differ
diff --git a/scripts/agm_tests/NanoPlot-report.html b/scripts/agm_tests/NanoPlot-report.html
new file mode 100644
index 0000000..4f36cf6
--- /dev/null
+++ b/scripts/agm_tests/NanoPlot-report.html
@@ -0,0 +1,463 @@
+
+
+
+
+
+
+NanoPlot Report
+
+
+
NanoPlot statistics report
+
+
NanoPlot reports
+
Summary statistics prior to filtering
+
+
+
+
General summary
+
+
+
+
Mean read length
+
1,589.5
+
+
+
Mean read quality
+
16.1
+
+
+
Median read length
+
1,011.0
+
+
+
Median read quality
+
17.4
+
+
+
Number of reads
+
10,000.0
+
+
+
Read length N50
+
2,584.0
+
+
+
STDEV read length
+
1,606.4
+
+
+
Total bases
+
15,894,925.0
+
+
+
Number, percentage and megabases of reads above quality cutoffs
+
+
+
+
>Q10
+
10000 (100.0%) 15.9Mb
+
+
+
>Q15
+
7452 (74.5%) 12.6Mb
+
+
+
>Q20
+
2169 (21.7%) 4.0Mb
+
+
+
>Q25
+
192 (1.9%) 0.2Mb
+
+
+
>Q30
+
18 (0.2%) 0.0Mb
+
+
+
Top 5 highest mean basecall quality scores and their read lengths
+
+
+
+
1
+
35.0 (989)
+
+
+
2
+
34.5 (1715)
+
+
+
3
+
34.2 (489)
+
+
+
4
+
33.9 (307)
+
+
+
5
+
33.9 (511)
+
+
+
Top 5 longest reads and their mean basecall quality score
+
+
+
+
1
+
24951 (10.3)
+
+
+
2
+
21731 (17.8)
+
+
+
3
+
19385 (16.7)
+
+
+
4
+
18470 (18.7)
+
+
+
5
+
16459 (22.0)
+
+
+
+
Summary statistics after filtering
+
+
+
+
General summary
+
+
+
+
Mean read length
+
1,589.5
+
+
+
Mean read quality
+
16.1
+
+
+
Median read length
+
1,011.0
+
+
+
Median read quality
+
17.4
+
+
+
Number of reads
+
10,000.0
+
+
+
Read length N50
+
2,584.0
+
+
+
STDEV read length
+
1,606.4
+
+
+
Total bases
+
15,894,925.0
+
+
+
Number, percentage and megabases of reads above quality cutoffs
+
+
+
+
>Q10
+
10000 (100.0%) 15.9Mb
+
+
+
>Q15
+
7452 (74.5%) 12.6Mb
+
+
+
>Q20
+
2169 (21.7%) 4.0Mb
+
+
+
>Q25
+
192 (1.9%) 0.2Mb
+
+
+
>Q30
+
18 (0.2%) 0.0Mb
+
+
+
Top 5 highest mean basecall quality scores and their read lengths
+
+
+
+
1
+
35.0 (989)
+
+
+
2
+
34.5 (1715)
+
+
+
3
+
34.2 (489)
+
+
+
4
+
33.9 (307)
+
+
+
5
+
33.9 (511)
+
+
+
Top 5 longest reads and their mean basecall quality score
+
+
+
+
1
+
24951 (10.3)
+
+
+
2
+
21731 (17.8)
+
+
+
3
+
19385 (16.7)
+
+
+
4
+
18470 (18.7)
+
+
+
5
+
16459 (22.0)
+
+
+
+
Plots
+
+
Weighted histogram of read lengths
+
+
+
+
+
Weighted histogram of read lengths after log transformation
+
+
+
+
+
Non weighted histogram of read lengths
+
+
+
+
+
Non weighted histogram of read lengths after log transformation
+
+
+
+
+
Yield by length
+
+
+
+
+
Read lengths vs Average read quality plot using dots
\ No newline at end of file
diff --git a/scripts/agm_tests/Non_weightedHistogramReadlength.png b/scripts/agm_tests/Non_weightedHistogramReadlength.png
new file mode 100644
index 0000000..9a26424
Binary files /dev/null and b/scripts/agm_tests/Non_weightedHistogramReadlength.png differ
diff --git a/scripts/agm_tests/Non_weightedLogTransformed_HistogramReadlength.html b/scripts/agm_tests/Non_weightedLogTransformed_HistogramReadlength.html
new file mode 100644
index 0000000..815817d
--- /dev/null
+++ b/scripts/agm_tests/Non_weightedLogTransformed_HistogramReadlength.html
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/scripts/agm_tests/Non_weightedLogTransformed_HistogramReadlength.png b/scripts/agm_tests/Non_weightedLogTransformed_HistogramReadlength.png
new file mode 100644
index 0000000..c8ca09a
Binary files /dev/null and b/scripts/agm_tests/Non_weightedLogTransformed_HistogramReadlength.png differ
diff --git a/scripts/agm_tests/WeightedHistogramReadlength.html b/scripts/agm_tests/WeightedHistogramReadlength.html
new file mode 100644
index 0000000..32cafa7
--- /dev/null
+++ b/scripts/agm_tests/WeightedHistogramReadlength.html
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/scripts/agm_tests/WeightedHistogramReadlength.png b/scripts/agm_tests/WeightedHistogramReadlength.png
new file mode 100644
index 0000000..d08f891
Binary files /dev/null and b/scripts/agm_tests/WeightedHistogramReadlength.png differ
diff --git a/scripts/agm_tests/WeightedLogTransformed_HistogramReadlength.html b/scripts/agm_tests/WeightedLogTransformed_HistogramReadlength.html
new file mode 100644
index 0000000..ae51897
--- /dev/null
+++ b/scripts/agm_tests/WeightedLogTransformed_HistogramReadlength.html
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/scripts/agm_tests/WeightedLogTransformed_HistogramReadlength.png b/scripts/agm_tests/WeightedLogTransformed_HistogramReadlength.png
new file mode 100644
index 0000000..fee26fb
Binary files /dev/null and b/scripts/agm_tests/WeightedLogTransformed_HistogramReadlength.png differ
diff --git a/scripts/agm_tests/Yield_By_Length.html b/scripts/agm_tests/Yield_By_Length.html
new file mode 100644
index 0000000..0e94829
--- /dev/null
+++ b/scripts/agm_tests/Yield_By_Length.html
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/scripts/agm_tests/Yield_By_Length.png b/scripts/agm_tests/Yield_By_Length.png
new file mode 100644
index 0000000..8909d7e
Binary files /dev/null and b/scripts/agm_tests/Yield_By_Length.png differ