#!/bin/zsh

typeset -A bla
bla=(ARG R HIS H LYS K ASP D GLU E \
	SER S THR T ASN N GLN Q CYS C SEC U GLY G PRO P \
	ALA A ILE I LEU L MET M PHE F TRP W TYR Y VAL V \
)


for f ($@) {
	lseq=
	OIFS=$IFS
	prot=()
	IFS=$'\n'; for line ( $(
			zcat $f \
				| grep \^SEQRES
			) ) {
		IFS=$OIFS
		seqres=($=line) # split
		if [[ $lseq != $seqres[3] ]] {
			if [[ -n $lseq ]] { if ( $unknown ) { echo -n ']' }; echo }
			unknown==false
			lseq=$seqres[3]
			((i=0))
			if [[ $#@ -gt 1 ]] { echo -n $f, }
			echo -n "Sequence_$lseq:"
		}
		((++i))
		if [[ $i -ne $seqres[2] ]] { echo "Fehler in $f: seqres $seqres[3] not in line" >2 }
		for prot ($seqres[5,-1]) {
			prot_let=$bla[$prot]
			if [[ -z $prot_let ]] {
				if ( ! $unknown ) { echo -n '['; unknown==true } \
				else { echo -n , }
				echo -n $prot
			} \
			else {
				if ( $unknown ) { echo -n ']'; unknown==false }
				echo -n $prot_let
			}
		}
	}
	if ( $unknown ) { echo -n ']' }; echo
}
