Beispiel #1
0
void
ebl_wstrtabfinalize (struct Ebl_WStrtab *st, Elf_Data *data)
{
  size_t copylen;
  wchar_t *endp;
  size_t nulllen = st->nullstr ? 1 : 0;

  /* Fill in the information.  */
  data->d_buf = malloc ((st->total + nulllen) * sizeof (wchar_t));
  if (data->d_buf == NULL)
    abort ();

  /* The first byte must always be zero if we created the table with a
     null string.  */
  if (st->nullstr)
    *((wchar_t *) data->d_buf) = L'\0';

  data->d_type = ELF_T_BYTE;
  data->d_size = st->total + nulllen;
  data->d_off = 0;
  data->d_align = 1;
  data->d_version = EV_CURRENT;

  /* Now run through the tree and add all the string while also updating
     the offset members of the elfstrent records.  */
  endp = (wchar_t *) data->d_buf + nulllen;
  copylen = sizeof (wchar_t) * nulllen;
  copystrings (st->root, &endp, &copylen);
  assert (copylen == (st->total + nulllen) * sizeof (wchar_t));
}
static void
copystrings (struct Ebl_Strent *nodep, char **freep, size_t *offsetp)
{
  if (nodep->left != NULL)
    copystrings (nodep->left, freep, offsetp);

  /* Process the current node.  */
  nodep->offset = *offsetp;
  *freep = (char *) mempcpy (*freep, nodep->string, nodep->len);
  *offsetp += nodep->len;

  for (struct Ebl_Strent *subs = nodep->next; subs != NULL; subs = subs->next)
    {
      assert (subs->len < nodep->len);
      subs->offset = nodep->offset + nodep->len - subs->len;
      assert (subs->offset != 0 || subs->string[0] == '\0');
    }

  if (nodep->right != NULL)
    copystrings (nodep->right, freep, offsetp);
}
void *
strtabfinalize (struct Strtab *st, size_t *size)
{
  size_t copylen;
  char *endp;
  char *retval;

  /* Fill in the information.  */
  endp = retval = (char *) xmalloc (st->total + 1);

  /* Always put an empty string at the beginning so that a zero offset
     can mean error.  */
  *endp++ = '\0';

  /* Now run through the tree and add all the string while also updating
     the offset members of the elfstrent records.  */
  copylen = 1;
  copystrings (st->root, &endp, &copylen);
  assert (copylen == st->total + 1);
  assert (endp = retval + st->total + 1);
  *size = copylen;

  return retval;
}
Beispiel #4
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  ;

}