-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/bin/sh | ||
# | ||
# uf-dress - Turn bare sequence data into an unfasta file. | ||
# 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/>. | ||
# | ||
# Created on 2016-01-25 | ||
|
||
# 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 | ||
echo "Usage: $(basename $0) [OPTIONS] [FILE] ..." | ||
echo | ||
echo " Insert headers to turn bare sequence FILE(s) into valid unfasta. If no FILE or" | ||
echo " FILE is '-' read from standard input. Write unfasta to standard output." | ||
echo | ||
echo " Options" | ||
echo " -r HDRSFILE Optional file to read header lines from. If not specified then" | ||
echo " default headers 'lcl|NUM' will be generated." | ||
echo | ||
echo " The HDRSFILE could be a file previously written by 'uf-bare', or output from" | ||
echo " the 'uf-hdrs' filter. Tip: use bash process substitution to avoid temp files:" | ||
echo | ||
echo ' $ uf file.fna | uf-bare | ..processing.. | uf-dress -r <(uf file.fna | uf-hdrs)' | ||
echo | ||
exit ${1:-1} | ||
} | ||
|
||
# Parse options | ||
|
||
unset HDRSFILE | ||
|
||
while [ $# -ne 0 -a "$(expr "$1" : '\(.\).*')" = "-" ]; do | ||
case $1 in | ||
-r) shift | ||
[ $# -ge 1 ] || usage_exit | ||
HDRSFILE="$1" | ||
;; | ||
--help) | ||
usage_exit 0 | ||
;; | ||
*) usage_exit | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
# Check options validity | ||
|
||
[ -z "$HDRSFILE" ] || [ -r "$HDRSFILE" ] || err_exit "cannot read file: '$HDRSFILE'" | ||
|
||
# Do the work | ||
|
||
awk -b -O -v F="$HDRSFILE" '{ | ||
if (F) getline HDR < F; else HDR = ">lcl|" NR | ||
print HDR | ||
} | ||
END { if (F) close (F) }' "$@" | ||
|