website/archive/binaries/mac/src/clustalo/src/clustal/hhalign_wrapper.c
/**
 * @brief re-attach leading and trailing gaps to alignment
 *
 * @param[in,out] prMSeq,
 * alignment structure (at this stage there should be no un-aligned sequences)
 * @param[in] iProfProfSeparator
 * gives sizes of input profiles, -1 if no input-profiles but un-aligned sequences
 *
 * @note leading and tailing profile columns 
 * that only contain gaps have no effect on the alignment 
 * and are removed during the alignment. if they are 
 * encountered a warning message is printed to screen.
 * some users like to preserve these gap columns
 * FS, r213->214
 */


@note leading and tailing profile columns
that only contain gaps have no effect on the alignment
and are removed during the alignment. if they are
encountered a warning message is printed to screen.
some users like to preserve these gap columns
FS, r213->214
@note leading and tailing profile columns that only contain gaps have no effect on the alignment and are removed during the alignment . if they are encountered a warning message is printed to screen . some users like to preserve these gap columns FS r213 - > 214
void
ReAttachLeadingGaps(mseq_t *prMSeq, int  iProfProfSeparator)
{
    int i, j;
    int iSize1 = 0; 
    int iSize2 = 0; 
    int iPPS   = iProfProfSeparator;
    int iLeadO1  = 0; 
    int iLeadO2  = 0; 
    int iLeadA1  = 0; 
    int iLeadA2  = 0; 
    int iTrailO1 = 0; 
    int iTrailO2 = 0; 
    int iTrailA1 = 0; 
    int iTrailA2 = 0; 
    int iLen  = 0; 
    int iLen1 = 0; 
    int iLen2 = 0; 
    int iCutHead = 0; 
    int iCutTail = 0; 
    char *pcIter = NULL;
    if (-1 == iProfProfSeparator){
        return;
    }
    else {
        assert(prMSeq->aligned);
        assert(prMSeq->nseqs > iProfProfSeparator);
    }
    iSize1 = iProfProfSeparator;
    iSize2 = prMSeq->nseqs - iProfProfSeparator;
    iLen  = strlen(prMSeq->seq[0]);
    iLen1 = strlen(prMSeq->orig_seq[0]);
    iLen2 = strlen(prMSeq->orig_seq[iPPS]);
    for (iLeadO1  = 0, pcIter =  prMSeq->orig_seq[0];             isgap(*pcIter); pcIter++, iLeadO1++);
    for (iLeadO2  = 0, pcIter =  prMSeq->orig_seq[iPPS];          isgap(*pcIter); pcIter++, iLeadO2++);
    for (iLeadA1  = 0, pcIter =  prMSeq->seq[0];                  isgap(*pcIter); pcIter++, iLeadA1++);
    for (iLeadA2  = 0, pcIter =  prMSeq->seq[iPPS];               isgap(*pcIter); pcIter++, iLeadA2++);
    for (iTrailO1 = 0, pcIter = &prMSeq->orig_seq[0][iLen1-1];    isgap(*pcIter); pcIter--, iTrailO1++);
    for (iTrailO2 = 0, pcIter = &prMSeq->orig_seq[iPPS][iLen2-1]; isgap(*pcIter); pcIter--, iTrailO2++);
    for (iTrailA1 = 0, pcIter = &prMSeq->seq[0][iLen-1];          isgap(*pcIter); pcIter--, iTrailA1++);
    for (iTrailA2 = 0, pcIter = &prMSeq->seq[iPPS][iLen-1];       isgap(*pcIter); pcIter--, iTrailA2++);
    iLeadO1  = iLeadO1  > iLeadA1  ? iLeadO1-iLeadA1   : 0;
    iLeadO2  = iLeadO2  > iLeadA2  ? iLeadO2-iLeadA2   : 0;
    iTrailO1 = iTrailO1 > iTrailA1 ? iTrailO1-iTrailA1 : 0;
    iTrailO2 = iTrailO2 > iTrailA2 ? iTrailO2-iTrailA2 : 0;
    iCutHead = iLeadO1  > iLeadO2  ? iLeadO1  : iLeadO2;
    iCutTail = iTrailO1 > iTrailO2 ? iTrailO1 : iTrailO2;
    if ( (iCutHead > 0) || (iCutTail > 0) ){ 
        for (i = 0; i < prMSeq->nseqs; i++){
            CKREALLOC(prMSeq->seq[i], iLen+iCutHead+iCutTail+2);
            if (iCutHead > 0){ 
                memmove(prMSeq->seq[i]+iCutHead, prMSeq->seq[i], iLen);
            }
            for (j = 0; j < iCutHead; j++){
                prMSeq->seq[i][j] = '-';
            }
            for (j = iLen+iCutHead; j < iLen+iCutHead+iCutTail; j++){
                prMSeq->seq[i][j] = '-';
            }
            prMSeq->seq[i][j] = '\0';
        }
    } 
}
void ReAttachLeadingGaps ( mseq_t * prMSeq , int iProfProfSeparator ) { int i , j ; int iSize1 = 0 ; int iSize2 = 0 ; int iPPS = iProfProfSeparator ; int iLeadO1 = 0 ; int iLeadO2 = 0 ; int iLeadA1 = 0 ; int iLeadA2 = 0 ; int iTrailO1 = 0 ; int iTrailO2 = 0 ; int iTrailA1 = 0 ; int iTrailA2 = 0 ; int iLen = 0 ; int iLen1 = 0 ; int iLen2 = 0 ; int iCutHead = 0 ; int iCutTail = 0 ; char * pcIter = NULL ; if ( -1 == iProfProfSeparator ) { return ; } else { assert ( prMSeq -> aligned ) ; assert ( prMSeq -> nseqs > iProfProfSeparator ) ; } iSize1 = iProfProfSeparator ; iSize2 = prMSeq -> nseqs - iProfProfSeparator ; iLen = strlen ( prMSeq -> seq [ 0 ] ) ; iLen1 = strlen ( prMSeq -> orig_seq [ 0 ] ) ; iLen2 = strlen ( prMSeq -> orig_seq [ iPPS ] ) ; for ( iLeadO1 = 0 , pcIter = prMSeq -> orig_seq [ 0 ] ; isgap ( * pcIter ) ; pcIter ++ , iLeadO1 ++ ) ; for ( iLeadO2 = 0 , pcIter = prMSeq -> orig_seq [ iPPS ] ; isgap ( * pcIter ) ; pcIter ++ , iLeadO2 ++ ) ; for ( iLeadA1 = 0 , pcIter = prMSeq -> seq [ 0 ] ; isgap ( * pcIter ) ; pcIter ++ , iLeadA1 ++ ) ; for ( iLeadA2 = 0 , pcIter = prMSeq -> seq [ iPPS ] ; isgap ( * pcIter ) ; pcIter ++ , iLeadA2 ++ ) ; for ( iTrailO1 = 0 , pcIter = & prMSeq -> orig_seq [ 0 ] [ iLen1 - 1 ] ; isgap ( * pcIter ) ; pcIter -- , iTrailO1 ++ ) ; for ( iTrailO2 = 0 , pcIter = & prMSeq -> orig_seq [ iPPS ] [ iLen2 - 1 ] ; isgap ( * pcIter ) ; pcIter -- , iTrailO2 ++ ) ; for ( iTrailA1 = 0 , pcIter = & prMSeq -> seq [ 0 ] [ iLen - 1 ] ; isgap ( * pcIter ) ; pcIter -- , iTrailA1 ++ ) ; for ( iTrailA2 = 0 , pcIter = & prMSeq -> seq [ iPPS ] [ iLen - 1 ] ; isgap ( * pcIter ) ; pcIter -- , iTrailA2 ++ ) ; iLeadO1 = iLeadO1 > iLeadA1 ? iLeadO1 - iLeadA1 : 0 ; iLeadO2 = iLeadO2 > iLeadA2 ? iLeadO2 - iLeadA2 : 0 ; iTrailO1 = iTrailO1 > iTrailA1 ? iTrailO1 - iTrailA1 : 0 ; iTrailO2 = iTrailO2 > iTrailA2 ? iTrailO2 - iTrailA2 : 0 ; iCutHead = iLeadO1 > iLeadO2 ? iLeadO1 : iLeadO2 ; iCutTail = iTrailO1 > iTrailO2 ? iTrailO1 : iTrailO2 ; if ( ( iCutHead > 0 ) || ( iCutTail > 0 ) ) { for ( i = 0 ; i < prMSeq -> nseqs ; i ++ ) { CKREALLOC ( prMSeq -> seq [ i ] , iLen + iCutHead + iCutTail + 2 ) ; if ( iCutHead > 0 ) { memmove ( prMSeq -> seq [ i ] + iCutHead , prMSeq -> seq [ i ] , iLen ) ; } for ( j = 0 ; j < iCutHead ; j ++ ) { prMSeq -> seq [ i ] [ j ] = ' ' ; } for ( j = iLen + iCutHead ; j < iLen + iCutHead + iCutTail ; j ++ ) { prMSeq -> seq [ i ] [ j ] = ' ' ; } prMSeq -> seq [ i ] [ j ] = ' \0 ' ; } } }
@brief re-attach leading and trailing gaps to alignment
 @param[in,out] prMSeq,
 alignment structure (at this stage there should be no un-aligned sequences)
 @param[in] iProfProfSeparator
 gives sizes of input profiles, -1 if no input-profiles but un-aligned sequences
@brief re - attach leading and trailing gaps to alignment @param [ in out ] prMSeq alignment structure ( at this stage there should be no un - aligned sequences ) @param [ in ] iProfProfSeparator gives sizes of input profiles - 1 if no input - profiles but un - aligned sequences
/* #seqs in 1st profile */ /* #seqs in 2nd profile */ /* leading  gaps in 1st seq of 1st profile */ /* leading  gaps in 1st seq of 2nd profile */ /* leading  gaps in 1st seq of final alignment */ /* leading  gaps in PPS seq of final alignment */ /* trailing gaps in 1st seq of 1st profile */ /* trailing gaps in 1st seq of 2nd profile */ /* trailing gaps in 1st seq of final alignment */ /* trailing gaps in PPS seq of final alignment */ /* length of final alignment */ /* length of 1st profile */ /* length of 2nd profile */ /* make up truncation at head */ /* make up truncation at tail */ /* count leading/trailing gaps in 1st sequence of 1st/2nd profile and final alignmant */ /* turn leading/trailing gaps into truncation */ /* re-allocate and shift memory */ /* skip if no re-attachment, FS, r244 -> r245 */ /* skip if no re-attachment, FS, r244 -> r245 */ /* (iCutHead > 0) || (iCutTail > 0) */