Skip to content

Commit

Permalink
--only-report option added (#346)
Browse files Browse the repository at this point in the history
* --only-report option added

* --only-report option added for barcoded too
  • Loading branch information
juanjo255 authored Oct 27, 2023
1 parent 241eca3 commit 63762a0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 25 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions nanoplot/NanoPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from nanoget import get_input
from nanoplot.filteroptions import filter_and_transform_data
from nanoplot.version import __version__
from nanoplotter.plot import Plot
import nanoplotter
import pickle
import sys
Expand Down Expand Up @@ -87,6 +88,9 @@ def main():
)
)

if args.only_report:
Plot.only_report = True

if args.barcoded:
main_path = settings["path"]
for barc in list(datadf["barcode"].unique()):
Expand Down
6 changes: 6 additions & 0 deletions nanoplot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ def get_args():
help="Output the stats file as a properly formatted TSV.",
action="store_true",
)
general.add_argument(
"--only-report",
help="Output only the report",
action="store_true",
default=False,
)
general.add_argument(
"--info_in_report", help="Add NanoPlot run info in the report.", action="store_true"
)
Expand Down
53 changes: 28 additions & 25 deletions nanoplotter/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class Plot(object):
"""A Plot object is defined by a path to the output file and the title of the plot."""

only_report = False

def __init__(self, path, title):
self.path = path
self.title = title
Expand Down Expand Up @@ -38,34 +40,35 @@ def encode2(self):
return '<img src="data:image/png;base64,{0}">'.format(urlquote(string))

def save(self, settings):
if self.html:
with open(self.path, "w") as html_out:
html_out.write(self.html)
if not settings["no_static"]:
try:
for fmt in settings["format"]:
self.save_static(fmt)
except (AttributeError, ValueError) as e:
p = os.path.splitext(self.path)[0] + ".png"
if os.path.exists(p):
os.remove(p)
if not(self.only_report):
if self.html:
with open(self.path, "w") as html_out:
html_out.write(self.html)
if not settings["no_static"]:
try:
for fmt in settings["format"]:
self.save_static(fmt)
except (AttributeError, ValueError) as e:
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)
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(
fname=self.path + "." + fmt,
format=fmt,
bbox_inches="tight",
)
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(
fname=self.path + "." + fmt,
format=fmt,
bbox_inches="tight",
)
else:
self.fig.savefig(fname=self.path, format=settings["format"], bbox_inches="tight")
else:
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.")
sys.exit("No method to save plot object: no html or fig defined.")

def show(self):
if self.fig:
Expand Down

0 comments on commit 63762a0

Please sign in to comment.