Mercurial > repos > pitagora > unix_tools
comparison sed.xml @ 2:8fd5091a4091 default tip
commit
author | pitagora <yamanaka@genome.rcast.u-tokyo.ac.jp> |
---|---|
date | Sun, 19 Oct 2014 17:20:13 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:69fbeac761c2 | 2:8fd5091a4091 |
---|---|
1 <!-- | |
2 This tool is based on 'cshl_sed_tool' from Hannon Lab, CSHL: | |
3 http://hannonlab.cshl.edu/galaxy_unix_tools/ | |
4 Thanks. Pitagora | |
5 --> | |
6 <tool id="sed" name="sed"> | |
7 <description></description> | |
8 <!-- NOTE | |
9 'sandbox' is a patched SED program, | |
10 which blocks executing shell commands and file reading/writing. | |
11 | |
12 Hopefully, it is safe enough to allow users to execute their own SED commands | |
13 --> | |
14 <command interpreter="sh">sed_wrapper.sh $silent $input $output '$url_paste'</command> | |
15 <inputs> | |
16 <param format="txt" name="input" type="data" label="File to process" /> | |
17 | |
18 <!-- Note: the parameter nane MUST BE 'url_paste' - | |
19 This is a hack in the galaxy library (see ./lib/galaxy/util/__init__.py line 142) | |
20 If the name is 'url_paste' the string won't be sanitized, and all the non-alphanumeric characters | |
21 will be passed to the shell script --> | |
22 <param name="url_paste" type="text" area="true" size="5x35" label="SED Program" help=""> | |
23 <sanitizer> | |
24 <valid initial="string.printable"> | |
25 <remove value="'"/> | |
26 </valid> | |
27 <mapping initial="none"> | |
28 <add source="'" target="__sq__"/> | |
29 </mapping> | |
30 </sanitizer> | |
31 </param> | |
32 | |
33 <param name="silent" type="select" label="operation mode" help="(Same as 'sed -n', leave at 'normal' unless you know what you're doing)" > | |
34 <option value="">normal</option> | |
35 <option value="-n">silent</option> | |
36 </param> | |
37 | |
38 </inputs> | |
39 <outputs> | |
40 <data format="input" name="output" metadata_source="input" /> | |
41 </outputs> | |
42 <help> | |
43 | |
44 **What it does** | |
45 | |
46 This tool runs the unix **sed** command on the selected data file. | |
47 | |
48 .. class:: infomark | |
49 | |
50 **TIP:** This tool uses the **extended regular** expression syntax (same as running 'sed -r'). | |
51 | |
52 | |
53 | |
54 **Further reading** | |
55 | |
56 - Short sed tutorial (http://www.linuxhowtos.org/System/sed_tutorial.htm) | |
57 - Long sed tutorial (http://www.grymoire.com/Unix/Sed.html) | |
58 - sed faq with good examples (http://sed.sourceforge.net/sedfaq.html) | |
59 - sed cheat-sheet (http://www.catonmat.net/download/sed.stream.editor.cheat.sheet.pdf) | |
60 - Collection of useful sed one-liners (http://student.northpark.edu/pemente/sed/sed1line.txt) | |
61 | |
62 ----- | |
63 | |
64 **Sed commands** | |
65 | |
66 The most useful sed command is **s** (substitute). | |
67 | |
68 **Examples** | |
69 | |
70 - **s/hsa//** will remove the first instance of 'hsa' in every line. | |
71 - **s/hsa//g** will remove all instances (beacuse of the **g**) of 'hsa' in every line. | |
72 - **s/A{4,}/--&--/g** will find sequences of 4 or more consecutive A's, and once found, will surround them with two dashes from each side. The **&** marker is a place holder for 'whatever matched the regular expression'. | |
73 - **s/hsa-mir-([^ ]+)/short name: \\1 full name: &/** will find strings such as 'hsa-mir-43a' (the regular expression is 'hsa-mir-' followed by non-space characters) and will replace it will string such as 'short name: 43a full name: hsa-mir-43a'. The **\\1** marker is a place holder for 'whatever matched the first parenthesis' (similar to perl's **$1**) . | |
74 | |
75 | |
76 **sed's Regular Expression Syntax** | |
77 | |
78 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. | |
79 | |
80 - **( ) { } [ ] . * ? + \ ^ $** are all special characters. **\\** can be used to "escape" a special character, allowing that special character to be searched for. | |
81 - **^** matches the beginning of a string(but not an internal line). | |
82 - **(** .. **)** groups a particular pattern. | |
83 - **{** n or n, or n,m **}** specifies an expected number of repetitions of the preceding pattern. | |
84 | |
85 - **{n}** The preceding item is matched exactly n times. | |
86 - **{n,}** The preceding item ismatched n or more times. | |
87 - **{n,m}** The preceding item is matched at least n times but not more than m times. | |
88 | |
89 - **[** ... **]** 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**. | |
90 - **.** Matches any single character except a newline. | |
91 - ***** The preceding item will be matched zero or more times. | |
92 - **?** The preceding item is optional and matched at most once. | |
93 - **+** The preceding item will be matched one or more times. | |
94 - **^** has two meaning: | |
95 - matches the beginning of a line or string. | |
96 - indicates negation in a character class. For example, [^...] matches every character except the ones inside brackets. | |
97 - **$** matches the end of a line or string. | |
98 - **\|** Separates alternate possibilities. | |
99 | |
100 | |
101 **Note**: SED uses extended regular expression syntax, not Perl syntax. **\\d**, **\\w**, **\\s** etc. are **not** supported. | |
102 | |
103 </help> | |
104 </tool> |