website/archive/binaries/mac/src/clustalo/src/clustal/hhalign_wrapper.c
/**
 * @brief reallocate enough memory for alignment and
 * attach sequence pointers to profiles
 *
 * @param[in,out] mseq
 * sequence/profile data, increase memory for sequences in profiles
 * @param[out] ppcProfile1
 * pointers to sequencese in 1st profile
 * @param[out] ppcProfile2
 * pointers to sequencese in 2nd profile
 * @param[out] pdWeightsL
 * weights (normalised to 1.0) for sequences in left  profile
 * @param[out] pdWeightsR
 * weights (normalised to 1.0) for sequences in right profile
 * @param[in] pdSeqWeights
 * weights for _all_ sequences in alignment
 * @param[in] iLeafCountL
 * number of sequences in 1st profile
 * @param[in] piLeafListL
 * array of integer IDs of sequences in 1st profile
 * @param[in] iLeafCountR
 * number of sequences in 2nd profile
 * @param[in] piLeafListR
 * array of integer IDs of sequences in 2nd profile
 *
 */
@brief reallocate enough memory for alignment and
attach sequence pointers to profiles


@brief reallocate enough memory for alignment and attach sequence pointers to profiles
void
PrepareAlignment(mseq_t *mseq, char **ppcProfile1, char **ppcProfile2,
                 double *pdWeightsL, double *pdWeightsR, double *pdSeqWeights,
                 int iLeafCountL, int *piLeafListL,
                 int iLeafCountR, int *piLeafListR)
{
    int iLenL = 0; 
    int iLenR = 0; 
    int iMaxLen = 0; 
    int i; 
    double dWeight = 0.00;
    double dWeightInv = 0.00;
    assert(NULL!=mseq);
    assert(NULL!=ppcProfile1);
    assert(NULL!=ppcProfile2);
    assert(NULL!=piLeafListL);
    assert(NULL!=piLeafListR);
    iLenL = strlen(mseq->seq[piLeafListL[0]]);
    iLenR = strlen(mseq->seq[piLeafListR[0]]);
    iMaxLen = iLenL + iLenR + 1;
    for (i = 0; i < iLeafCountL; i++){
        mseq->seq[piLeafListL[i]] =
            CKREALLOC(mseq->seq[piLeafListL[i]], iMaxLen);
    }
    for (i = 0; i < iLeafCountR; i++){
        mseq->seq[piLeafListR[i]] =
            CKREALLOC(mseq->seq[piLeafListR[i]], iMaxLen);
    }
    for (i = 0; i < iLeafCountL; i++){
        ppcProfile1[i] = mseq->seq[piLeafListL[i]];
    }
    ppcProfile1[i] = NULL;
    for (i = 0; i < iLeafCountR; i++){
        ppcProfile2[i] = mseq->seq[piLeafListR[i]];
    }
    ppcProfile2[i] = NULL;
    if ( (1 == iLeafCountL) && (1 == iLeafCountR) ){
        if ( ('X' == ppcProfile1[0][0]) && ('X' == ppcProfile2[0][0]) ){
#define NOTX 'N'
            ppcProfile1[0][0] = NOTX; 
            ppcProfile2[0][0] = NOTX; 
        }
        if ( ('X' == ppcProfile1[0][iLenL-1]) && ('X' == ppcProfile2[0][iLenR-1]) ){
            ppcProfile1[0][iLenL-1] = NOTX; 
            ppcProfile2[0][iLenR-1] = NOTX; 
        }
    }
    if (NULL != pdSeqWeights){
        dWeight = 0.00;
        for (i = 0; i < iLeafCountL; i++){
            register double dAux = pdSeqWeights[piLeafListL[i]];
#ifndef NDEBUG
            if (dAux <= 0.00){
                Log(&rLog, LOG_DEBUG, "seq-weight %d = %f", piLeafListL[i], dAux);
            }
#endif
            pdWeightsL[i] = dAux;
            dWeight      += dAux;
        } 
        dWeightInv = 1.00 / dWeight;
        for (i = 0; i < iLeafCountL; i++){
            pdWeightsL[i] *= dWeightInv;
        }
        dWeight = 0.00;
        for (i = 0; i < iLeafCountR; i++){
            register double dAux = pdSeqWeights[piLeafListR[i]];
#ifndef NDEBUG
            if (dAux <= 0.00){
                Log(&rLog, LOG_DEBUG, "seq-weight %d = %f", piLeafListR[i], dAux);
            }
#endif
            pdWeightsR[i] = dAux;
            dWeight      += dAux;
        } 
        dWeightInv = 1.00 / dWeight;
        for (i = 0; i < iLeafCountR; i++){
            pdWeightsR[i] *= dWeightInv;
        }
    } 
    else {
        pdWeightsL[0] = pdWeightsR[0] = -1.00;
    }
#if TRACE
    for (i = 0; i < iLeafCountL; i++){
        Log(&rLog, LOG_FORCED_DEBUG, "ppcProfile1[%d/%d] pointing to mseq %d = %s",
                  i, iLeafCountR, piLeafListL[i], ppcProfile1[i]);
    }
    for (i = 0; i < iLeafCountR; i++){
        Log(&rLog, LOG_FORCED_DEBUG, "ppcProfile2[%d/%d] pointing to mseq %d = %s",
                  i, iLeafCountR, piLeafListR[i], ppcProfile2[i]);
    }
#endif
    return;
}
void PrepareAlignment ( mseq_t * mseq , char * * ppcProfile1 , char * * ppcProfile2 , double * pdWeightsL , double * pdWeightsR , double * pdSeqWeights , int iLeafCountL , int * piLeafListL , int iLeafCountR , int * piLeafListR ) { int iLenL = 0 ; int iLenR = 0 ; int iMaxLen = 0 ; int i ; double dWeight = 0.00 ; double dWeightInv = 0.00 ; assert ( NULL != mseq ) ; assert ( NULL != ppcProfile1 ) ; assert ( NULL != ppcProfile2 ) ; assert ( NULL != piLeafListL ) ; assert ( NULL != piLeafListR ) ; iLenL = strlen ( mseq -> seq [ piLeafListL [ 0 ] ] ) ; iLenR = strlen ( mseq -> seq [ piLeafListR [ 0 ] ] ) ; iMaxLen = iLenL + iLenR + 1 ; for ( i = 0 ; i < iLeafCountL ; i ++ ) { mseq -> seq [ piLeafListL [ i ] ] = CKREALLOC ( mseq -> seq [ piLeafListL [ i ] ] , iMaxLen ) ; } for ( i = 0 ; i < iLeafCountR ; i ++ ) { mseq -> seq [ piLeafListR [ i ] ] = CKREALLOC ( mseq -> seq [ piLeafListR [ i ] ] , iMaxLen ) ; } for ( i = 0 ; i < iLeafCountL ; i ++ ) { ppcProfile1 [ i ] = mseq -> seq [ piLeafListL [ i ] ] ; } ppcProfile1 [ i ] = NULL ; for ( i = 0 ; i < iLeafCountR ; i ++ ) { ppcProfile2 [ i ] = mseq -> seq [ piLeafListR [ i ] ] ; } ppcProfile2 [ i ] = NULL ; if ( ( 1 == iLeafCountL ) && ( 1 == iLeafCountR ) ) { if ( ( ' ' == ppcProfile1 [ 0 ] [ 0 ] ) && ( ' ' == ppcProfile2 [ 0 ] [ 0 ] ) ) { #define NOTX  'N' ppcProfile1 [ 0 ] [ 0 ] = NOTX ; ppcProfile2 [ 0 ] [ 0 ] = NOTX ; } if ( ( ' ' == ppcProfile1 [ 0 ] [ iLenL - 1 ] ) && ( ' ' == ppcProfile2 [ 0 ] [ iLenR - 1 ] ) ) { ppcProfile1 [ 0 ] [ iLenL - 1 ] = NOTX ; ppcProfile2 [ 0 ] [ iLenR - 1 ] = NOTX ; } } if ( NULL != pdSeqWeights ) { dWeight = 0.00 ; for ( i = 0 ; i < iLeafCountL ; i ++ ) { register double dAux = pdSeqWeights [ piLeafListL [ i ] ] ; #ifndef NDEBUG if ( dAux <= 0.00 ) { Log ( & rLog , LOG_DEBUG , " " , piLeafListL [ i ] , dAux ) ; } #endif pdWeightsL [ i ] = dAux ; dWeight += dAux ; } dWeightInv = 1.00 / dWeight ; for ( i = 0 ; i < iLeafCountL ; i ++ ) { pdWeightsL [ i ] *= dWeightInv ; } dWeight = 0.00 ; for ( i = 0 ; i < iLeafCountR ; i ++ ) { register double dAux = pdSeqWeights [ piLeafListR [ i ] ] ; #ifndef NDEBUG if ( dAux <= 0.00 ) { Log ( & rLog , LOG_DEBUG , " " , piLeafListR [ i ] , dAux ) ; } #endif pdWeightsR [ i ] = dAux ; dWeight += dAux ; } dWeightInv = 1.00 / dWeight ; for ( i = 0 ; i < iLeafCountR ; i ++ ) { pdWeightsR [ i ] *= dWeightInv ; } } else { pdWeightsL [ 0 ] = pdWeightsR [ 0 ] = -1.00 ; } #if TRACE for ( i = 0 ; i < iLeafCountL ; i ++ ) { Log ( & rLog , LOG_FORCED_DEBUG , " " , i , iLeafCountR , piLeafListL [ i ] , ppcProfile1 [ i ] ) ; } for ( i = 0 ; i < iLeafCountR ; i ++ ) { Log ( & rLog , LOG_FORCED_DEBUG , " " , i , iLeafCountR , piLeafListR [ i ] , ppcProfile2 [ i ] ) ; } #endif return ; }
@brief reallocate enough memory for alignment and
 attach sequence pointers to profiles
@brief reallocate enough memory for alignment and attach sequence pointers to profiles
/* length of 1st profile */ /* length of 2nd profile */ /* maximum possible length of alignment */ /* aux */ /* get length of profiles,
     * in a profile all sequences should have same length so only look at 1st
     */ /* reallocate enough memory for sequences in alignment (for adding
     * gaps)
     */ /* attach sequences to profiles
     */ /* remove terminal 'X' for single sequences:
     * it is a quirk of hhalign() to delete 2 individual sequences
     * if 2 terminal X's meet during alignment,
     * just replace (one of) them.
     * this can be undone at the end.
     * profiles -consisting of more than 1 sequence-
     * appear to be all-right.
     * there seems to be no problem with B's and Z's
     */ /* FIXME: arbitrary assignment */ /* FIXME: arbitrary assignment */ /* FIXME: arbitrary assignment */ /* FIXME: arbitrary assignment */ /* obtain sequence weights
     */ /* 0 <= i < iLeafCountL */ /* 0 <= i < iLeafCountL */ /* (NULL != pdSeqWeights) */