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

Feature/symlink #15

Merged
merged 2 commits into from
Jul 31, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions extract-from-isa
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

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

# Global variables {{{1
################################################################
Expand All @@ -14,6 +16,7 @@ DEBUG=0
EXT=
INPUT_DIR=
OUTPUT_DIR=
SYMLINK=$NO

# Print help {{{1
################################################################
Expand All @@ -28,6 +31,7 @@ function print_help {
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
Expand Down Expand Up @@ -69,6 +73,7 @@ function read_args {
-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." ;;
Expand Down Expand Up @@ -104,15 +109,20 @@ 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 "$INPUT_DIR" -iname "*.$EXT" >files_to_extract
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
print_debug_msg 1 "Copy \"$EXT\" files to extract to \"$OUTPUT_DIR\"."
xargs -I % cp % "$OUTPUT_DIR" <files_to_extract
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
Expand Down
2 changes: 1 addition & 1 deletion isa2mzdata.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- vi: se fdm=marker : -->
<tool id="isa2mzdata" name="ISA to mzData" version="1.1.3">
<tool id="isa2mzdata" name="ISA to mzData" version="1.2.0">

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

Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*_extract
mtbls291-mzmls
fake_mzml_study_extract_symlinks
41 changes: 33 additions & 8 deletions test/test-extract-from-isa
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,49 @@ function error {
################################################################

function test_study {
study_name=$1
ext=$2
n_expected_files=$3
input_path="$PROG_PATH/res/${study_name}"
output_path="$PROG_PATH/${study_name}_extract"
local study_name=$1
local ext=$2
local n_expected_files=$3
local input_path="$PROG_PATH/res/${study_name}"
local output_path="$PROG_PATH/${study_name}_extract"

# Remove existing output
rm -rf "$output_path"

# Call program
"$PROG_PATH/../extract-from-isa" -i "$input_path" -o "$output_path" -e $ext
"$PROG_PATH/../extract-from-isa" -i "$input_path" -o "$output_path" -e $ext || exit 1

# Check output
n_files=$(ls "$output_path/" | wc -l)
n_right_ext_files=$(find "$output_path" -iname "*.$ext" | wc -l)
local n_files=$(ls "$output_path/" | wc -l)
local n_right_ext_files=$(find "$output_path" -iname "*.$ext" | wc -l)
[[ $n_files -eq $n_expected_files ]] || error "Error while extracting $ext files from $study_name. Extracted $n_files instead of $n_expected_files."
[[ $n_files -eq $n_right_ext_files ]] || error "Error while extracting $ext files from $study_name. $n_right_ext_files extracted files have the right extension. Was expecting $n_expected_files."
}

# Test symbolic links {{{1
################################################################

test_symlinks() {

local study_name=fake_mzml_study
local ext=mzML
local n_expected_files=1
local input_path="$PROG_PATH/res/${study_name}"
local output_path="$PROG_PATH/${study_name}_extract_symlinks"

# Remove existing output
rm -rf "$output_path"

# Call program
"$PROG_PATH/../extract-from-isa" -i "$input_path" -o "$output_path" -e $ext -s || exit 1

# Check output
local n_files=$(ls "$output_path/" | wc -l)
[[ $n_files -eq $n_expected_files ]] || error "Error while extracting $ext files from $study_name. Extracted $n_files instead of $n_expected_files."
extracted_file=$(ls "$output_path/")
[[ -L $output_path/$extracted_file ]] || error "Extracted file $output_path/$extracted_file is not a symbolic link."
}

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

Expand All @@ -53,3 +77,4 @@ test_study fake_mzxml_study mzXML 1
test_study fake_nmrml_study nmrML 1
test_study fake_netcdf_study CDF 1
test_study fake_case_insensitive_mzml_study mzML 3
test_symlinks