-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrcgrep
executable file
·31 lines (23 loc) · 1.02 KB
/
rcgrep
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
if [[ ! -n $1 ]]; then
cat <<EOH
Usable only as a pipe. This wraps around zegrep and adds the reverse complement
of the specified search pattern. Character classes [] and group/branching ( | )
will work. Backslash patterns will fail. Use '-' to stretch between patterns.
The augmented zegrep command is output on STDERR.
- Usage:
rcgrep PATTERN [grep options]
- Multiline sequences are combined into a single line (numbered lines not supported)
- The stretch wildcard character is '-' (it will be translated to .*).
- The grep options -i and --color=always are provided already.
- When piping to less use less -R .
EOH
exit 0
fi
seq=$1
shift 1
qes=$(echo $seq | tr GCATUgcatu CGTAAcgtaa | rev | tr '][)(' '[]()' | perl -pe 's/\-/\.\*/g');
seq=$(echo $seq | perl -pe 's/\-/\.\*/g');
options=( "-i" "--color=always" "$@" )
echo "___ Command used: zegrep \"${options[@]}\" \"($seq|$qes)\" ___" >&2
perl -ne 'chomp;print;print"\n"unless/^[acgtnxu\- \~]+$/i;END{print"\n"}' | zegrep "${options[@]}" "($seq|$qes)"