Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tools/isa-extractor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
planemo-venv
tool_test_output.*
dist
.Rproj.user
11 changes: 11 additions & 0 deletions tools/isa-extractor/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
dist: bionic

notifications:
email:
recipients:
- [email protected]

script:
- make test
- make plint
- make ptest
46 changes: 46 additions & 0 deletions tools/isa-extractor/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
SCRIPT_NAME=extract-from-isa
REPOS_NAME=isaextractor
TOOLS_XML=$(wildcard isa2*.xml)

all:

test:
make -C $@

planemo-venv/bin/planemo: planemo-venv
. planemo-venv/bin/activate && pip install --upgrade pip setuptools
. planemo-venv/bin/activate && pip install planemo

planemo-venv:
virtualenv -p python2.7 $@

plint: planemo-venv/bin/planemo
. planemo-venv/bin/activate && planemo lint $(TOOLS_XML)

ptest: planemo-venv/bin/planemo
. planemo-venv/bin/activate && planemo test --conda_dependency_resolution --galaxy_branch release_19.01 $(TOOLS_XML)

dist/$(REPOS_NAME)/:
mkdir -p $@
cp -Lr README.md $(SCRIPT_NAME) $(TOOLS_XML) test-data $@

ptesttoolshed_diff: dist/$(REPOS_NAME)/ planemo-venv/bin/planemo
. planemo-venv/bin/activate && cd $< && planemo shed_diff --shed_target testtoolshed

ptesttoolshed_update: dist/$(REPOS_NAME)/ planemo-venv/bin/planemo
. planemo-venv/bin/activate && cd $< && planemo shed_update --check_diff --shed_target testtoolshed

ptoolshed_diff: dist/$(REPOS_NAME)/ planemo-venv/bin/planemo
. planemo-venv/bin/activate && cd $< && planemo shed_diff --shed_target toolshed

ptoolshed_update: dist/$(REPOS_NAME)/ planemo-venv/bin/planemo
. planemo-venv/bin/activate && cd $< && planemo shed_update --check_diff --shed_target toolshed

clean:
$(RM) -r $(HOME)/.planemo
$(RM) -r planemo-venv
make -C test $@
$(RM) tool_test_output.*
$(RM) -r dist

.PHONY: all clean test planemolint planemotest
12 changes: 12 additions & 0 deletions tools/isa-extractor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ISA extractor

[![Build Status](https://travis-ci.org/workflow4metabolomics/isa-extractor.svg?branch=master)](https://travis-ci.org/workflow4metabolomics/isa-extractor)

Extract collections of raw data files (mzML, mzXML, netCDF, mzData or nmrML) from an ISA study.

## Updates

### 1.3.0

* Wrote planemo tests for all tools.
* Run tests in Travis-CI.
130 changes: 130 additions & 0 deletions tools/isa-extractor/extract-from-isa
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/bin/bash
# vi: fdm=marker

# Constants {{{1
################################################################

PROG_NAME=$(basename $0)
PROG_PATH=$(dirname $0)
YES=yes
NO=no

# Global variables {{{1
################################################################

DEBUG=0
EXT=
INPUT_DIR=
OUTPUT_DIR=
SYMLINK=$NO

# Print help {{{1
################################################################

function print_help {
echo "Usage: $PROG_NAME -i <ISA_DIR> -e <EXT> -o <OUTPUT_DIR>"
echo
echo "Extract files with a given extension from ISA-Tab archives into a collection."
echo
echo "Options:"
echo " -e, --ext EXT The extension of the files to find."
echo " -h, --help Print this help message."
echo " -i, --input DIR Input directory containing ISA archive."
echo " -o, --output DIR Set the output directory to use."
echo " -s, --symlink Create symbolic links instead of copying files."
}

# Error {{{1
################################################################

function error {

local msg=$1

echo "ERROR: $msg" >&2

exit 1
}

# Print debug msg {{{1
################################################################

function print_debug_msg {

local dbglvl=$1
local dbgmsg=$2

[ $DEBUG -ge $dbglvl ] && echo "[DEBUG] $dbgmsg" >&2
}

# Read args {{{1
################################################################

function read_args {

local args="$*" # save arguments for debugging purpose

# Read options
while true ; do
shift_count=1
case $1 in
-e|--ext) EXT="$2" ; shift_count=2 ;;
-g|--debug) DEBUG=$((DEBUG + 1)) ;;
-h|--help) print_help ; exit 0 ;;
-i|--input) INPUT_DIR="$2" ; shift_count=2 ;;
-o|--output) OUTPUT_DIR="$2" ; shift_count=2 ;;
-s|--symlink) SYMLINK=$YES ;;
-) error "Illegal option $1." ;;
--) error "Illegal option $1." ;;
--*) error "Illegal option $1." ;;
-?) error "Unknown option $1." ;;
-[^-]*) split_opt=$(echo $1 | sed 's/^-//' | sed 's/\([a-zA-Z]\)/ -\1/g') ; set -- $1$split_opt "${@:2}" ;;
*) break
esac
shift $shift_count
done
shift $((OPTIND - 1))

# Debug
print_debug_msg 1 "Arguments are : $args"

