Skip to content

Commit 5e02ab9

Browse files
author
Jen Reiter
authored
Merge pull request #1 from flywheel-apps/v0.1
V0.1
2 parents f952e3e + 412d569 commit 5e02ab9

File tree

5 files changed

+303
-0
lines changed

5 files changed

+303
-0
lines changed

Dockerfile

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# flywheel/siemens_to_ismrmrd
2+
3+
FROM ubuntu:14.04
4+
MAINTAINER Jennifer Reiter <[email protected]>
5+
6+
## Install Dependencies
7+
# g++, HDF5, Boost, CodeSynthesis XSD, TinyXML, Libxslt
8+
# Libxml2, Xerces-C XML parser library, Cmake build tool
9+
RUN apt-get update \
10+
&& apt-get install -y g++ \
11+
libhdf5-serial-dev \
12+
h5utils \
13+
hdf5-tools \
14+
libboost-all-dev \
15+
xsdcxx \
16+
libtinyxml-dev \
17+
libxslt1-dev \
18+
libxml2-dev \
19+
libxerces-c-dev \
20+
cmake
21+
22+
# Download the ISMRMRD code
23+
ADD https://github.com/ismrmrd/ismrmrd/archive/v1.3.2.tar.gz /
24+
# Unpack the tar.gz
25+
RUN tar -zxvf /v1.3.2.tar.gz
26+
RUN rm /v1.3.2.tar.gz
27+
# Set ISMRMRD environment variable
28+
ENV ISMRMRD_HOME /usr/local/ismrmrd
29+
# Rename the ismrmrd-1.3.2 directory to ISMRMRD_HOME
30+
RUN mv /ismrmrd-1.3.2 $ISMRMRD_HOME
31+
# Install ISMRMRD code
32+
RUN cd $ISMRMRD_HOME && \
33+
mkdir build && \
34+
cd build && \
35+
cmake .. && \
36+
make && \
37+
sudo make install && \
38+
sudo ldconfig
39+
40+
# SET LD_LIBRARY_PATH
41+
ENV LD_LIBRARY_PATH /usr/local/lib
42+
43+
# Download the Siemens to ISMRMRD code (v1.0.1)
44+
RUN mkdir /siemens_to_ismrmrd
45+
ADD https://github.com/ismrmrd/siemens_to_ismrmrd/archive/v1.0.1.tar.gz /siemens_to_ismrmrd
46+
# Unpack the tar.gz
47+
RUN cd /siemens_to_ismrmrd && tar -zxvf v1.0.1.tar.gz
48+
# Install
49+
RUN cd siemens_to_ismrmrd/siemens_to_ismrmrd-1.0.1 && \
50+
mkdir build && \
51+
cd build && \
52+
cmake .. && \
53+
make && \
54+
sudo make install
55+
56+
# Install wget in order to install jq
57+
RUN apt-get update && apt-get -y install wget
58+
# Install jq to parse the JSON config file
59+
RUN wget -N -qO- -O /usr/bin/jq http://stedolan.github.io/jq/download/linux64/jq
60+
RUN chmod +x /usr/bin/jq
61+
62+
# Make directory for flywheel spec (v0)
63+
ENV FLYWHEEL /flywheel/v0
64+
RUN mkdir -p ${FLYWHEEL}
65+
COPY manifest.json ${FLYWHEEL}
66+
67+
# Copy run script
68+
COPY run ${FLYWHEEL}/run
69+
RUN chmod +x ${FLYWHEEL}/run
70+
71+
# ENV preservation for Flywheel Engine
72+
RUN env -u HOSTNAME -u PWD > ${FLYWHEEL}/docker-env.sh
73+
74+
# Configure entrypoint
75+
ENTRYPOINT ["/flywheel/v0/run"]

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,34 @@
1+
[![Docker Pulls](https://img.shields.io/docker/pulls/flywheel/siemens_to_ismrmrd.svg)](https://hub.docker.com/r/flywheel/siemens_to_ismrmrd/)
2+
[![Docker Stars](https://img.shields.io/docker/stars/flywheel/siemens_to_ismrmrd.svg)](https://hub.docker.com/r/flywheel/siemens_to_ismrmrd/)
3+
14
# siemens_to_ismrmrd
25
Siemens to ISMRMRD converter
6+
7+
Build context for a [Flywheel Gear](https://github.com/flywheel-io/gears/tree/master/spec) which runs the `siemens_to_ismrmrd` tool (v1.0.1).
8+
For more information on the ISMRMRD format see [ISMRMRD's documentation](http://ismrmrd.github.io/)
9+
10+
* You can change ```build.sh``` to edit the repository name for the image (default=`flywheel/siemens_to_ismrmrd`).
11+
* The resulting image is ~1GB
12+
13+
### Build the Image
14+
To build the image:
15+
```
16+
git clone https://github.com/flywheel-apps/siemens_to_ismrmrd.git
17+
./build.sh
18+
```
19+
20+
### Example Local Usage
21+
To run the `siemens_to_ismrmrd` command in this image on your local instance, do the following:
22+
```
23+
docker run --rm -ti \
24+
-v </path/to/input/data>:/flywheel/v0/input/dat \
25+
-v </path/for/output/data>:/flywheel/v0/output \
26+
flywheel/siemens_to_ismrmrd
27+
```
28+
29+
Usage notes:
30+
* You are mounting the directory (using the ```-v``` flag) which contains the input data in the container at ```/flywheel/v0/input/``` and mounting the directory where you want your output data within the container at ```/flywheel/v0/output```.
31+
* The input directory should contain only the file you wish to convert (a .dat file)
32+
* If an alternate parameter map (.xml file) for conversion is desired, an optional directory can be mounted with the additional line ```-v </path/to/xml/data>:/flywheel/v0/input/user_map```
33+
* If an alternate stylesheet (.xsl file) for conversion is desired, an optional directory can be mounted with the additional line ```-v </path/to/xsl/data>:/flywheel/v0/input/user_stylesheet```
34+
* No input arguments are required for the container to be executed

build.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# Builds the container.
3+
# The container can be exported using the export.sh script
4+
CONTAINER=flywheel/siemens_to_ismrmrd
5+
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
6+
7+
docker build --tag $CONTAINER $DIR

manifest.json

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"author": "Souheil Inati, Michael Hansen, et al.",
3+
"config": {
4+
"debug": {
5+
"default": false,
6+
"description": "Debug XML flag. The debug flag outputs the following additional files: xml_raw.xml, processed.xml, config_buffer.xprot.",
7+
"type": "boolean"
8+
},
9+
"measNum": {
10+
"default": 1,
11+
"description": "Measurement number. Value used in the case of input VD file that contains multiple measurements.",
12+
"type": "integer"
13+
}
14+
},
15+
"custom": {
16+
"docker-image": "flywheel/siemens_to_ismrmrd:v0.1"
17+
},
18+
"description": "The Siemens to ISMRM-RD Converter (siemens_to_ismrmrd v1.0.1, ismrmrd v1.3.2) is used to convert data from Siemens raw data format (.dat) to ISMRM-RD raw data format (.h5).",
19+
"inputs": {
20+
"dat": {
21+
"base": "file",
22+
"description": "Input is a Siemens dat file. Dat file can be a VB file or a VD file. In case of VD file that contains multiple measurements, the user can specify which measurement to convert by using the config option 'measNum'.",
23+
"type": {
24+
"enum": [
25+
"Siemens MR Raw"
26+
]
27+
}
28+
},
29+
"user_map": {
30+
"base": "file",
31+
"description": "Parameter map XML file.",
32+
"name": {
33+
"pattern": "^.*.xml$"
34+
},
35+
"optional": true
36+
},
37+
"user_stylesheet": {
38+
"base": "file",
39+
"description": "Parameter stylesheet XSL file.",
40+
"name": {
41+
"pattern": "^.*.xsl$"
42+
},
43+
"optional": true
44+
}
45+
},
46+
"label": "Siemens to ISMRM-RD Converter (siemens_to_ismrmrd v1.0.1, ismrmrd v1.3.2)",
47+
"license": "Other",
48+
"maintainer": "Jennifer Reiter <[email protected]>",
49+
"name": "siemens-to-ismrmrd",
50+
"source": "https://github.com/flywheel-apps/siemens_to_ismrmrd",
51+
"url": "https://github.com/ismrmrd/siemens_to_ismrmrd",
52+
"version": "0.1"
53+
}

run

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#! /bin/bash
2+
# This script is meant to evoke the algorithm without requiring any input arguments
3+
#
4+
5+
# Define directory names
6+
FLYWHEEL_BASE=/flywheel/v0
7+
MANIFEST_FILE=$FLYWHEEL_BASE/manifest.json
8+
CONFIG_FILE=$FLYWHEEL_BASE/config.json
9+
# Base input directory
10+
INPUT_DIR=$FLYWHEEL_BASE/input
11+
# Siemens Dat directory
12+
DAT_DIR=$INPUT_DIR/dat
13+
# Optional XML and XSL directories
14+
USER_XML=$INPUT_DIR/user_map
15+
USER_XSL=$INPUT_DIR/user_stylesheet
16+
# Output
17+
OUTPUT_DIR=$FLYWHEEL_BASE/output
18+
19+
CONTAINER='[flywheel/siemens-to-ismrmrd]'
20+
21+
# Configure the ENV according to the original Docker image
22+
source ${FLYWHEEL_BASE}/docker-env.sh
23+
24+
# Check if the input directory is not empty
25+
if [[ "$(ls -A $INPUT_DIR)" ]] ; then
26+
echo "$CONTAINER Starting..."
27+
else
28+
echo "Input directory is empty: $INPUT_DIR"
29+
exit 1
30+
fi
31+
32+
# Check if XML directory is present
33+
if [[ -e $USER_XML ]] ; then
34+
xml_file=`find $USER_XML -iname '*.xml'`
35+
if [[ ! -e "$xml_file" ]]; then
36+
echo "No parameter map (.xml) was found within input directory $USER_XML"
37+
exit 1
38+
fi
39+
# Replace spaces with _
40+
xml_file_nospaces="${xml_file// /_}"
41+
mv "$xml_file" "$xml_file_nospaces"
42+
else
43+
xml_file_nospaces=""
44+
fi
45+
# Check if XSL directory is present
46+
if [[ -e $USER_XSL ]] ; then
47+
xsl_file=`find $USER_XSL -iname '*.xsl'`
48+
if [[ ! -e "$xsl_file" ]]; then
49+
echo "No parameter stylesheet (.xsl) was found within input directory $USER_XSL"
50+
exit 1
51+
fi
52+
# Replace spaces with _
53+
xsl_file_nospaces="${xsl_file// /_}"
54+
mv "$xsl_file" "$xsl_file_nospaces"
55+
else
56+
xsl_file_nospaces=""
57+
fi
58+
59+
# Find input file in input directory with the extension .dat
60+
input_file=`find $DAT_DIR -iname '*.dat'`
61+
bni=`basename "$input_file"`
62+
filename="${bni%%.*}"
63+
64+
# If input file found
65+
if [[ ! -e "$input_file" ]] ; then
66+
echo "No SIEMENS Raw file (.dat) was found within input directory $DAT_DIR"
67+
exit 1
68+
fi
69+
# Replace spaces with _
70+
filename_nospaces=${filename// /_}
71+
mv "$input_file" $DAT_DIR/$filename_nospaces.dat
72+
73+
# Get output file extension from config file, if it exists
74+
if [[ -e $CONFIG_FILE ]] ; then
75+
echo "Config file is present"
76+
debug=`cat $CONFIG_FILE | jq -r '.config.debug'`
77+
measNum=`cat $CONFIG_FILE | jq -r '.config.measNum'`
78+
else
79+
echo "Config file is not present, using default values"
80+
debug=`cat $MANIFEST_FILE | jq -r '.config.debug.default'`
81+
measNum=`cat $MANIFEST_FILE | jq -r '.config.measNum.default'`
82+
fi
83+
84+
### Sort through different configurations to add to command
85+
# Define debug command
86+
if [[ $debug = 'true' ]] ; then
87+
debug_cmd="--debug"
88+
else
89+
debug_cmd=""
90+
fi
91+
# Define measNum command
92+
if [[ $measNum = '1' ]] ; then
93+
# If measNum is 1, no need to add a command, that is the default
94+
# or the input file is VB and measNum does not apply
95+
measNum_cmd=""
96+
else
97+
measNum_cmd="--measNum $measNum"
98+
fi
99+
# Determine if XML file is given or pMap is defined
100+
if [[ $xml_file_nospaces ]] ; then
101+
pMap_cmd="--user-map $xml_file_nospaces"
102+
else
103+
pMap_cmd=""
104+
fi
105+
# Determine if XSL file is given or pMapStyle is defined
106+
if [[ $xsl_file_nospaces ]] ; then
107+
pMapStyle_cmd="--user-stylesheet $xsl_file_nospaces"
108+
else
109+
pMapStyle_cmd=""
110+
fi
111+
112+
## Call siemens_to_ismrmrd
113+
# cd into output directory incase of debug files being generated
114+
cd $OUTPUT_DIR && siemens_to_ismrmrd -f $DAT_DIR/$filename_nospaces.dat -o $OUTPUT_DIR/$filename_nospaces.h5 $debug_cmd $measNum_cmd $pMap_cmd $pMapStyle_cmd
115+
116+
# Rename the debug files, if present
117+
for debugfile in 'config_buffer.xprot' 'processed.xml' 'xml_raw.xml'
118+
do
119+
debugfile_full=$OUTPUT_DIR/$debugfile
120+
if [[ -e $debugfile_full ]] ; then
121+
mv $debugfile_full $OUTPUT_DIR/"$filename_nospaces"_"$debugfile"
122+
fi
123+
done
124+
125+
# Get a list of the files in the output directory
126+
outputs=`find $OUTPUT_DIR -type f -name "*"`
127+
# If outputs exist, then go on...
128+
if [[ -z $outputs ]] ; then
129+
echo "No results found in output directory... Exiting"
130+
exit 1
131+
else
132+
chmod -R 777 $OUTPUT_DIR
133+
echo -e "Wrote: `ls $OUTPUT_DIR`"
134+
fi
135+
136+
exit 0

0 commit comments

Comments
 (0)