Mercurial > repos > bgruening > text_processing
comparison grep.xml @ 0:ec66f9d90ef0 draft
initial uploaded
| author | bgruening |
|---|---|
| date | Thu, 05 Sep 2013 04:58:21 -0400 |
| parents | |
| children | a4ad586d1403 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:ec66f9d90ef0 |
|---|---|
| 1 <tool id="unixtools_grep_tool" name="Search in textfiles" version="0.1.1"> | |
| 2 <description>(grep)</description> | |
| 3 <requirements> | |
| 4 <requirement type="package" version="8.21">gnu_coreutils</requirement> | |
| 5 <requirement type="package" version="2.14">gnu_grep</requirement> | |
| 6 <requirement type="set_environment">UNIX_TOOLS_SCRIPT_PATH</requirement> | |
| 7 </requirements> | |
| 8 <command interpreter="sh"> | |
| 9 #if $color = "COLOR": | |
| 10 GREP_COLOR='1;34' grep --color=always -P "$@" -- "${url_paste}" '${input}' | \$UNIX_TOOLS_SCRIPT_PATH/ansi2html.sh > "${output}" | |
| 11 #else: | |
| 12 grep -P "$@" -- "${url_paste}" '${input}' | grep -v "^--$" > "${output}" | |
| 13 #end if | |
| 14 | |
| 15 ##grep_wrapper.sh '$input' '$output' '$url_paste' $color -A $lines_after -B $lines_before $invert $case_sensitive | |
| 16 </command> | |
| 17 <inputs> | |
| 18 <param format="txt" name="input" type="data" label="Select lines from" /> | |
| 19 | |
| 20 <param name="invert" type="select" label="that"> | |
| 21 <option value="">Match</option> | |
| 22 <option value="-v">Don't Match</option> | |
| 23 </param> | |
| 24 | |
| 25 <param name="url_paste" type="text" size="40" label="Regular Expression" help="See below for more details"> | |
| 26 <sanitizer> | |
| 27 <valid initial="string.printable"> | |
| 28 <remove value="'"/> | |
| 29 </valid> | |
| 30 </sanitizer> | |
| 31 </param> | |
| 32 | |
| 33 <param name="case_sensitive" type="select" label="Match type"> | |
| 34 <option value="-i">case insensitive</option> | |
| 35 <option value="">case sensitive</option> | |
| 36 </param> | |
| 37 | |
| 38 <param name="lines_before" type="integer" label="Show lines preceding the matched line (-B)" help="leave it at zero unless you know what you're doing" value="0" /> | |
| 39 <param name="lines_after" type="integer" label="Show lines trailing the matched line (-A)" help="leave it at zero unless you know what you're doing" value="0" /> | |
| 40 | |
| 41 <param name="color" type="select" label="Output"> | |
| 42 <option value="NOCOLOR">text file (for further processing)</option> | |
| 43 <option value="COLOR">Highlighted HTML (for easier viewing)</option> | |
| 44 </param> | |
| 45 | |
| 46 </inputs> | |
| 47 <outputs> | |
| 48 <data format="input" name="output" metadata_source="input"> | |
| 49 <change_format> | |
| 50 <when input="color" value="COLOR" format="html" | |
| 51 /> | |
| 52 </change_format> | |
| 53 </data> | |
| 54 </outputs> | |
| 55 <tests> | |
| 56 <test> | |
| 57 <!-- grep a FASTA file for sequences with specific motif --> | |
| 58 <param name="input" value="unix_grep_input1.txt" /> | |
| 59 <output name="output" file="unix_grep_output1.txt" /> | |
| 60 <param name="case_sensitive" value="case sensitive" /> | |
| 61 <param name="invert" value="" /> | |
| 62 <param name="url_paste" value="AA.{2}GT" /> | |
| 63 <param name="lines_before" value="1" /> | |
| 64 <param name="lines_after" value="0" /> | |
| 65 <param name="color" value="NOCOLOR" /> | |
| 66 </test> | |
| 67 <test> | |
| 68 <!-- grep a FASTA file for sequences with specific motif - | |
| 69 show highlighed output --> | |
| 70 <param name="input" value="unix_grep_input1.txt" /> | |
| 71 <output name="output" file="unix_grep_output2.html" /> | |
| 72 <param name="case_sensitive" value="case sensitive" /> | |
| 73 <param name="invert" value="" /> | |
| 74 <param name="url_paste" value="AA.{2}GT" /> | |
| 75 <param name="lines_before" value="0" /> | |
| 76 <param name="lines_after" value="0" /> | |
| 77 <param name="color" value="COLOR" /> | |
| 78 </test> | |
| 79 </tests> | |
| 80 <help> | |
| 81 | |
| 82 **What it does** | |
| 83 | |
| 84 This tool runs the unix **grep** command on the selected data file. | |
| 85 | |
| 86 .. class:: infomark | |
| 87 | |
| 88 **TIP:** This tool uses the **perl** regular expression syntax (same as running 'grep -P'). This is **NOT** the POSIX or POSIX-extended syntax (unlike the awk/sed tools). | |
| 89 | |
| 90 | |
| 91 **Further reading** | |
| 92 | |
| 93 - Wikipedia's Regular Expression page (http://en.wikipedia.org/wiki/Regular_expression) | |
| 94 - Regular Expressions cheat-sheet (PDF) (http://www.addedbytes.com/cheat-sheets/download/regular-expressions-cheat-sheet-v2.pdf) | |
| 95 - Grep Tutorial (http://www.panix.com/~elflord/unix/grep.html) | |
| 96 | |
| 97 ----- | |
| 98 | |
| 99 **Grep Examples** | |
| 100 | |
| 101 - **AGC.AAT** would match lines with AGC followed by any character, followed by AAT (e.g. **AGCQAAT**, **AGCPAAT**, **AGCwAAT**) | |
| 102 - **C{2,5}AGC** would match lines with 2 to 5 consecutive Cs followed by AGC | |
| 103 - **TTT.{4,10}AAA** would match lines with 3 Ts, followed by 4 to 10 characters (any characeters), followed by 3 As. | |
| 104 - **^chr([0-9A-Za-z])+** would match lines that begin with chromsomes, such as lines in a BED format file. | |
| 105 - **(ACGT){1,5}** would match at least 1 "ACGT" and at most 5 "ACGT" consecutively. | |
| 106 - **hsa|mmu** would match lines containing "hsa" or "mmu" (or both). | |
| 107 | |
| 108 ----- | |
| 109 | |
| 110 **Regular Expression Syntax** | |
| 111 | |
| 112 The select tool searches the data for lines containing or not containing a match to the given pattern. A Regular Expression is a pattern descibing a certain amount of text. | |
| 113 | |
| 114 - **( ) { } [ ] . * ? + \ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for. | |
| 115 - **^** matches the beginning of a string(but not an internal line). | |
| 116 - **\\d** matches a digit, same as [0-9]. | |
| 117 - **\\D** matches a non-digit. | |
| 118 - **\\s** matches a whitespace character. | |
| 119 - **\\S** matches anything BUT a whitespace. | |
| 120 - **\\t** matches a tab. | |
| 121 - **\\w** matches an alphanumeric character ( A to Z, 0 to 9 and underscore ) | |
| 122 - **\\W** matches anything but an alphanumeric character. | |
| 123 - **(** .. **)** groups a particular pattern. | |
| 124 - **\\Z** matches the end of a string(but not a internal line). | |
| 125 - **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern. | |
| 126 | |
| 127 - **{n}** The preceding item is matched exactly n times. | |
| 128 - **{n,}** The preceding item ismatched n or more times. | |
| 129 - **{n,m}** The preceding item is matched at least n times but not more than m times. | |
| 130 | |
| 131 - **[** ... **]** creates a character class. Within the brackets, single characters can be placed. A dash (-) may be used to indicate a range such as **a-z**. | |
| 132 - **.** Matches any single character except a newline. | |
| 133 - ***** The preceding item will be matched zero or more times. | |
| 134 - **?** The preceding item is optional and matched at most once. | |
| 135 - **+** The preceding item will be matched one or more times. | |
| 136 - **^** has two meaning: | |
| 137 - matches the beginning of a line or string. | |
| 138 - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets. | |
| 139 - **$** matches the end of a line or string. | |
| 140 - **\|** Separates alternate possibilities. | |
| 141 | |
| 142 | |
| 143 </help> | |
| 144 </tool> |
