diff --git a/lib/galaxy/tools/__init__.py b/lib/galaxy/tools/__init__.py index 121a7bf6f91..39357284d9a 100644 --- a/lib/galaxy/tools/__init__.py +++ b/lib/galaxy/tools/__init__.py @@ -202,6 +202,9 @@ WORKFLOW_SAFE_TOOL_VERSION_UPDATES = { '__BUILD_LIST__': safe_update(packaging.version.parse("1.0.0"), packaging.version.parse("1.0.1")), '__APPLY_RULES__': safe_update(packaging.version.parse("1.0.0"), packaging.version.parse("1.1.0")), '__EXTRACT_DATASET__': safe_update(packaging.version.parse("1.0.0"), packaging.version.parse("1.0.1")), + 'Grep1': safe_update(packaging.version.parse("1.0.1"), packaging.version.parse("1.0.2")), + 'Show beginning1': safe_update(packaging.version.parse("1.0.0"), packaging.version.parse("1.0.1")), + 'Show tail1': safe_update(packaging.version.parse("1.0.0"), packaging.version.parse("1.0.1")), } diff --git a/tools/filters/grep.py b/tools/filters/grep.py deleted file mode 100644 index fad39281aac..00000000000 --- a/tools/filters/grep.py +++ /dev/null @@ -1,137 +0,0 @@ -# Filename: grep.py -# Author: Ian N. Schenck -# Version: 8/23/2005 -# -# This script accepts regular expressions, as well as an "invert" -# option, and applies the regular expression using grep. This wrapper -# provides security and pipeline. -# -# Grep is launched based on these inputs: -# -i Input file -# -o Output file -# -pattern RegEx pattern -# -v true or false (output NON-matching lines) -from __future__ import print_function - -import os -import re -import subprocess -import sys -from subprocess import PIPE, Popen -from tempfile import NamedTemporaryFile - - -# This function is exceedingly useful, perhaps package for reuse? -def getopts(argv): - opts = {} - while argv: - if argv[0][0] == '-': - opts[argv[0]] = argv[1] - argv = argv[2:] - else: - argv = argv[1:] - return opts - - -def main(): - args = sys.argv[1:] - - try: - opts = getopts(args) - except IndexError: - print("Usage:") - print(" -i Input file") - print(" -o Output file") - print(" -pattern RegEx pattern") - print(" -v true or false (Invert match)") - return 0 - - outputfile = opts.get("-o") - if outputfile is None: - print("No output file specified.") - return -1 - - inputfile = opts.get("-i") - if inputfile is None: - print("No input file specified.") - return -2 - - invert = opts.get("-v") - if invert is None: - print("Match style (Invert or normal) not specified.") - return -3 - - pattern = opts.get("-pattern") - if pattern is None: - print("RegEx pattern not specified.") - return -4 - - # All inputs have been specified at this point, now validate. - - # replace if input has been escaped, remove sq - # characters that are allowed but need to be escaped - mapped_chars = {'>': '__gt__', - '<': '__lt__', - '\'': '__sq__', - '"': '__dq__', - '[': '__ob__', - ']': '__cb__', - '{': '__oc__', - '}': '__cc__'} - - # with new sanitizing we only need to replace for single quote, - # but this needs to remain for backwards compatibility - for key, value in mapped_chars.items(): - pattern = pattern.replace(value, key) - - # match filename and invert flag - fileRegEx = re.compile(r"^[A-Za-z0-9./\-_]+$") - invertRegEx = re.compile(r"(true)|(false)") - - # verify that filename and inversion flag are in the correct format - if not fileRegEx.match(outputfile): - print("Illegal output filename.") - return -5 - if not fileRegEx.match(inputfile): - print("Illegal input filename.") - return -6 - if not invertRegEx.match(invert): - print("Illegal invert option.") - return -7 - - # invert grep search? - if invert == "true": - invertflag = "-v" - print("Not matching pattern: %s" % pattern) - else: - invertflag = "" - print("Matching pattern: %s" % pattern) - - # set version flag - versionflag = "-P" - - # MacOS 10.8.2 does not support -P option for perl-regex anymore - versionmatch = Popen("grep -V | grep 'BSD'", shell=True, stdout=PIPE).communicate()[0] - if versionmatch: - versionflag = "-E" - - # create temp file holding pattern - # by using a file to hold the pattern, we don't have worry about sanitizing grep commandline and can include single quotes in pattern - pattern_file_name = NamedTemporaryFile().name - open(pattern_file_name, 'w').write(pattern) - - # generate grep command - commandline = "grep %s %s -f %s %s > %s" % (versionflag, invertflag, pattern_file_name, inputfile, outputfile) - - # run grep - errorcode = subprocess.call(commandline, shell=True) - - # remove temp pattern file - os.unlink(pattern_file_name) - - # return error code - return errorcode - - -if __name__ == "__main__": - main() diff --git a/tools/filters/grep.xml b/tools/filters/grep.xml index c904bb4c769..e388b932dfe 100644 --- a/tools/filters/grep.xml +++ b/tools/filters/grep.xml @@ -1,36 +1,73 @@ - + + + grep + lines that match an expression operation_3695 - grep.py -i $input -o $out_file1 -pattern '$pattern' -v $invert + + + + '$out_file1' && + tail -n +2 '$input' + #else + cat '$input' + #end if + | grep -f '$pattern_file' $invert > '$out_file1' + ]]> + + $pattern + - - + + - - - - + - + - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/filters/headWrapper.pl b/tools/filters/headWrapper.pl deleted file mode 100644 index 89aa006fb5a..00000000000 --- a/tools/filters/headWrapper.pl +++ /dev/null @@ -1,18 +0,0 @@ -#! /usr/bin/env perl - -use strict; -use warnings; - -# a wrapper for head for use in galaxy -# headWrapper.pl [filename] [# lines to show] [output] - -die "Check arguments" unless @ARGV == 3; -die "Line number must be an integer\n" unless $ARGV[1]=~ m/^\d+$/; - -open (OUT, ">$ARGV[2]") or die "Cannot create $ARGV[2]:$!\n"; -open (HEAD, "head -n $ARGV[1] $ARGV[0]|") or die "Cannot run head:$!\n"; -while () { - print OUT; -} -close OUT; -close HEAD; diff --git a/tools/filters/headWrapper.xml b/tools/filters/headWrapper.xml index 477f1f77684..30776b148ac 100644 --- a/tools/filters/headWrapper.xml +++ b/tools/filters/headWrapper.xml @@ -1,23 +1,51 @@ - + lines from a dataset operation_3695 - -perl '$__tool_directory__/headWrapper.pl' '$input' $lineNum '$out_file1' - + + coreutils + + '$out_file1' && + tail -n +2 '$input' + #else + cat '$input' + #end if + | head -n $lineNum + >> '$out_file1' + ]]> - + + - + - + + + + + + + + + + + + + + + + + diff --git a/tools/filters/tailWrapper.pl b/tools/filters/tailWrapper.pl deleted file mode 100644 index 35e7d4ee51c..00000000000 --- a/tools/filters/tailWrapper.pl +++ /dev/null @@ -1,19 +0,0 @@ -#! /usr/bin/env perl - -use strict; -use warnings; - -# a wrapper for tail for use in galaxy -# lessWrapper.pl [filename] [# lines to show] [output] - -die "Check arguments" unless @ARGV == 3; -die "Line number should be an integer\n" unless $ARGV[1]=~ m/^\d+$/; - -open (OUT, ">$ARGV[2]") or die "Cannot create $ARGV[2]:$!\n"; -open (TAIL, "tail -n $ARGV[1] $ARGV[0]|") or die "Cannot run tail:$!\n"; -while () { - print OUT; -} -close OUT; -close TAIL; - diff --git a/tools/filters/tailWrapper.xml b/tools/filters/tailWrapper.xml index 166018ec1d2..b1b59bcc419 100644 --- a/tools/filters/tailWrapper.xml +++ b/tools/filters/tailWrapper.xml @@ -1,10 +1,24 @@ - + lines from a dataset - -perl '$__tool_directory__/tailWrapper.pl' '$input' $lineNum '$out_file1' + + coreutils + + '$out_file1' + ]]> - + + @@ -13,7 +27,23 @@ perl '$__tool_directory__/tailWrapper.pl' '$input' $lineNum '$out_file1' - + + + + + + + + + + + + + + + + +