Beispiel #1
0
void printmatl(double *a, int m, int n)
/**
 print a matrix n wide m rows
*/
{
    printmatwl(a, m, n, 5) ;
}
Beispiel #2
0
void dopop3out(char **fglist,  SNP **xsnplist, int ncols, char *line, char *outpop) 
{
  Indiv **xindlist ;
  Indiv *indx ;
  int *xindex, *xtypes ;
  int nrows ;
  int t, k, i, trun ;
  double f3score, f3scoresig ;
  double f2score, f2scoresig, y, y1, y2, p, q ;
  char *eglist[4] ;
  int numeg = 4 ;
  double ytop, ybot, yxbot ;
  double ztop, zbot ;
  int col ; 
  SNP *cupt ;
  double zztop[6], yytop[6] ; 
  double u, s1, s2, atop, btop, alphabot, betabot, alphatop ;
  double ya, yb, za, zb, yt ;
  char obuff[1024], *sx ;
  int nsnp = 0 ;


  copystrings(fglist, eglist, 3) ; 
  eglist[3] = strdup(outpop) ;

  ZALLOC(xindex, numindivs, int) ;
  ZALLOC(xindlist, numindivs, Indiv *) ;
  

  setstatusv(indivmarkers, numindivs, NULL, NO) ;
  setstatuslist(indivmarkers, numindivs, eglist, numeg) ;
  
  nrows = loadindx(xindlist, xindex, indivmarkers, numindivs) ;
  
  if (nrows == 0) {
   for (i=0; i<numeg; ++i) { 
    printf("zz %s\n", eglist[i]) ;
   }
   fatalx("fatal error (probably missing pop)\n") ;
  }

  ZALLOC(xtypes, nrows, int) ;


  for (i=0; i<nrows; i++) {
    indx = xindlist[i] ;
    k = indxindex(eglist, numeg, indx -> egroup) ;
    xtypes[i] = k ;
  }

   ztop = zbot = 0.0 ;
   vzero(zztop, 6) ;
   for (col=0; col<ncols;  ++col)  {
    cupt = xsnplist[col] ;
    if (cupt -> ignore) continue ;
    loadaa(cupt, xindex, xtypes, nrows, numeg) ;

    f3scz(&ytop,  &ybot, cupt, indivmarkers, xindex, xtypes, nrows, 2, 0, 1) ;
    if (isnan(ytop)) fatalx("zznan\n") ;
    if (ybot < -0.5) continue ;
    f3scz(&yytop[0],  &yxbot, cupt, indivmarkers, xindex, xtypes, nrows, 3, 0, 1) ; if (yxbot < -0.5) continue ;
    f3scz(&yytop[1],  &yxbot, cupt, indivmarkers, xindex, xtypes, nrows, 3, 0, 2) ; if (yxbot < -0.5) continue ;
    f3scz(&yytop[2],  &yxbot, cupt, indivmarkers, xindex, xtypes, nrows, 3, 1, 2) ; if (yxbot < -0.5) continue ;
    f2scz(&yytop[3],  &yxbot, cupt, indivmarkers, xindex, xtypes, nrows, 3, 0, 3) ; if (yxbot < -0.5) continue ;
    f2scz(&yytop[4],  &yxbot, cupt, indivmarkers, xindex, xtypes, nrows, 3, 1, 3) ; if (yxbot < -0.5) continue ;
    f2scz(&yytop[5],  &yxbot, cupt, indivmarkers, xindex, xtypes, nrows, 3, 2, 3) ; if (yxbot < -0.5) continue ;
    ztop += ytop ;
    zbot += ybot ;
    if ((ytop>0) || (ybot > 0)) ++nsnp  ; // monomorphic snps not counted
    vvp(zztop, zztop, yytop, 6) ;
   }
//verbose = YES ; 
   ztop /= zbot ;
   vst(zztop, zztop, 1.0/zbot, 6) ;
    u = zztop[0] ; 
    vsp(yytop, zztop, -u, 6) ;
    s1 = yytop[1] ; /* alpha a */
    s2 = yytop[2] ; 
    atop = yytop[3] ;
    btop = yytop[4] ; 
    alphabot = s1/atop ; 
    betabot =  s2/btop ; 
    alphatop = 1.0-betabot ;
 
    y1 = -ztop -s1 ;  
    if (s2>s1) { 
     alphabot = MAX(alphabot, y1/(s2-s1)) ;  
    }
    if (s2<s1) { 
     alphatop = MIN(alphatop, y1/(s2-s1)) ;  
    }
    
    
  sx = obuff ;
  sx += sprintf(sx, "%s", line) ;  
//printf(" %12.6f", ztop) ;
  sx += sprintf(sx, " %9.3f", alphabot) ;
  sx += sprintf(sx, " %9.3f", alphatop) ;
/**
// next code is computing bounds on h (drift -> C) 
  za = alphatop; zb = 1.0-za ;
  ya = s1/za; yb = s2/zb; yt = -za*zb*(ya+yb) ; y1 = ztop - yt ; 
  za = alphabot; zb = 1.0-za ;
  ya = s1/za; yb = s2/zb; yt = -za*zb*(ya+yb) ; y2 = ztop - yt ; 
  sx += sprintf(sx, "     %9.3f %9.3f", y1, y2) ;
  sx += sprintf(sx, " %7d", nsnp) ;
*/
  printf("%s", obuff) ;
  printnl() ; 
  if (verbose) printmatwl(yytop, 1, 6, 6) ;
  if (outputname != NULL) {  
   fprintf(ofile, "%s\n", obuff) ;
   fflush(ofile) ;
  }

  free(xtypes) ;
  free(xindex) ;
  free(xindlist) ;
  freeup(eglist, 4) ;
  destroyaa() ;

  return  ;

}