Skip to content

Commit

Permalink
Merge pull request #60 from keara-soloway/chapbook-demo
Browse files Browse the repository at this point in the history
add: new Writer and galaxy tool for Chapbook demo
  • Loading branch information
keara-soloway authored Jun 28, 2023
2 parents ee1df7d + 743573b commit d90f34d
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHAP/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from CHAP.common.writer import (
ExtractArchiveWriter,
MatplotlibFigureWriter,
NexusWriter,
YAMLWriter,
TXTWriter,
Expand Down
31 changes: 31 additions & 0 deletions CHAP/common/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,37 @@ def write(self, data, filename):
return data


class MatplotlibFigureWriter(Writer):
"""Writer for saving matplotlib figures to image files."""
def write(self, data, filename, savefig_kw={}, force_overwrite=False):
"""Write the matplotlib.fgure.Figure contained in `data` to
the filename provided.
:param data: input containing a matplotlib figure
:type data: CHAP.pipeline.PipelineData
:param filename: name of the file to write to.
:param savefig_kw: keyword args to pass to
matplotlib.figure.Figure.savefig, defaults to {}
:type savefig_kw: dict, optional
:param force_overwrite: flag to allow data in `filename` to be
overwritten, if it already exists.
:return: the original input data
"""

if os.path.isfile(filename) and not force_overwrite:
raise FileExistsError(f'{filename} already exists')

figure = self.unwrap_pipelinedata(data)

from matplotlib.figure import Figure
if not isinstance(figure, Figure):
raise TypeError('Cannot write object of type'
f'{type(figure)} as a matplotlib Figure.')

figure.savefig(filename, **savefig_kw)
return figure


class NexusWriter(Writer):
"""Writer for NeXus files from `NXobject`-s"""
def write(self, data, filename, force_overwrite=False):
Expand Down
45 changes: 45 additions & 0 deletions galaxy-tools/chapbook_demo/chapbook_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<tool id="CHAP_chapbook_demo" name="CHAPbook" version="@TOOL_VERSION@+galaxy@VERSION_SUFFIX@" python_template_version="@PYTHON_TEMPLATE_VERSION@" profile="@PROFILE@">
<macros>
<import>../macros.xml</import>
</macros>
<requirements>
<expand macro="chap-requirement" />
<requirement type="package" version="1.0.1">nexusformat</requirement>
<requirement type="package" version="2023.3.0">pyfai</requirement>
<requirement type="package" version="1.10.7">pydantic</requirement>
</requirements>
<command detect_errors="exit_code"><![CDATA[
pip --exists-action i install certif-pyspec==1.5.3 &&
cd '$indir' &&
CHAP --config '$config'
]]></command>
<environment_variables>
<environment_variable name="PYTHONPATH">/home/chess_chapaas/chess/chap/</environment_variable>
</environment_variables>
<inputs>
<param type="data" name="config" format="yaml" label="Pipeline Configuration File" />
<param type="text" name="indir" label="Input Directory" />
</inputs>
<outputs>
<data name="data" format="nex" label="Reduced data"/>
<data name="plot" format="png" label="Plot"/>
</outputs>
<tests>
<test>
<param name="config" value="config.yaml"/>
<param name="indir" value="/tmp/"/>
</test>
</tests>
<help><![CDATA[
CHESS Analysis Pipeline (CHAP):
To run it on command line you'll use:
CHAP --config CONFIG
To run it within galaxy you'll only need to upload your
required configuration pipeline and necessary data.
]]></help>
<citations>
<expand macro="chap-citation" />
</citations>
</tool>

0 comments on commit d90f34d

Please sign in to comment.