website/archive/binaries/mac/src/clustalo/src/clustal/hhalign_wrapper.c
/**
 * @brief translate unknown residues back to ambiguity codes;
 * hhalign translates ambiguity codes (B,Z) into unknown residue (X).
 * we still have the original (un-aligned) residue information,
 * by iterating along the original and aligned sequences we can
 * reconstruct where codes have been changed and restore them
 * to their original value
 *
 * @param[in,out] mseq
 * sequence/profile data, mseq->seq [in,out] is changed to conform
 * with mseq->orig_seq [in]
 *
 */
@brief translate unknown residues back to ambiguity codes;
hhalign translates ambiguity codes (B,Z) into unknown residue (X).
we still have the original (un-aligned) residue information,
by iterating along the original and aligned sequences we can
reconstruct where codes have been changed and restore them
to their original value

@param[in,out] mseq
sequence/profile data, mseq->seq [in,out] is changed to conform
with mseq->orig_seq [in]
@brief translate unknown residues back to ambiguity codes ; hhalign translates ambiguity codes ( B Z ) into unknown residue ( X ) . we still have the original ( un - aligned ) residue information by iterating along the original and aligned sequences we can reconstruct where codes have been changed and restore them to their original value @param [ in out ] mseq sequence / profile data mseq - > seq [ in out ] is changed to conform with mseq - > orig_seq [ in ]
void
TranslateUnknown2Ambiguity(mseq_t *mseq)
{
    int iS; 
    int iR, iRo; 
    int iChange, iCase, iAmbi; 
    static int siOffset = 'a' - 'A';
    for (iS = 0; iS < mseq->nseqs; iS++){
        iR = iRo = 0;
        iChange = iCase = iAmbi = 0;
        while(('\0' != mseq->seq[iS][iR]) &&
              ('\0' != mseq->orig_seq[iS][iRo])) {
            while(isgap(mseq->seq[iS][iR])) {
                iR++;
            } 
            while(isgap(mseq->orig_seq[iS][iRo])) {
                iRo++;
            } 
            if ( ('\0' == mseq->seq[iS][iR]) ||
                 ('\0' == mseq->orig_seq[iS][iRo]) ){
                break;
            }
            if (mseq->seq[iS][iR] != mseq->orig_seq[iS][iRo]){
                iChange++;
                if ( (mseq->seq[iS][iR] == mseq->orig_seq[iS][iRo]+siOffset) ||
                     (mseq->seq[iS][iR] == mseq->orig_seq[iS][iRo]-siOffset) ){
                    iCase++;
                }
                else {
                    iAmbi++;
                }
#if TRACE
                Log(&rLog, LOG_FORCED_DEBUG, "seq=%d, pos=(%d:%d), (%c:%c)",
                     iS, iR, iRo,
                     mseq->seq[iS][iR], mseq->orig_seq[iS][iRo]);
#endif
                mseq->seq[iS][iR] = mseq->orig_seq[iS][iRo];
            }
            iR++;
            iRo++;
        } 
        Log(&rLog, LOG_DEBUG,
             "in seq %d re-translated %d residue codes (%d true, %d case)",
             iS, iChange, iAmbi, iCase);
        while(isgap(mseq->seq[iS][iR])) {
            iR++;
        } 
        while(isgap(mseq->orig_seq[iS][iRo])) {
            iRo++;
        } 
        if ( ('\0' != mseq->seq[iS][iR]) ||
             ('\0' != mseq->orig_seq[iS][iRo]) ){
            Log(&rLog, LOG_FATAL, "inconsistency in un/aligned sequence %d\n>%s\n>%s\n",
                  iS, mseq->seq[iS], mseq->orig_seq[iS]);
        }
    } 
}
void TranslateUnknown2Ambiguity ( mseq_t * mseq ) { int iS ; int iR , iRo ; int iChange , iCase , iAmbi ; static int siOffset = ' ' - ' ' ; for ( iS = 0 ; iS < mseq -> nseqs ; iS ++ ) { iR = iRo = 0 ; iChange = iCase = iAmbi = 0 ; while ( ( ' \0 ' != mseq -> seq [ iS ] [ iR ] ) && ( ' \0 ' != mseq -> orig_seq [ iS ] [ iRo ] ) ) { while ( isgap ( mseq -> seq [ iS ] [ iR ] ) ) { iR ++ ; } while ( isgap ( mseq -> orig_seq [ iS ] [ iRo ] ) ) { iRo ++ ; } if ( ( ' \0 ' == mseq -> seq [ iS ] [ iR ] ) || ( ' \0 ' == mseq -> orig_seq [ iS ] [ iRo ] ) ) { break ; } if ( mseq -> seq [ iS ] [ iR ] != mseq -> orig_seq [ iS ] [ iRo ] ) { iChange ++ ; if ( ( mseq -> seq [ iS ] [ iR ] == mseq -> orig_seq [ iS ] [ iRo ] + siOffset ) || ( mseq -> seq [ iS ] [ iR ] == mseq -> orig_seq [ iS ] [ iRo ] - siOffset ) ) { iCase ++ ; } else { iAmbi ++ ; } #if TRACE Log ( & rLog , LOG_FORCED_DEBUG , " " , iS , iR , iRo , mseq -> seq [ iS ] [ iR ] , mseq -> orig_seq [ iS ] [ iRo ] ) ; #endif mseq -> seq [ iS ] [ iR ] = mseq -> orig_seq [ iS ] [ iRo ] ; } iR ++ ; iRo ++ ; } Log ( & rLog , LOG_DEBUG , " " , iS , iChange , iAmbi , iCase ) ; while ( isgap ( mseq -> seq [ iS ] [ iR ] ) ) { iR ++ ; } while ( isgap ( mseq -> orig_seq [ iS ] [ iRo ] ) ) { iRo ++ ; } if ( ( ' \0 ' != mseq -> seq [ iS ] [ iR ] ) || ( ' \0 ' != mseq -> orig_seq [ iS ] [ iRo ] ) ) { Log ( & rLog , LOG_FATAL , " \n \n \n " , iS , mseq -> seq [ iS ] , mseq -> orig_seq [ iS ] ) ; } } }
@brief translate unknown residues back to ambiguity codes;
 hhalign translates ambiguity codes (B,Z) into unknown residue (X).
@brief translate unknown residues back to ambiguity codes ; hhalign translates ambiguity codes ( B Z ) into unknown residue ( X ) .
/* iterator for sequence */ /* iterator for residue (original) */ /* counts how many replacements */ /* skip gaps in aligned sequences */ /* was gap in unaligned seq
               * this should probably not happen */ /* was gap in aligned seq */ /* check if we reached the end of the sequence after
             * skipping the gaps */ /* FIXME: count replacements, discard case changes */ /* !EO seq */ /* assert that both sequences (un/aligned) have terminated */ /* skip gaps in aligned sequences */ /* was gap in unaligned seq
           * this should probably not happen */ /* was gap in aligned seq */ /* 0 <= iS < mseq->nseqs */