-
Notifications
You must be signed in to change notification settings - Fork 0
/
uf-bare
executable file
·70 lines (57 loc) · 2.2 KB
/
uf-bare
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
#
# uf-bare - Extract the bare sequence data from an unfasta stream.
# Copyright (C) 2016 Marco van Zwetselaar <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This utility is part of http://io.zwets.it/unfasta
# Function to exit this script with an error message on stderr
err_exit() {
echo "$(basename "$0"): $*" >&2
exit 1
}
# Function to show usage information and exit
usage_exit() {
echo "
Usage: $(basename $0) [OPTIONS] [FILE ...]
Output only the bare sequences (contigs) from each FILE to standard output,
omitting the headers. If no FILE is present or FILE is '-', read from stdin.
Options
-w HDRSFILE Write the headers to HDRSFILE, which must not already exist.
-f, --force Overwrite HDRSFILE if it exists.
By default headers go to /dev/null. Use option -w to store them in a file.
The file can be merged back in with 'uf-dress'.
" >&2
exit ${1:-1}
}
# Parse options
unset HDRSFILE FORCE
while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-w) shift; HDRSFILE="$1" ;;
-f|--force) FORCE="yes" ;;
--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift || usage_exit
done
# Check options validity
[ -z "$HDRSFILE" ] || [ -n "$FORCE" ] || [ ! -e "$HDRSFILE" ] || err_exit "file exists (use --force to overwrite): '$HDRSFILE'"
# Do the work
gawk -bO -v F="$HDRSFILE" -v P="$(basename "$0")" '
NR%2==1 && substr($0,1,1) != ">" { print P ": warning: discarding line that does not look like a FASTA header: " $0 > "/dev/stderr" }
NR%2==1 && F { print > F }
NR%2==0' "$@"
# vim: sts=4:sw=4:et:si:ai