#!/bin/bash -e

# Simple bash script to revert the names of extended residues to the
# standard ones.
#
# Note that *all* occurences of the residue names are replaced, which
# may cause problems if other instances of those names occur besides
# the actual residue names, but that is highly unlikely. Nonetheless,
# a warning message is printed to make the user aware of this. 
#
############################################################################

[[ $# -gt 1 ]] && \
    echo "Error: Usage: revert-res [FILE or STDIN]" >/dev/stderr && exit 1

sedexp=$(awk '!/;/{printf (n++!=0?";":"")"s/%s/%s/",$2,$1}' convert.def)
reslist=$(awk '!/;/{printf (n++!=0?",":"")"%s",$2}' convert.def)

sed $sedexp $1

echo "revert-res: *all* occurences of $reslist were replaced." >/dev/stderr

exit 0

############################################################################
