root/galaxy-central/tools/unix_tools/grep_wrapper.sh @ 3

リビジョン 3, 1.7 KB (コミッタ: kohda, 14 年 前)

Install Unix tools  http://hannonlab.cshl.edu/galaxy_unix_tools/galaxy.html

行番号 
1#!/bin/sh
2
3##
4## Galaxy wrapper for GREP command.
5##
6
7##
8## command line arguments:
9##   input_file
10##   output_file
11##   regex
12##   COLOR or NOCOLOR
13##   [other parameters passed on to grep]
14
15INPUT="$1"
16OUTPUT="$2"
17REGEX="$3"
18COLOR="$4"
19
20shift 4
21
22if [ -z "$COLOR" ]; then
23        echo usage: $0 INPUTFILE OUTPUTFILE REGEX COLOR\|NOCOLOR [other grep patameters] >&2
24        exit 1
25fi
26
27if [ ! -r "$INPUT" ]; then
28        echo "error: input file ($INPUT) not found!" >&2
29        exit 1
30fi
31
32# Messages printed to STDOUT will be displayed in the "INFO" field in the galaxy dataset.
33# This way the user can tell what was the command
34echo "grep" "$@" "$REGEX"
35
36if [ "$COLOR" == "COLOR" ]; then
37        #
38        # What the heck is going on here???
39        # 1. "GREP_COLORS" is an environment variable, telling GREP which ANSI colors to use.
40        # 2. "--colors=always" tells grep to actually use colors (according to the GREP_COLORS variable)
41        # 3. first sed command translates the ANSI color to a <FONT> tag with blue color (and a <B> tag, too)
42        # 4. second sed command translates the no-color ANSI command to a </FONT> tag (and a </B> tag, too)
43        # 5. htmlize_pre scripts takes a text input and wraps it in <HTML><BODY><PRE> tags, making it a fixed-font HTML file.
44
45        GREP_COLORS="ms=31" grep --color=always -P "$@" -- "$REGEX" "$INPUT" | \
46                grep -v "^\[36m\[K--\[m\[K$" | \
47                sed -r 's/\[[0123456789;]+m\[K?/<font color="blue"><b>/g' | \
48                sed -r 's/\[m\[K?/<\/b><\/font>/g' | \
49                htmlize_pre.sh > "$OUTPUT"
50
51
52        if (( $? ));  then exit; fi
53
54elif [ "$COLOR" == "NOCOLOR" ]; then
55        grep -P "$@" -- "$REGEX" "$INPUT" | grep -v "^--$" > "$OUTPUT"
56        if (( $? ));  then exit; fi
57else
58        echo Error: third parameter must be "COLOR" or "NOCOLOR" >&2
59        exit 1
60fi
61
62exit 0
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。