# Check input params
[[ $# -eq 0 ]] || error "No remaining arguments are allowed."
[[ -n $INPUT_DIR ]] || error "You must specify an input directory, using -i option."
[[ -d $INPUT_DIR ]] || error "\"$INPUT_DIR\" is not a valid directory."
[[ -n $OUTPUT_DIR ]] || error "You must specify an output directory, using -o option."
[[ ! -e $OUTPUT_DIR ]] || error "\"$OUTPUT_DIR\" already exists."
[[ -n $EXT ]] || error "You must specify the extension of the files you are looking for, with the -e option."
}

# MAIN {{{1
################################################################

read_args "$@"

# Create output directory
print_debug_msg 1 "Create output directory \"$OUTPUT_DIR\"."
mkdir -p "$OUTPUT_DIR"

# Find files to extract
print_debug_msg 1 "Find \"$EXT\" files to extract in \"$INPUT_DIR\"."
files_to_extract=$(mktemp -t tmp.XXXXXX)
find "$(realpath $INPUT_DIR)" -iname "*.$EXT" >files_to_extract
print_debug_msg 1 "Files to extract:"
if [[ $DEBUG -ge 1 ]] ; then
cat files_to_extract >&2
fi

# Extract files
if [[ $SYMLINK == $YES ]] ; then
print_debug_msg 1 "Create symbolic links of all \"$EXT\" files to extract into \"$OUTPUT_DIR\"."
xargs -I % ln -s % "$OUTPUT_DIR" <files_to_extract
else
print_debug_msg 1 "Copy all \"$EXT\" files to extract to \"$OUTPUT_DIR\"."
xargs -I % cp % "$OUTPUT_DIR" <files_to_extract
fi
rm files_to_extract
print_debug_msg 1 "Files extracted:"
if [[ $DEBUG -ge 1 ]] ; then
ls -1 "$OUTPUT_DIR" >&2
fi
18 changes: 18 additions & 0 deletions tools/isa-extractor/isa-extractor.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Makefile
77 changes: 77 additions & 0 deletions tools/isa-extractor/isa2mzdata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!-- vi: se fdm=marker : -->
<tool id="isa2mzdata" name="ISA to mzData" version="1.3.0">

<description>Extract mzData files from an ISA dataset and output a collection of mzData dataset.</description>

<!-- Command {{{1 -->

<command><![CDATA[
## @@@BEGIN_CHEETAH@@@

$__tool_directory__/extract-from-isa
-i "$isa.extra_files_path"
-e mzData
-o mzData

## @@@END_CHEETAH@@@
]]></command>

<!-- Inputs {{{1 -->

<inputs>
<param name="isa" label="ISA" type="data" format="isa-tab"/>
</inputs>

<!-- Outputs {{{1 -->

<outputs>
<collection name="mzData" type="list" label="mzData files">
<discover_datasets pattern="(?P&lt;designation&gt;.+)\.[mM][zZ][dD][aA][tT][aA]$" directory="mzData" format="mzdata"/>
</collection>
</outputs>

<!-- Tests {{{1 -->
<tests>
<test>
<param name="isa" value="mzdata_study.zip" ftype="isa-tab"/>
<output_collection name="mzData" type="list" count="1">
<element name="empty" file="mzdata_study_output/empty.mzData" ftype="mzdata"/>
</output_collection>
</test>
</tests>

<!-- Help {{{1 -->
<help>
<!-- @@@BEGIN_RST@@@ -->

====================
ISA to mzData
====================

Extract mzData files contained inside an ISA archive.

-----
Input
-----

ISA dataset
===========

The ISA-Tab dataset from which to extract the files.

------
Output
------

The output is a collection of mzData files.

<!-- @@@END_RST@@@ -->
</help>

<!-- Citations {{{1 -->
<citations>
<citation type="doi">10.1038/ng.1054</citation> <!-- ISA -->
<citation type="doi">10.1093/bioinformatics/btu813</citation> <!-- W4M -->
</citations>

</tool>
77 changes: 77 additions & 0 deletions tools/isa-extractor/isa2mzml.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<!-- vi: se fdm=marker : -->
<tool id="isa2mzml" name="ISA to mzML" version="1.3.0">

<description>Extract mzML files from an ISA dataset and output a collection of mzML dataset.</description>

<!-- Command {{{1 -->

<command><![CDATA[
## @@@BEGIN_CHEETAH@@@

$__tool_directory__/extract-from-isa
-i "$isa.extra_files_path"
-e mzML
-o mzML

## @@@END_CHEETAH@@@
]]></command>

<!-- Inputs {{{1 -->

<inputs>
<param name="isa" label="ISA" type="data" format="isa-tab"/>
</inputs>

<!-- Outputs {{{1 -->

<outputs>
<collection name="mzML" type="list" label="mzML files">
<discover_datasets pattern="(?P&lt;designation&gt;.+)\.[mM][zZ][mM][lL]$" directory="mzML" format="mzml"/>
</collection>
</outputs>

<!-- Tests {{{1 -->
<tests>
<test>
<param name="isa" value="mzml_study.zip" ftype="isa-tab"/>
<output_collection name="mzML" type="list" count="1">
<element name="empty" file="mzml_study_output/empty.mzML" ftype="mzml"/>
</output_collection>
</test>
</tests>

<!-- Help {{{1 -->
<help>
<!-- @@@BEGIN_RST@@@ -->

====================
ISA to mzML
====================

Extract mzML files contained inside an ISA archive.

-----
Input
-----

ISA dataset
===========

The ISA-Tab dataset from which to extract the files.

------
Output
------

The output is a collection of mzML files.

<!-- @@@END_RST@@@ -->
</help>

<!-- Citations {{{1 -->
<citations>
<citation type="doi">10.1038/ng.1054</citation> <!-- ISA -->
<citation type="doi">10.1093/bioinformatics/btu813</citation> <!-- W4M -->
</citations>

</tool>
Loading
Loading