Skip to content

Commit

Permalink
[uf] strip all carriage returns
Browse files Browse the repository at this point in the history
  • Loading branch information
zwets committed Jan 26, 2021
1 parent 94235dd commit e90da8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 49 deletions.
25 changes: 8 additions & 17 deletions uf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Usage: $(basename $0) [OPTIONS] [FILE ...]
-l, --lower Write lowercase
-u, --upper Write uppercase
Option -r reverts sequences to classic FASTA by breaking lines at 80 chars.
Option -r reverts sequences to classic FASTA by breaking lines at 60 chars.
Note however that there is no need to do this, as every unfasta file is also
a valid FASTA file. The 60 or 80 char limit is only a recommendation.
Expand All @@ -59,33 +59,24 @@ UPPER=0

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
-l|--lower)
LOWER=1
;;
-u|--upper)
UPPER=1
;;
-r|--rever*)
REVERT="true"
;;
-h|--help)
usage_exit 0
;;
*) usage_exit
;;
-l|--lower) LOWER=1 ;;
-u|--upper) UPPER=1 ;;
-r|--rever*) REVERT="true" ;;
-h|--help) usage_exit 0 ;;
*) usage_exit ;;
esac
shift
done

if [ -n "$REVERT" ]; then
gawk -bO -v WIDTH=80 -v L=$LOWER -v U=$UPPER '
gawk -bO -v WIDTH=60 -v L=$LOWER -v U=$UPPER '
/^>/
/^[^>]/ { for (i=1;i<=length();i+=WIDTH) { S=substr($0,i,WIDTH); print (L ? tolower(S) : U ? toupper(S) : S) } }' "$@"
else
gawk -bO -v L=$LOWER -v U=$UPPER 'BEGIN { ORS="" }
/^>/ { if (NR!=1) print "\n"; print $0 "\n" }
/^[^>]/ { gsub(/[[:space:]]/,""); print (L ? tolower($0) : U ? toupper($0) : $0) }
END { print "\n" }' "$@"
fi
fi | tr -d '\r'

# vim: sts=4:sw=4:et:si:ai
41 changes: 9 additions & 32 deletions uf-select
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,15 @@ unset NTH SEQID REGEX

while [ $# -ne 0 -a "$(expr "$1" : '\(.\)..*')" = "-" ]; do
case $1 in
--nth=*)
NTH=${1#--nth=}
;;
-n|--nth)
shift
[ $# -ge 1 ] || usage_exit
NTH=$1
;;
--id=*)
SEQID=${1#--id=}
;;
-i|--id)
shift
[ $# -ge 1 ] || usage_exit
SEQID=$1
;;
--grep=*)
REGEX=${1#--grep=}
;;
-g|--grep)
shift
[ $# -ge 1 ] || usage_exit
REGEX=$1
;;
-h|--help)
usage_exit 0
;;
-)
break
;;
*) usage_exit
;;
--nth=*) NTH=${1#--nth=} ;;
-n|--nth) shift; [ $# -ge 1 ] || usage_exit; NTH=$1 ;;
--id=*) SEQID=${1#--id=} ;;
-i|--id) shift; [ $# -ge 1 ] || usage_exit; SEQID=$1 ;;
--grep=*) REGEX=${1#--grep=} ;;
-g|--grep) shift; [ $# -ge 1 ] || usage_exit; REGEX=$1 ;;
-h|--help) usage_exit 0 ;;
-) break ;;
*) usage_exit ;;
esac
shift
done
Expand Down

0 comments on commit e90da8b

Please sign in to comment.