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

Add SlicerRadiomicsCLI #37

Merged
merged 4 commits into from Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Expand Up @@ -33,9 +33,14 @@ if(${EXTENSION_NAME}_SUPERBUILD)
return()
endif()

#-----------------------------------------------------------------------------
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(SlicerRadiomicsAddCLI)

#-----------------------------------------------------------------------------
# Extension modules
add_subdirectory(SlicerRadiomics)
add_subdirectory(SlicerRadiomicsCLI)
## NEXT_MODULE

#-----------------------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,21 @@
Copyright 2018 Harvard Medical School

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7 changes: 7 additions & 0 deletions SlicerRadiomicsCLI/CMakeLists.txt
@@ -0,0 +1,7 @@

set(MODULE_NAME SlicerRadiomicsCLI)

SlicerRadiomicsAddCLI(
NAME ${MODULE_NAME}
)

13 changes: 13 additions & 0 deletions SlicerRadiomicsCLI/SlicerRadiomicsCLI
@@ -0,0 +1,13 @@
#!/usr/bin/env python-real
# -*- coding: utf-8 -*-

import sys
from radiomics.scripts import commandline

if __name__ == '__main__':
if sys.argv[1] == '--xml' or sys.argv[1] == '-x':
with open(__file__ + '.xml', 'r') as xmlFP:
print(xmlFP.read())
else:
sys.argv.append('--format=csv') # Append this format to ensure a csv return format (default is txt)
commandline.main() # Entry point for the "pyradiomics" script
1 change: 1 addition & 0 deletions SlicerRadiomicsCLI/SlicerRadiomicsCLI.bat
@@ -0,0 +1 @@
python-real.exe %~dp0SlicerRadiomicsCLI %*
41 changes: 41 additions & 0 deletions SlicerRadiomicsCLI/SlicerRadiomicsCLI.xml
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<executable>
<category>Informatics</category>
<title>RadiomicsCLI</title>
<description><![CDATA[This provides a commandline interface to access to the radiomics feature extraction implemented in pyradiomics library. See more details at http://pyradiomics.readthedocs.io/.]]></description>
<version>1.0.0</version>
<documentation-url>https://www.slicer.org/wiki/Documentation/Nightly/Extensions/Radiomics</documentation-url>
<license>3-Clause BSD License</license>
<contributor>Andrey Fedorov (BWH), Nicole Aucoin (BWH), Jean-Christophe Fillion-Robin (Kitware), Joost van Griethuysen (AVL-NKI), Hugo Aerts (DFCI)</contributor>
<acknowledgements><![CDATA[This work was partially supported by NIH/NCI ITCR program grant U24 CA194354.]]></acknowledgements>
<parameters>
<label>IO</label>
<description><![CDATA[Input/output parameters]]></description>
<image>
<name>Image</name>
<label>input Source Image</label>
<channel>input</channel>
<index>0</index>
<description><![CDATA[Input image volume to extract features from]]></description>
</image>
<image>
<name>Mask</name>
<label>input Label map</label>
<channel>input</channel>
<index>1</index>
<description><![CDATA[Input label map volume defining the ROI to extract features from]]></description>
</image>
<table fileExtensions=".csv">
<longflag alias="o">out</longflag>
<label>Results</label>
<channel>output</channel>
<description><![CDATA[calculated results]]></description>
</table>
<file fileExtensions=".yaml,.yml,.json">
<longflag alias="p">param</longflag>
<label>customization parameter file</label>
<channel>input</channel>
<description><![CDATA[YAML or JSON structured file defining the customization that is to be applied.]]></description>
</file>
</parameters>
</executable>
109 changes: 109 additions & 0 deletions cmake/SlicerRadiomicsAddCLI.cmake
@@ -0,0 +1,109 @@
################################################################################
#
# Program: SlicerRadiomics
#
# Copyright (c) Kitware Inc.
#
# See LICENSE.txt
#
# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
# and was partially funded by NIH grant 1U24CA194354-01
#
################################################################################

# This CMake module defines the function SlicerRadiomicsAddCLI.

#
# SlicerRadiomicsAddCLI
# =====================
#
# Add a shell script-based Slicer CLI to the build system.
#
# SlicerRadiomicsAddCLI(
# NAME <module_name>
# )
#
# NAME This is the name of the CLI to configure and install. It expects the following
# files to exist in the current directory:
# <module_name>
# <module_name>.bat
# <module_name>.xml
#
# Notes:
#
# * The function adds a custom target named ``Copy<module_name>Scripts``
# responsible to copy module files into ``SlicerExecutionModel_DEFAULT_CLI_RUNTIME_OUTPUT_DIRECTORY``.
#
# * The function adds an install rule associated with ``RuntimeLibraries`` component that will install
# the module files into ``SlicerExecutionModel_DEFAULT_CLI_INSTALL_RUNTIME_DESTINATION``.
#
# * The list of module files is composed differently based on the platform:
# - Unix: <module_name> and <module_name>.xml
# - Windows: <module_name>, <module_name>.bat and <module_name>.xml
#
function(SlicerRadiomicsAddCLI)
set(options
)
set(oneValueArgs
NAME
)
set(multiValueArgs
)
cmake_parse_arguments(MY
"${options}"
"${oneValueArgs}"
"${multiValueArgs}"
${ARGN}
)
message(STATUS "Configuring SEM CLI module: ${MY_NAME}")

# Sanity checks
set(expected_defined_vars
SlicerExecutionModel_DEFAULT_CLI_RUNTIME_OUTPUT_DIRECTORY
SlicerExecutionModel_DEFAULT_CLI_INSTALL_RUNTIME_DESTINATION
)
foreach(var IN LISTS expected_defined_vars)
if(NOT DEFINED ${var})
message(FATAL_ERROR "Variable ${var} is not defined !")
endif()
endforeach()

set(expected_parameters
NAME
)
foreach(param IN ITEMS NAME)
if(NOT MY_${param})
message(FATAL_ERROR "Parameter ${param} is expected !")
endif()
endforeach()

set(cli_files
"${MY_NAME}"
"${MY_NAME}.xml"
)
if(WIN32)
list(APPEND cli_files
"${MY_NAME}.bat"
)
endif()

set(build_dir ${SlicerExecutionModel_DEFAULT_CLI_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR})
set(copy_commands )
foreach(cli_file IN LISTS cli_files)
list(APPEND copy_commands
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${cli_file} ${build_dir}/${cli_file}
)
endforeach()

add_custom_target(Copy${MY_NAME}Scripts ALL
${copy_commands}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Copying ${MY_NAME} files into build directory"
)

install(FILES ${cli_files}
DESTINATION ${SlicerExecutionModel_DEFAULT_CLI_INSTALL_RUNTIME_DESTINATION}
COMPONENT RuntimeLibraries
)

endfunction()