Example #1
0
MAT expected_intensities(const real_t lambda, const NUC * bases,
                         const MAT M, const MAT P, const MAT N, MAT e) {
    validate(lambda>=0,NULL);
    validate(NULL!=bases,NULL);
    validate(NULL!=M,NULL);
    validate(NULL!=P,NULL);
    validate(NULL!=N,NULL);
    const uint_fast32_t ncycle = P->nrow;
    if(NULL==e) {
        e = new_MAT(NBASE,ncycle);
        validate(NULL!=e,NULL);
    }
    memset(e->x, 0, NBASE*ncycle*sizeof(real_t));

    if(has_ambiguous_base(bases,ncycle)) {
        for(uint_fast32_t cy2=0 ; cy2<ncycle ; cy2++) {
            for(uint_fast32_t cy=0 ; cy<ncycle ; cy++) {
                const uint_fast32_t base = bases[cy];
                if(!isambig(base)) {
                    for ( uint_fast32_t ch=0 ; ch<NBASE ; ch++) {
                        e->x[cy2*NBASE+ch] += M->x[base*NBASE+ch] * P->x[cy2*ncycle+cy];
                    }
                }
            }
        }
    } else {
        for(uint_fast32_t cy2=0 ; cy2<ncycle ; cy2++) {
            for(uint_fast32_t cy=0 ; cy<ncycle ; cy++) {
                const uint_fast32_t base = bases[cy];
                for ( uint_fast32_t ch=0 ; ch<NBASE ; ch++) {
                    e->x[cy2*NBASE+ch] += M->x[base*NBASE+ch] * P->x[cy2*ncycle+cy];
                }
            }
        }
    }

    // Multiply by brightness;
    scale_MAT(e,lambda);
    // Add noise
    for ( uint_fast32_t i=0 ; i<(NBASE*ncycle) ; i++) {
        e->x[i] += N->x[i];
    }
    return e;
}
Example #2
0
/**
 * Accumulate covariance matrix (ncycle * NBASE x ncycle * NBASE).
 * Only lower triangular matrix is accumulated.
 * Note: If V is NULL, the required memory is allocated.
 * - p:        Matrix of processed intensities
 * - lambda:   Brightness of cluster
 * - base:     Current base call
 * - do_full:  Calculate full covariance matrix, or just band suitable for fitting Omega
 * - V:        Covariance matrix used for accumulation
 */
static MAT  accumulate_covariance( const real_t we, const MAT p, const real_t lambda, const NUC * base, const bool do_full, MAT V) {
    validate(NULL!=p, NULL);
    validate(NBASE==p->nrow, NULL);
    validate(lambda>=0.0, NULL);

    const uint_fast32_t ncycle = p->ncol;
    const int lda = ncycle * NBASE;

    // Allocate memory for V if necessary
    if (NULL==V) {
        V = new_MAT(lda, lda);
        if (NULL==V) {
            return NULL;
        }
    }

    // Perform accumulation. V += R R^t
    // Note: R = P - \lambda I_b, where I_b is unit vector with b'th elt = 1
    for (uint_fast32_t cy = 0; cy < ncycle; cy++) {
        if (!isambig(base[cy])) {
            p->x[cy * NBASE + base[cy]] -= lambda;
        }
    }
    if ( do_full ) {
        syr(LAPACK_LOWER, &lda, &we, p->x, LAPACK_UNIT, V->x, &lda);
    }
    else {
        // Only update base*base blocks on the diagonal or immediately above and below it
        // Update more elements than necessary but excess are ignored later.
        for ( int i=0 ; i<lda ; i++) {
            for ( int j=i ; j<i+2*NBASE ; j++ ) {
                if(j>=lda) {
                    break;
                }
                V->x[i*lda+j] += we * p->x[i] * p->x[j];
            }
        }
    }

    return V;
}
int dofqfile(char *filename)
{
   int i, found;
   char *p;

   found = NOTFOUND;
   if (tryboth)         /* No suffix was supplied: we add .com, .exe and .cmd */
     {
       p = filename + strlen(filename);
       for (i = 0; i < NUMSUFFIXES; i++)
          {
             strcpy(p, suffixes[i]);
             found = dofsfile(filename);
             if (found == FOUND && !isambig(filename))
               return(FOUND);
          }
     }        /* file was specified with an extension of exe, com or cmd */
   else
     found = dofsfile(filename);
   return(found);
}
int do_a_file(char *filename)    /* may still be ambiguous */
{
   int rc;
   struct charchain *pathp;

   if (isfq(filename))
     {
       rc = dofqfile(filename);                          //@1c
       return(DONE);
     }
   else
     {
       for (pathp = pathroot; pathp; pathp = pathp->next)
          {
                   rc = donotfqfile(filename, pathp->name);
                   if ( (rc == FOUND) && !isambig(filename) )
                     return(DONE);
          }   /* end FOR */
     }
   return(UNDONE);
}
int dofsfile(char *filename)
{
   char result[CCHMAXPATH];
   int  rc, attrib;
   int  found = NOTFOUND;

   if (fmf_init(filename, FMF_ALL_FILES, FMF_NO_SUBDIR))
     return(NOTFOUND);
   else
     {
        do
          {
             rc = fmf_return_next(result, &attrib);
             if (rc == 0)
               {
                 showresult(result);
                 found = FOUND;
               }
          } while (!rc && isambig(filename));
     }
   fmf_close();
   return(found);
}