コード例 #1
0
ファイル: dowtjack.c プロジェクト: b1234561/AdmixTools
void
callwtjack(char *iname, char *oname) 
{
  FILE *ifile, *ofile ;
  char line[MAXSTR];
  char *sx;
  char *spt[MAXFF];
  int nsplit, len, i, k;
  char c;
 
  openit(iname, &ifile, "r") ;
  openit(oname, &ofile, "w") ;

  double *jwt, *jmean;
  
  /* output variable */
  double est, sig;   // NB
  est =0; sig=0;

  /*input variables */
  len = numlines(iname);
  ZALLOC(jwt, len, double);     
  ZALLOC(jmean, len, double);
  k = 0;

 /* read input file and store data */
  while (fgets(line,MAXSTR,ifile) != NULL)  
  {
	nsplit = splitup(line, spt, MAXFF);
	sx = spt[0];
	c = sx[0];
	if (c == '#') {
		freeup(spt, nsplit);
		continue;
	}
	
	jwt[k] = atof(spt[1]);
	jmean[k] = atof(spt[2]);
	//printf("mean: %9.3f len: %9.3f\n", jmean[k], jwt[k]) ;
	k++;
	freeup(spt, nsplit);
  }  
  len = k ;  // better style  who knows how numlines handles commas
 fclose(ifile) ;
 // printf("mean: %9.3f len: %d\n", mean, len) ;


 /*call weightjack */
	weightjack(&est, &sig, mean, jmean, jwt, len);
	fprintf(ofile,"%9.3f", est);	 	// d format ??
	fprintf(ofile,"%9.3f", sig);	 	
	fprintf(ofile,"\n");
	free(jmean);
	free(jwt);
 fclose(ofile) ;

 }
コード例 #2
0
ファイル: twstats.c プロジェクト: jiaolongsun/EIG
int
main (int argc, char **argv)
{
  FILE *ofile;
  int nlambda = 0;
  int i, m;
  double zn, zvar, tw, tail;
  double *xx[0], *lambda;

  readcommands (argc, argv);
  settwxtable (twxtab);

  if (oname == NULL)
    ofile = stdout;
  else
    openit (oname, &ofile, "w");

  if (iname == NULL)
    fatalx ("i paraameter compulsory\n");
  nlambda = numlines (iname);
  ZALLOC(lambda, nlambda, double);
  xx[0] = lambda;
  nlambda = getxx (xx, nlambda, 1, iname);
  vst (lambda, lambda, -1.0, nlambda);
  sortit (lambda, NULL, nlambda);
  vst (lambda, lambda, -1.0, nlambda);
  m = numgtz (lambda, nlambda);

  fprintf (ofile, "%4s  %12s", "#N", "eigenvalue");
  fprintf (ofile, "%12s", "difference");
  fprintf (ofile, " %9s %12s", "twstat", "p-value");
  fprintf (ofile, " %9s", "effect. n");
  fprintf (ofile, "\n");

  for (i = 0; i < m; ++i)
    {

      zn = nval;
      tail = dotwcalc (lambda + i, m - i, &tw, &zn, &zvar, minleneig);
      fprintf (ofile, "%4d  %12.6f", i + 1, lambda[i]);
      if (i == 0)
        fprintf (ofile, "%12s", "NA");
      else
        fprintf (ofile, "%12.6f", lambda[i] - lambda[i - 1]);
      if (tail >= 0.0)
        fprintf (ofile, " %9.3f %12.6g", tw, tail);
      else
        fprintf (ofile, " %9s %12s", "NA", "NA");
      if (zn > 0.0)
        {
          fprintf (ofile, " %9.3f", zn);
        }
      else
        {
          fprintf (ofile, " %9s", "NA");
        }
      fprintf (ofile, "\n");
    }
  return 0;
}
コード例 #3
0
ファイル: qpBound.c プロジェクト: b1234561/AdmixTools
int readpopx(char *pname, char ***plists, int npops)  
// reads lists of npops pops on a line
{
 FILE *fff ; 
 char line[MAXSTR+1], c ;
 char *spt[MAXFF], *sx  ;
 char **pp ;
 int nsplit,  t, num = 0  ;

 openit(pname, &fff, "r") ;
 line[MAXSTR] = '\0' ;
 while (fgets(line, MAXSTR, fff) != NULL)  {
   nsplit = splitup(line, spt, MAXFF) ;
   if (nsplit == 0) continue ;
   sx = spt[0] ; 
   if (sx[0] == '#')  {  
    freeup(spt, nsplit) ;
    continue ;
   }
   if (nsplit < npops) fatalx("length mismatch %s\n", line) ;
   ZALLOC(plists[num], npops+1, char *) ;
   plists[num][npops] == NULL ;
   pp = plists[num] ;
   for (t=0; t<npops; ++t) {  
    pp[t] = strdup(spt[t]) ;
   }
   striptrail(line, '\n') ;
   lines[num] = strdup(line) ; 
   ++num ; 
   freeup(spt, nsplit) ;
  }
  fclose(fff) ;
  return num ;
}
コード例 #4
0
ファイル: strsubs.c プロジェクト: galaxysd/AdmixTools
int numlines(char *name)
// number of lines   no comments or blanks
{
    FILE *fff ;
    char line[MAXSTR] ;
    char *spt[MAXSTR] ;
    char *sx ;
    int nsplit, num=0 ;

    num = 0;
    if (name == NULL) fatalx("(numlines)  no name")  ;
    openit(name, &fff, "r") ;
    while (fgets(line, MAXSTR, fff) != NULL)  {
        nsplit = splitup(line, spt, MAXFF) ;
        if (nsplit==0) continue ;
        sx = spt[0] ;
        if (sx[0] == '#') {
            freeup(spt, nsplit) ;
            continue ;
        }
        ++num ;
        freeup(spt, nsplit) ;
    }
    fclose(fff) ;
    return num ;
}
コード例 #5
0
ファイル: s_main.c プロジェクト: jyg/pure-data
void glob_initfromgui(void *dummy, t_symbol *s, int argc, t_atom *argv)
{
    char *cwd = atom_getsymbolarg(0, argc, argv)->s_name;
    t_namelist *nl;
    unsigned int i;
    int did_fontwarning = 0;
    int j;
    sys_oldtclversion = atom_getfloatarg(1, argc, argv);
    if (argc != 2 + 3 * NZOOM * NFONT)
        bug("glob_initfromgui");
    for (j = 0; j < NZOOM; j++)
        for (i = 0; i < NFONT; i++)
    {
        int size   = atom_getfloatarg(3 * (i + j * NFONT) + 2, argc, argv);
        int width  = atom_getfloatarg(3 * (i + j * NFONT) + 3, argc, argv);
        int height = atom_getfloatarg(3 * (i + j * NFONT) + 4, argc, argv);
        if (!(size && width && height))
        {
            size   = (j+1)*sys_fontspec[i].fi_pointsize;
            width  = (j+1)*sys_fontspec[i].fi_width;
            height = (j+1)*sys_fontspec[i].fi_height;
            if (!did_fontwarning)
            {
                verbose(1, "ignoring invalid font-metrics from GUI");
                did_fontwarning = 1;
            }
        }
        sys_gotfonts[j][i].fi_pointsize = size;
        sys_gotfonts[j][i].fi_width = width;
        sys_gotfonts[j][i].fi_height = height;
#if 0
            fprintf(stderr, "font (%d %d %d)\n",
                sys_gotfonts[j][i].fi_pointsize, sys_gotfonts[j][i].fi_width,
                    sys_gotfonts[j][i].fi_height);
#endif
    }
        /* load dynamic libraries specified with "-lib" args */
    if (sys_oktoloadfiles(0))
    {
        for  (nl = STUFF->st_externlist; nl; nl = nl->nl_next)
            if (!sys_load_lib(0, nl->nl_string))
                post("%s: can't load library", nl->nl_string);
        sys_oktoloadfiles(1);
    }
        /* open patches specifies with "-open" args */
    for  (nl = sys_openlist; nl; nl = nl->nl_next)
        openit(cwd, nl->nl_string);
    namelist_free(sys_openlist);
    sys_openlist = 0;
        /* send messages specified with "-send" args */
    for  (nl = sys_messagelist; nl; nl = nl->nl_next)
    {
        t_binbuf *b = binbuf_new();
        binbuf_text(b, nl->nl_string, strlen(nl->nl_string));
        binbuf_eval(b, 0, 0, 0);
        binbuf_free(b);
    }
    namelist_free(sys_messagelist);
    sys_messagelist = 0;
}
コード例 #6
0
ファイル: convertf.c プロジェクト: b1234561/AdmixTools
void flipsnps(char *fsname, SNP **snpm, int numsnps, int phasedmode) 
{
  FILE *fff ;
  char line[MAXSTR] ;
  char *spt[MAXFF] ;
  char *ss ;
  int nsplit, n, k ;
  SNP *cupt ; 

  if (fsname == NULL) return ;
  openit (fsname, &fff, "r") ;

  freesnpindex() ;

  while (fgets(line, MAXSTR, fff) != NULL)  {
    nsplit = splitup(line, spt, MAXFF) ; 
    if (nsplit==0) continue ;
    if (spt[0][0] == '#') { 
     freeup(spt, nsplit) ;
     continue ;
    }
    
     k = snpindex(snpm, numsnps, spt[0]) ;      
     if (k>=0) {
      flip1(snpm[k], phasedmode, flipreference) ;
     }
    freeup(spt, nsplit) ;
  }
  fclose (fff) ;
}
コード例 #7
0
ファイル: convertf.c プロジェクト: b1234561/AdmixTools
void flipstrand(char *fsname, SNP **snpm, int numsnps) 
// move alleles to opposite strand
{
  FILE *fff ;
  char line[MAXSTR] ;
  char *spt[MAXFF] ;
  char *ss ;
  int nsplit, n, k ;
  SNP *cupt ; 

  if (fsname == NULL) return ;
  openit (fsname, &fff, "r") ;

  freesnpindex() ;

  while (fgets(line, MAXSTR, fff) != NULL)  {
    nsplit = splitup(line, spt, MAXFF) ; 
    if (nsplit==0) continue ;
    if (spt[0][0] == '#') { 
     freeup(spt, nsplit) ;
     continue ;
    }
    
     k = snpindex(snpm, numsnps, spt[0]) ;      
     if (k>=0) {
      cupt = snpm[k] ;
      cupt -> alleles[0] = compbase(cupt -> alleles[0]) ;
      cupt -> alleles[1] = compbase(cupt -> alleles[1]) ;
     }
    freeup(spt, nsplit) ;
  }
  fclose (fff) ;
}
コード例 #8
0
ファイル: STDIOLIB.C プロジェクト: AnimatorPro/Animator-Pro
main(int argc,char **argv)
{
	openit(argc,argv);

	sioset(fdata);
	sioset(pj__get_pto_errno);
	sioset(clearerr);
	sioset(feof);
	sioset(ferror);
	sioset(pj_errno_errcode);

	sioset(fopen);
	sioset(fclose);

	sioset(fseek);
	sioset(ftell);
	sioset(fflush);
	sioset(rewind);

	sioset(fread);
	sioset(fgetc);
	sioset(fgets);
	sioset(ungetc);

	sioset(fwrite);
	sioset(fputc);
	sioset(fputs);
	sioset(fprintf);

	sioset(printf);
	sioset(sprintf);

	closeit();
}
コード例 #9
0
ファイル: strsubs.c プロジェクト: chrchang/eigensoft
int numcols(char *name)
// number of cols 
{
  FILE *fff ;
  char line[MAXSTR] ;
  char *spt[MAXSTR] ;
  char *sx ;
  int nsplit ;

  if (name == NULL) fatalx("(numlines)  no name")  ;
  openit(name, &fff, "r") ;
  while (fgets(line, MAXSTR, fff) != NULL)  {
   nsplit = splitup(line, spt, MAXFF) ; 
   if (nsplit==0) continue ;
   sx = spt[0] ;
   if (sx[0] == '#') {
    freeup(spt, nsplit) ;
    continue ;
   }
   freeup(spt, nsplit) ;
   fclose(fff) ;
   return nsplit ;
  }
  return 0; // empty file; should this be a fatal error?
}
コード例 #10
0
ファイル: s_main.c プロジェクト: rfabbri/pd-extended-core
void glob_initfromgui(void *dummy, t_symbol *s, int argc, t_atom *argv)
{
    char *cwd = atom_getsymbolarg(0, argc, argv)->s_name;
    t_namelist *nl;
    unsigned int i;
    int j;
    int nhostfont = (argc-2)/3;
    sys_oldtclversion = atom_getfloatarg(1, argc, argv);
    if (argc != 2 + 3 * nhostfont) bug("glob_initfromgui");
    for (i = 0; i < NFONT; i++)
    {
        int best = 0;
        int wantheight = sys_fontlist[i].fi_maxheight;
        int wantwidth = sys_fontlist[i].fi_maxwidth;
        for (j = 1; j < nhostfont; j++)
        {
            if (atom_getintarg(3 * j + 4, argc, argv) <= wantheight &&
                atom_getintarg(3 * j + 3, argc, argv) <= wantwidth)
                    best = j;
        }
            /* best is now the host font index for the desired font index i. */
        sys_fontlist[i].fi_hostfontsize =
            atom_getintarg(3 * best + 2, argc, argv);
        sys_fontlist[i].fi_width = atom_getintarg(3 * best + 3, argc, argv);
        sys_fontlist[i].fi_height = atom_getintarg(3 * best + 4, argc, argv);
    }
#if 0
    for (i = 0; i < 6; i++)
        fprintf(stderr, "font (%d %d %d) -> (%d %d %d)\n",
            sys_fontlist[i].fi_fontsize,
            sys_fontlist[i].fi_maxwidth,
            sys_fontlist[i].fi_maxheight,
            sys_fontlist[i].fi_hostfontsize,
            sys_fontlist[i].fi_width,
            sys_fontlist[i].fi_height);
#endif
        /* auto-load anything in that is in startupdir */
    if(!sys_nostartup)
        sys_loadstartup();
        /* load dynamic libraries specified with "-lib" args */
    for  (nl = sys_externlist; nl; nl = nl->nl_next)
        if (!sys_load_lib(0, nl->nl_string))
            post("%s: can't load library", nl->nl_string);
        /* open patches specifies with "-open" args */
    for  (nl = sys_openlist; nl; nl = nl->nl_next)
        openit(cwd, nl->nl_string);
    namelist_free(sys_openlist);
    sys_openlist = 0;
        /* send messages specified with "-send" args */
    for  (nl = sys_messagelist; nl; nl = nl->nl_next)
    {
        t_binbuf *b = binbuf_new();
        binbuf_text(b, nl->nl_string, strlen(nl->nl_string));
        binbuf_eval(b, 0, 0, 0);
        binbuf_free(b);
    }
    namelist_free(sys_messagelist);
    sys_messagelist = 0;
}
コード例 #11
0
ファイル: WNDO.C プロジェクト: AnimatorPro/Animator-Pro
main(int argc,char **argv)
{
	openit(argc,argv);
	prtf(W_RASTS, rasts);
	prtf(W_BEHIND, behind);
	prtf(W_ONERAST, onerast);
	prtf(W_YDOTS, ydots);
	closeit();
}
コード例 #12
0
ファイル: smartrel.c プロジェクト: b1234561/EIG
void
writesnpeigs(char *snpeigname, SNP **xsnplist, double *ffvecs, int numeigs, int ncols) 
{
// this is called at end and ffvecs overwritten
  double *xpt, y, yscal, *snpsc ;
  int i, j, k, kmax, kmin ;
  SNP * cupt  ;
  FILE *fff ;
  
  for (j=0; j<numeigs; ++j) {  
   xpt = ffvecs+j*ncols ;  
   y = asum2(xpt, ncols) ;  
   yscal = (double) ncols / y ;
   yscal = sqrt(yscal) ;
   vst(xpt, xpt, yscal, ncols) ;
  }


  ZALLOC(snpsc, ncols, double) ;
  vclear(snpsc, -99999, ncols) ;
  for (j=0; j<numeigs; ++j) {  
   for (i=0; i<ncols; ++i) {  
    cupt = xsnplist[i] ;
    if (cupt -> ignore) continue ;
    y = ffvecs[j*ncols+i] ;
    snpsc[i] = fabs(y) ; 
   }
   for (k=0; k<=10; ++k) { 
    vlmaxmin(snpsc, ncols, &kmax, &kmin) ;
    cupt = xsnplist[kmax] ;
    printf("eigbestsnp %4d %20s %2d %12d %9.3f\n", j+1, cupt -> ID, cupt -> chrom, nnint(cupt -> physpos), snpsc[kmax]) ;
    snpsc[kmax] = -1.0 ;
   }
  }
  free(snpsc) ;


  if (snpeigname == NULL) return ;
  openit (snpeigname, &fff, "w") ;

  for (i=0; i<ncols; ++i) {  
   cupt = xsnplist[i] ;
   if (cupt -> ignore) continue ;

   fprintf(fff, "%20s", cupt -> ID) ;
   fprintf(fff,  " %2d", cupt -> chrom) ;
   fprintf(fff,  " %12d", nnint(cupt -> physpos)) ;

   for (j=0; j<numeigs; ++j) {  
    fprintf(fff, " %9.3f", ffvecs[j*ncols+i]) ;  
   }
   fprintf(fff, "\n") ;
  }

  fclose(fff) ;

}
コード例 #13
0
ファイル: strsubs.c プロジェクト: galaxysd/AdmixTools
int
getnamesstripcolon(char ****pnames, int maxrow, int numcol, char *fname, int lo, int hi)
{

// count is base 1
    char line[MAXSTR] ;
    char *spt[MAXFF] ;
    char *sx ;
    int nsplit, i, j, num=0, maxff, numcolp, lcount=0 ;
    FILE *fff ;
    int nbad = 0 ;
    char ***names ;

    names = *pnames ;
    if (fname == NULL) fff = stdin ;
    else {
        openit(fname, &fff, "r") ;
    }
    numcolp = numcol + 1 ;
    maxff = MAX(MAXFF, numcolp) ;

    while (fgets(line, MAXSTR, fff) != NULL)  {
        subcolon(line) ;
        nsplit = splitup(line, spt, maxff) ;
        if (nsplit == 0) {
            freeup(spt, nsplit) ;
            continue ;
        }
        sx = spt[0] ;
        if (sx[0] == '#') {
            freeup(spt, nsplit) ;
            continue ;
        }
        if (nsplit<numcol) {
            ++nbad ;
            if (nbad<10) printf("+++ bad line: nsplit: %d numcol: %d\n%s\n", nsplit, numcol, line) ;
            continue ;
        }
        ++lcount ;
        if ((lcount<lo) || (lcount>hi)) {
            freeup(spt, nsplit) ;
            continue ;
        }
        if (num>=maxrow) fatalx("too much data\n") ;
        for (i=0; i<numcol; i++)  {
            names[i][num] = strdup(spt[i]) ;
        }
        freeup(spt, nsplit) ;
        ++num ;
    }
    if (fname != NULL) fclose(fff) ;
    return num ;
}
コード例 #14
0
void test2() {
  int i;
  create_big_file("test2file");
  unsigned char key[KEY_LENGTH];
  for (i = 0; i < KEY_LENGTH; ++i) key[i] = (unsigned char) (110 - i);

  for (i = 1; i <= 3; ++i) {
    int p2fd;
    pyramid* p = openit("test2file", &p2fd, key, i);
    print_ids(p, 2);
    closeit(p2fd, p, i);
  }
  
}
コード例 #15
0
void test3() {
  int i;
  unsigned char key[KEY_LENGTH];
  for (i = 0; i < KEY_LENGTH; ++i) key[i] = (unsigned char) (rand() % 256);
  create_big_file("test3file");
  for (i = 1; i <= 3; ++i) {
    int p3fd;
    pyramid *p = openit("test3file", &p3fd, key, i);
    print_ids(p, 3);
    move_id_in_pyramid(p, p, randomly_select_id_pyramid(p));
    move_id_in_pyramid(p->next_level, p, randomly_select_id_pyramid(p->next_level));
    move_id_in_pyramid(p->next_level->next_level, p, randomly_select_id_pyramid(p->next_level->next_level));
    print_ids(p, 3);
    closeit(p3fd, p, i);
  }
}
コード例 #16
0
ファイル: strsubs.c プロジェクト: galaxysd/AdmixTools
int
getxxnames(char ***pnames, double **xx, int maxrow, int numcol, char *fname)
{

    char line[MAXSTR] ;
    char *spt[MAXFF] ;
    char *sx ;
    int nsplit, i, j, num=0, maxff, numcolp ;
    FILE *fff ;
    int nbad = 0 ;
    char **names = NULL ;

    if (pnames != NULL) names = *pnames ;
    if (fname == NULL) fff = stdin ;
    else {
        openit(fname, &fff, "r") ;
    }
    numcolp = numcol + 1 ;
    maxff = MAX(MAXFF, numcolp) ;

    while (fgets(line, MAXSTR, fff) != NULL)  {
        nsplit = splitup(line, spt, maxff) ;
        if (nsplit == 0) {
            freeup(spt, nsplit) ;
            continue ;
        }
        sx = spt[0] ;
        if (sx[0] == '#') {
            freeup(spt, nsplit) ;
            continue ;
        }
        if (names != NULL) names[num] = strdup(sx) ;
        if (nsplit<numcolp) {
            ++nbad ;
            if (nbad<10) printf("+++ bad line: nsplit: %d numcol: %d\n%s\n", nsplit, numcol, line) ;
            continue ;
        }
        if (num>=maxrow) fatalx("too much data\n") ;
        for (i=0; i<numcol; i++)  {
            xx[i][num]  = atof(spt[i+1]) ;
        }
        freeup(spt, nsplit) ;
        ++num ;
    }
    if (fname != NULL) fclose(fff) ;
    return num ;
}
コード例 #17
0
ファイル: lockfile.C プロジェクト: Sidnicious/sfslite
bool
lockfile::acquire (bool wait)
{
  for (;;) {
    if (!fdok () && !openit ())
      return false;
    if (islocked)
      return true;

    if (flock (fd, LOCK_EX | (wait ? 0 : LOCK_NB)) < 0) {
      if (wait && errno == EINTR)
	continue;
      return false;
    }

    utimes (path.cstr(), NULL);
    islocked = true;
  }
}
コード例 #18
0
ファイル: strsubs.c プロジェクト: galaxysd/AdmixTools
int
getss(char **ss, char *fname)
/**
 get list of names
*/
{

    char line[MAXSTR] ;
    char qqq[MAXSTR] ;
    char *spt[MAXFF] ;
    char *sx ;
    int nsplit, i, j, num=0, maxff ;
    FILE *fff ;


    if (fname == NULL) fff = stdin ;
    else {
        openit(fname, &fff, "r") ;
    }
    maxff = MAXFF  ;

    while (fgets(line, MAXSTR, fff) != NULL)  {
        nsplit = splitup(line, spt, maxff) ;
        if (nsplit == 0) {
            freeup(spt, nsplit) ;
            continue ;
        }
        sx = spt[0] ;
        if (sx[0] == '#') {
            freeup(spt, nsplit) ;
            continue ;
        }
        if (nsplit<1) {
            continue ;
        }
        ss[num] = strdup(spt[0]) ;
        freeup(spt, nsplit) ;
        ++num ;
    }
    if (fname != NULL) fclose(fff) ;
    return num ;
}
コード例 #19
0
ファイル: dirseek.c プロジェクト: ShaoyuC/OS161
static
void
dotest(void)
{
	printf("Opening directory...\n");
	openit();

	printf("Running tests...\n");

	/* read the whole directory */
	firstread();

	/* make sure eof behaves right */
	readateof();

	/* read all the filenames again by seeking */
	readallonebyone();

	/* try reading at eof */
	doreadateof();

	/* read a bunch of the filenames over and over again */
	readallrandomly();

	/* rewind and read the whole thing again, to make sure that works */
	doreadat0();

	/* do invalid reads */
	dobadreads();

	/* rewind again to make sure the invalid attempts didn't break it */
	doreadat0();

	printf("Closing directory...\n");
	closeit();
}
コード例 #20
0
int main(void)
{
	
#line 14 "test_informix.pgc"
 int i = 14 ;

#line 14 "test_informix.pgc"

	
#line 15 "test_informix.pgc"
 decimal j , m , n ;

#line 15 "test_informix.pgc"

	
#line 16 "test_informix.pgc"
 char c [ 10 ] ;

#line 16 "test_informix.pgc"


	ECPGdebug(1, stderr);
	/* exec sql whenever sqlerror  do dosqlprint ( ) ; */
#line 19 "test_informix.pgc"


	{ ECPGconnect(__LINE__, 1, "ecpg1_regression" , NULL, NULL , NULL, 0); 
#line 21 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 21 "test_informix.pgc"

	if (sqlca.sqlcode != 0) exit(1);

	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "create table test ( i int primary key , j int , c text )", ECPGt_EOIT, ECPGt_EORT);
#line 24 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 24 "test_informix.pgc"


	/* this INSERT works */
	rsetnull(CDECIMALTYPE, (char *)&j);
	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( 7 , $1  , 'test   ' )", 
	ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 28 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 28 "test_informix.pgc"

	{ ECPGtrans(__LINE__, NULL, "commit");
#line 29 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 29 "test_informix.pgc"


	/* this INSERT should fail because i is a unique column */
	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( 7 , 12 , 'a' )", ECPGt_EOIT, ECPGt_EORT);
#line 32 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 32 "test_informix.pgc"

	printf("INSERT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
	if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback");
#line 34 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 34 "test_informix.pgc"


	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "insert into test ( i , j , c ) values ( $1  , 1 , 'a      ' )", 
	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 36 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 36 "test_informix.pgc"

	{ ECPGtrans(__LINE__, NULL, "commit");
#line 37 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 37 "test_informix.pgc"


	/* this will fail (more than one row in subquery) */
	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select i from test where j = ( select j from test )", ECPGt_EOIT, ECPGt_EORT);
#line 40 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 40 "test_informix.pgc"

	{ ECPGtrans(__LINE__, NULL, "rollback");
#line 41 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 41 "test_informix.pgc"


	/* this however should be ok */
	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select i from test where j = ( select j from test order by i limit 1 )", ECPGt_EOIT, ECPGt_EORT);
#line 44 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 44 "test_informix.pgc"

	printf("SELECT: %ld=%s\n", sqlca.sqlcode, sqlca.sqlerrm.sqlerrmc);
	if (sqlca.sqlcode != 0) { ECPGtrans(__LINE__, NULL, "rollback");
#line 46 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 46 "test_informix.pgc"


	sqlca.sqlcode = 100;
	ECPGset_var( 0, &( i ), __LINE__);\
 ECPG_informix_reset_sqlca(); /* declare c cursor for select * from test where i <= $1  */
#line 49 "test_informix.pgc"

	printf ("%ld\n", sqlca.sqlcode);
	openit();

	deccvint(0, &j);

	while (1)
	{
		{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT, 
	ECPGt_int,&(i),(long)1,(long)1,sizeof(int), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_decimal,&(j),(long)1,(long)1,sizeof(decimal), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, 
	ECPGt_string,(c),(long)10,(long)1,(10)*sizeof(char), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
#line 57 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 57 "test_informix.pgc"

		if (sqlca.sqlcode == 100) break;
		else if (sqlca.sqlcode != 0) printf ("Error: %ld\n", sqlca.sqlcode);

		if (risnull(CDECIMALTYPE, (char *)&j))
			printf("%d NULL\n", i);
		else
		{
			int a;

			dectoint(&j, &a);
			printf("%d %d \"%s\"\n", i, a, c);
		}
	}

	deccvint(7, &j);
	deccvint(14, &m);
	decadd(&j, &m, &n);
	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "delete from test where i = $1  :: decimal", 
	ECPGt_decimal,&(n),(long)1,(long)1,sizeof(decimal), 
	ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT, ECPGt_EORT);
#line 75 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 75 "test_informix.pgc"

	printf("DELETE: %ld\n", sqlca.sqlcode);

	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 14", ECPGt_EOIT, ECPGt_EORT);
#line 78 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 78 "test_informix.pgc"

	printf("Exists: %ld\n", sqlca.sqlcode);

	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "select 1 from test where i = 147", ECPGt_EOIT, ECPGt_EORT);
#line 81 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 81 "test_informix.pgc"

	printf("Does not exist: %ld\n", sqlca.sqlcode);

	{ ECPGtrans(__LINE__, NULL, "commit");
#line 84 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 84 "test_informix.pgc"

	{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "drop table test", ECPGt_EOIT, ECPGt_EORT);
#line 85 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 85 "test_informix.pgc"

	{ ECPGtrans(__LINE__, NULL, "commit");
#line 86 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 86 "test_informix.pgc"


	{ ECPGdisconnect(__LINE__, "CURRENT");
#line 88 "test_informix.pgc"

if (sqlca.sqlcode < 0) dosqlprint ( );}
#line 88 "test_informix.pgc"


	return 0;
}
コード例 #21
0
ファイル: smartrel.c プロジェクト: b1234561/EIG
int main(int argc, char **argv)
{

  char **eglist ;
  int numeg ;
  int i, j, k, pos; 
  int *vv ;
  SNP *cupt, *cupt2 ;
  Indiv *indx ;
  double y1, y2, y ;

  int n0, n1, nkill ;

  int nindiv = 0 ;
  int nignore, numrisks = 1 ;
  SNP **xsnplist  ;
  Indiv **xindlist ;
  int *xindex ;
  int nrows, ncols, m ;
  double *XTX, *cc, *evecs, *ww ;
  double *lambda ;
  double *tvecs ;
  int weightmode = NO ;
  int t ;
  double *xmean, *xfancy ;
  double *ldmat = NULL, *ldmat2 = NULL;
  double *ldvv = NULL, *ldvv2 = NULL, *vv2 = NULL ;
  int chrom,  numclear ;
  double gdis ;
  int outliter, numoutiter, *badlist, nbad ;
  int a, b, n ;
  FILE *outlfile ;
  

  int xblock, blocksize=10000 ;   
  double *tblock ;  

  OUTLINFO *outpt ;
  int *idperm, *vecind ;   // for sort

  readcommands(argc, argv) ;
  printf("## smartrel version: %s\n", WVERSION) ;
  packmode = YES ;
  setomode(&outputmode, omode) ;

  if (parname == NULL) return 0 ;
  if (xchrom == (numchrom+1)) noxdata = NO ;

  if (fstonly) { 
   printf("fstonly\n") ;
   numeigs = 0 ; 
   numoutliter = 0 ;
   numoutiter = 0 ;
   outputname = NULL ;
   snpeigname = NULL ;
  }

  if (fancynorm) printf("norm used\n\n") ;
  else printf("no norm used\n\n") ;

  nostatslim = MAX(nostatslim, 3) ;

  outlfile = ofile = stdout; 

  if (outputname != NULL)  openit(outputname, &ofile, "w") ;
  if (outliername != NULL) openit(outliername, &outlfile, "w") ;
  if (fstdetailsname != NULL) openit(fstdetailsname, &fstdetails, "w") ;

  numsnps = 
    getsnps(snpname, &snpmarkers, 0.0, badsnpname, &nignore, numrisks) ;

  numindivs = getindivs(indivname, &indivmarkers) ;
  k = getgenos(genotypename, snpmarkers, indivmarkers, 
    numsnps, numindivs, nignore) ;


  if (poplistname != NULL) 
  { 
    ZALLOC(eglist, numindivs, char *) ; 
    numeg = loadlist(eglist, poplistname) ;
    seteglist(indivmarkers, numindivs, poplistname);
  }
  else
  {
    setstatus(indivmarkers, numindivs, NULL) ;
    ZALLOC(eglist, MAXPOPS, char *) ;
    numeg = makeeglist(eglist, MAXPOPS, indivmarkers, numindivs) ;
  }
  for (i=0; i<numeg; i++) 
  {  
    /* printf("%3d %s\n",i, eglist[i]) ; */
  }

  nindiv=0 ;
  for (i=0; i<numindivs; i++) 
  {
    indx = indivmarkers[i] ;
    if(indx -> affstatus == YES) ++nindiv  ;
  }

  for (i=0; i<numsnps; i++)  
  {  
    cupt = snpmarkers[i] ; 
    chrom = cupt -> chrom ;
    if ((noxdata) && (chrom == (numchrom+1))) cupt-> ignore = YES ;
    if (chrom == 0) cupt -> ignore = YES ;
    if (chrom > (numchrom+1)) cupt -> ignore = YES ;
  }
  for (i=0; i<numsnps; i++)  
  {
    cupt = snpmarkers[i] ; 
    pos = nnint(cupt -> physpos) ;
    if ((xchrom>0) && (cupt -> chrom != xchrom)) cupt -> ignore = YES ;
    if ((xchrom > 0) && (pos < lopos)) cupt -> ignore = YES ;
    if ((xchrom > 0) && (pos > hipos)) cupt -> ignore = YES ;
    if (cupt -> ignore) continue ;
    if (numvalidgtx(indivmarkers, cupt, YES) <= 1) 
    { 
      printf("nodata: %20s\n", cupt -> ID) ;
      cupt -> ignore = YES ;
    }
  }

  if (killr2) {
   nkill = killhir2(snpmarkers, numsnps, numindivs, r2physlim, r2genlim, r2thresh) ;
   if (nkill>0) printf("killhir2.  number of snps killed: %d\n", nkill) ;
  }

  ZALLOC(vv, numindivs, int) ;
  numvalidgtallind(vv, snpmarkers, numsnps,  numindivs) ; 
  for (i=0; i<numindivs; ++i)  { 
  if (vv[i] == 0) {
    indx = indivmarkers[i] ;
    indx -> ignore = YES ; 
   }
  }
  free(vv) ;

  numsnps = rmsnps(snpmarkers, numsnps, NULL) ;  //  rid ignorable snps

   
  if (missingmode) 
  {
    setmiss(snpmarkers, numsnps) ;
    fancynorm = NO ;
  }

  if  (weightname != NULL)   
  {  
    weightmode = YES ;
    getweights(weightname, snpmarkers, numsnps) ;
  }
  if (ldregress>0) 
  {  
    ZALLOC(ldvv,  ldregress*numindivs, double) ;
    ZALLOC(ldvv2,  ldregress*numindivs, double) ;
    ZALLOC(vv2,  numindivs, double) ;
    ZALLOC(ldmat,  ldregress*ldregress, double) ;
    ZALLOC(ldmat2,  ldregress*ldregress, double) ;
    setidmat(ldmat, ldregress) ;         
    vst(ldmat, ldmat, 1.0e-6, ldregress*ldregress) ;
  }

  ZALLOC(xindex, numindivs, int) ;
  ZALLOC(xindlist, numindivs, Indiv *) ;
  ZALLOC(xsnplist, numsnps, SNP *) ;

  if (popsizelimit > 0) 
  {  
    setplimit(indivmarkers, numindivs, eglist, numeg, popsizelimit) ; 
  }

  nrows = loadindx(xindlist, xindex, indivmarkers, numindivs) ;
  ncols = loadsnpx(xsnplist, snpmarkers, numsnps, indivmarkers) ;
  printf("number of samples used: %d number of snps used: %d\n", nrows, ncols) ;

/**
  cupt = xsnplist[0] ;
  for (j=0; j<nrows; ++j) {  
   k = xindex[j] ;
   g = getgtypes(cupt, k) ;
   indx = indivmarkers[k] ;
   t = indxindex(eglist, numeg, indx -> egroup) ;
   printf("yy1 %20s %20s %20s %d %d %d\n", cupt ->ID, indx -> ID, indx -> egroup, j, k, g) ;
  }
  printf("yya: ") ; printimat(xindex, 1, nrows) ;
  printf("zzindxa:  %s\n", indivmarkers[230] -> egroup) ;
*/

  /* printf("## nrows: %d  ncols  %d\n", nrows, ncols) ; */
  ZALLOC(xmean, ncols, double) ;
  ZALLOC(xfancy, ncols, double) ;
  ZALLOC(XTX, nrows*nrows, double) ;
  ZALLOC(evecs, nrows*nrows, double) ;
  ZALLOC(tvecs, nrows*nrows, double) ;
  ZALLOC(lambda, nrows, double) ;
  ZALLOC(cc, nrows, double) ;
  ZALLOC(ww, nrows, double) ;
  ZALLOC(badlist, nrows, int) ;

  blocksize = MIN(blocksize, ncols) ; 
  ZALLOC(tblock, nrows*blocksize, double) ;

  // xfancy is multiplier for column xmean is mean to take off
  // badlist is list of rows to delete (outlier removal) 

  numoutiter = 1 ;  

  if (numoutliter>=1) 
  {
    numoutiter = numoutliter+1 ;
    ZALLOC(outinfo, nrows,  OUTLINFO *) ;  
    for (k=0; k<nrows; k++) 
    {  
      ZALLOC(outinfo[k], 1, OUTLINFO) ;
    }
    /* fprintf(outlfile, "##%18s %4s %6s %9s\n", "ID", "iter","eigvec", "score") ; */
  }

  for (outliter = 1; outliter <= numoutiter ; ++outliter)  {
    if (fstonly) { 
     setidmat(XTX, nrows) ;
     vclear(lambda, 1.0, nrows) ;
     break ;
    }
    if (outliter>1) {
     ncols = loadsnpx(xsnplist, snpmarkers, numsnps, indivmarkers) ;
    }
    vzero(XTX, nrows*nrows) ;
    vzero(tblock, nrows*blocksize) ;
    xblock = 0 ; 

    vzero(xmean, ncols) ;
    vclear(xfancy, 1.0, ncols) ;

    for (i=0; i<ncols; i++) 
    { 
      cupt = xsnplist[i] ;
      chrom = cupt -> chrom ;
      getcolxz(cc, cupt, xindex, nrows, i, xmean, xfancy, &n0, &n1) ;
      t = MIN(n0, n1) ; 

      if (t <= minallelecnt)  {  
       cupt -> ignore = YES ;
       vzero(cc, nrows) ; 
      }

      if (weightmode) 
      {
        vst(cc, cc, xsnplist[i] -> weight, nrows) ;
      }
      if (ldregress>0) 
      {  
        numclear = 0 ;
        for (k=1; k<= ldregress; ++k)  
        {  
          j = i-k ;  
          if (j<0) 
          { 
            numclear = ldregress-k+1 ; 
            break ;
          }
          cupt2 = xsnplist[j] ;  
          if (cupt2 -> chrom != chrom) gdis = ldlimit + 1.0 ; 
          else gdis = cupt -> genpos - cupt2 -> genpos ;
          if (gdis>=ldlimit) 
          {   
            numclear = ldregress-k+1 ; 
            break ;
          }
        }
        if (numclear>0) clearld(ldmat, ldvv, ldregress, nrows, numclear) ; 
        ldreg(ldmat, ldmat2, cc, vv2, ldvv, ldvv2, ldregress, nrows) ;
        copyarr(ldmat2, ldmat, ldregress*ldregress) ;
        copyarr(vv2, cc, nrows) ;
        copyarr(ldvv2, ldvv, ldregress*nrows) ;
      }
      copyarr(cc, tblock+xblock*nrows, nrows) ;
      ++xblock ; 

/** this is the key code to parallelize */
      if (xblock==blocksize) 
      {  
        domult(tvecs, tblock, xblock, nrows) ;
        vvp(XTX, XTX, tvecs, nrows*nrows) ;
        xblock = 0 ;
        vzero(tblock, nrows*blocksize) ;
      }
    }

    if (xblock>0) 
    { 
     domult(tvecs, tblock, xblock, nrows) ;
     vvp(XTX, XTX, tvecs, nrows*nrows) ;
    }
    symit(XTX, nrows) ;

    /**
    a = 0; b=0 ;
    printf("zz1 %12.6f ", XTX[a*nrows+b]) ;
    a = nrows-1; b=nrows-1 ;
    printf(" %12.6f %15.9g\n", XTX[a*nrows+b], asum(XTX, nrows*nrows)) ;
    */

    if (verbose) 
    {
      printdiag(XTX, nrows) ;
    }

    y = trace(XTX, nrows) / (double) (nrows-1) ;
    if (isnan(y)) fatalx("bad XTX matrix\n") ;
    /* printf("trace:  %9.3f\n", y) ; */
    if (y<=0.0) fatalx("XTX has zero trace (perhaps no data)\n") ;
    vst(XTX, XTX, 1.0/y, nrows * nrows) ;
/// mean eigenvalue is 1
    eigvecs(XTX, lambda, evecs, nrows) ;
// eigenvalues are in decreasing order 

    if (outliter > numoutliter) break ;  
    // last pass skips outliers 
    numoutleigs = MIN(numoutleigs, nrows-1) ;
    nbad = ridoutlier(evecs, nrows, numoutleigs, outlthresh, badlist, outinfo) ;
    if (nbad == 0) break ; 
    for (i=0; i<nbad; i++) 
    {  
      j = badlist[i] ;
      indx = xindlist[j] ;
      outpt = outinfo[j] ;
      fprintf(outlfile, "REMOVED outlier %s iter %d evec %d sigmage %.3f\n", indx -> ID, outliter, outpt -> vecno, outpt -> score) ;
      indx -> ignore = YES ;
    }
    nrows = loadindx(xindlist, xindex, indivmarkers, numindivs) ;
    printf("number of samples after outlier removal: %d\n", nrows) ;
  }

  if (outliername != NULL) fclose(outlfile) ;

  m = numgtz(lambda, nrows)  ;
  /* printf("matrix rank: %d\n", m) ; */
  if (m==0) fatalx("no data\n") ;

/** smartrel code */
  for (i=0; i<numeigs; i++) {  
   y = sqrt(lambda[i]) ;
   vst(ww, evecs+i*nrows, y, nrows) ;               
   subouter(XTX, ww, nrows) ;
  }
  free(tvecs) ; 

  n = 0 ;
  ZALLOC(vecind, nrows*nrows/2, int) ; 
  for (i=0; i<nrows; i++) { 
   for (j=i+1; j<nrows; j++) { 
    k = i*nrows + j ; 
    y1 = XTX[i*nrows+i] ;
    y2 = XTX[j*nrows+j] ;
    y = XTX[k]/sqrt(y1*y2) ;
    y += 1/(double)(nrows-1);
    if (y<relthresh) continue ;
    vecind[n] = k ; 
    evecs[n] = -y ;
    ++n ;
   }
  }
  free(XTX) ; 
  if (n==0) { 
   printf("## nothing above relthresh!\n") ;
   printf("##end of smartrel run\n") ;
   return 0 ;
  }
  ZALLOC(idperm, n, int) ; 
  sortit(evecs, idperm, n) ;
  for (i=0; i<n; i++) {  
   j = idperm[i] ;
   k = vecind[j] ;
   a = k/nrows ; 
   b = k%nrows ;
   printf("rel: %20s ",  xindlist[a] ->ID) ;
   printf("%20s ",  xindlist[b] ->ID) ;
   printf(" %9.3f", -evecs[i]) ;
   printnl() ;
  }
  
  printf("##end of smartrel run\n") ;
  return 0 ;
}
コード例 #22
0
ファイル: qpBound.c プロジェクト: b1234561/AdmixTools
void
dof3score(double *f3score, double *f3scoresig, SNP **xsnplist, int *xindex, int *xtypes, 
 int nrows, int ncols, int numeg, int nblocks) 
{

   int t1, t2 ;
   int a, b, c, d ;
   int c1[2], c2[2], *cc ;
   int *rawcol, *popall, *pop0, *pop1 ;
   int k, g, i, col, j ; 
   double ya, yb, y, jest, jsig, mean ;
   SNP *cupt ;
   double top, bot, *djack, *wjack, gtop, gbot, *wbot, *wtop ;
   double *btop, *bbot, wt ;
   double ytop, ybot ;
   double y1, y2, yscal ;
   double *w1, *w2, *ww, m1, m2 ;  
   int bnum, totnum  ;
   FILE *fff ; 
   double xn[3], xmean[3], xh[3] ;
   
   if (snpdetailsname != NULL) openit(snpdetailsname, &fff, "w") ;
   
   if (nrows==0) fatalx("badbug\n") ;

   ZALLOC(w1, nblocks, double) ;
   ZALLOC(w2, nblocks, double) ;
   ZALLOC(ww, nblocks, double) ;
   ZALLOC(wjack, nblocks, double) ;
   ZALLOC(djack, nblocks, double) ;
   ZALLOC(btop, nblocks, double) ;
   ZALLOC(bbot, nblocks, double) ;
   ZALLOC(wtop, nblocks, double) ;
   ZALLOC(wbot, nblocks, double) ;

   
   setjquart(pubjack, jackweight, jackquart) ;

   totnum = 0 ;
   for (col=0; col<ncols;  ++col)  {
    cupt = xsnplist[col] ;
    if (cupt -> ignore) continue ;

    bnum = cupt -> tagnumber ; 
    if (bnum<0) continue ;
    if (bnum>=nblocks) fatalx("logic bug\n") ;

      f3sc(&ytop,  &ybot, cupt, indivmarkers, xindex, xtypes, nrows, 2, 0, 1) ;
      if (isnan(ytop)) fatalx("zznan\n") ;
      if (ybot < -0.5) continue ;
      if ((dzeromode == NO) && (ybot<=0.001)) continue ;
      if (snpdetailsname != NULL)  {

       finfo(xn+0, xmean+0, xh+0, 0) ; 
       finfo(xn+1, xmean+1, xh+1, 1) ; 
       finfo(xn+2, xmean+2, xh+2, 2) ;  // Sardin Karit CEU

       fprintf(fff, "%20s ", cupt -> ID) ;
       for (a=0; a<=2; ++a) { 
        fprintf(fff, "  %6.0f", xn[a]) ;
        fprintf(fff, " %9.3f", xmean[a]) ;
        fprintf(fff, " %9.3f", xh[a]) ;
       }
       fprintf(fff, "  %9.3f ", ytop) ;         
  //   fprintf(fff, "%9.3f ", ybot/2.0) ;         
       fprintf(fff, " %c ", cupt -> alleles[0]) ;
       fprintf(fff, "%c", cupt -> alleles[1]) ;
       fprintf(fff, "\n") ;
       
        
      }
     
      btop[bnum] += ytop ;
      bbot[bnum] += ybot ;
      ++wjack[bnum] ;
      ++totnum  ;
      
   }

   if (totnum <= 1) fatalx("no data...\n") ;
/**
   printf("totnum: %d ", totnum) ;
   printmat(wjack, 1, 10) ;
*/



    gtop = asum(btop, nblocks) ;
    gbot = asum(bbot, nblocks) ;

    *f3score = mean = gtop/gbot ;

    for (k=0; k<nblocks; k++) {  
     top = btop[k] ; 
     bot = bbot[k] ;
     wtop[k] = gtop-top ; 
     wbot[k] = gbot-bot ;
     wbot[k] += 1.0e-10 ;
     djack[k] = wtop[k]/wbot[k] ;  // delete-block estimate
    }
      
    estjackq(&jest, &jsig, btop, bbot,  wjack, nblocks) ;
    *f3score = jest ;
    *f3scoresig = jsig ;

    free(w1) ; 
    free(w2) ; 
    free(ww) ; 

    free(wtop) ; 
    free(wbot) ; 
    free(djack) ;
    free(wjack) ;

    free(btop) ;
    free(bbot) ;
    if (snpdetailsname != NULL) fclose(fff) ;

}
コード例 #23
0
ファイル: smarteigenstrat.c プロジェクト: yiqinyang2/SOAPpop
int main(int argc, char **argv)
{
  double *V;
  double *xx;
  double *iscase;
  double *iscasecorr;
  int K;
  int k,m,n;
  int nignore;
  double rowsum, rowsum1;
  double chisq, Echisq, gamma, denom;

  readcommands(argc, argv) ;
  if (outputname != NULL) 
    openit(outputname, &fpout, "w") ;
  else 
    fpout = stdout;
  fprintf(fpout, "Chisq EIGENSTRAT\n");

  setinmode(&inmode, imode);
  packmode = YES;

  numsnps = 
    getsnps(snpname, &snpmarkers, 0.0,  NULL, &nignore, 1) ;

  NSAMPLES = getindivs(indivname, &indivmarkers) ;

  setstatus(indivmarkers, NSAMPLES, "Case") ;
  setgenotypename(&genotypename, indivname) ;
  if (genotypename != NULL)  {
   getgenos(genotypename, snpmarkers, indivmarkers, 
    numsnps, NSAMPLES, nignore) ;
  }

  /*******************************************************************/
  /*  Free memory:  Usually this is done in outfiles:                */
  /*                                                                 */
  /*  nind = rmindivs(&snpmarkers, numsnps, &indmarkers, NSAMPLES);  */
  /*                                                                 */
  /*  But where is the snpmarkers array released?                    */
  /*******************************************************************/

  L = numpc;
  readpcafile(&V, &outlier, &K, L, NSAMPLES);
  getphenos(NSAMPLES, &iscase, outlier, &iscasecorr, L, V);

  /* main eigenstrat loop here */

  if ((xx = (double *)malloc(NSAMPLES*sizeof(*xx))) == NULL)
  {  fprintf(stderr,"CM\n");  exit(1);  }

  for(m=0;m<numsnps;m++)  {

    SNP *cupt = snpmarkers[m];
    for(n=0; n<NSAMPLES; n++)
    {
      int j = getgtypes(cupt,n);

      if(j == 0)       { xx[n] = 0.0; }
      else if(j == 1)  { xx[n] = 0.5; }
      else if(j == 2 ) { xx[n] = 1.0; }
      else if(j == -1) { xx[n] = -100.0; }

      if(outlier[n] == 1) xx[n] = -100.0;

    }

    /* mean-adjust xx */
    rowsum = 0.0; rowsum1 = 0.0;
    for(n=0; n<NSAMPLES; n++)
    {
      if(qtmode == NO && ((outlier[n]) || (xx[n] < -99.0))) continue;
      if(qtmode == YES && ((outlier[n]) || (xx[n] == -100.0))) continue;
      rowsum += xx[n];
      rowsum1 += 1.0;
    }
    for(n=0; n<NSAMPLES; n++)
    {  
      if(outlier[n]) continue;
      if(qtmode == NO)  {
        if (xx[n] < -99.0) 
          xx[n] = -100.0; /* still keep track */
        else 
	  xx[n] -= rowsum/rowsum1;
      }
      else  {
        if (xx[n] == -100.0) 
          xx[n] = -100.0; /* still keep track */
        else 
	  xx[n] -= rowsum/rowsum1;
      }
    }

    /* Chisq */
    chisq = compute_chisq(xx,iscase);

    /* EIGENSTRAT */
    for(k=0; k<L; k++)
    {
      gamma = 0.0;
      denom = 0.0;
      for(n=0; n<NSAMPLES; n++) 
      {
        if(qtmode == NO && (outlier[n] || xx[n] < -99.0)) continue;
        if(qtmode == YES && (outlier[n] || xx[n] == -100.0)) continue;
        gamma += xx[n]*V[NSAMPLES*n+k];
        denom += V[NSAMPLES*n+k]*V[NSAMPLES*n+k];
      }
      gamma /= denom;
      for(n=0; n<NSAMPLES; n++) 
      {
        if(qtmode == NO && (outlier[n] || xx[n] < -99.0)) continue;
        if(qtmode == YES && (outlier[n] || xx[n] == -100.0)) continue;
        xx[n] -= gamma*V[NSAMPLES*n+k];
      }
    }
    Echisq = compute_chisqE(xx,iscasecorr);

    if(rowsum1 == 0.0)
    {
      chisq = -1.0; Echisq = -1.0;
    }

    if(chisq >= 0.0) fprintf(fpout,"%.04f",chisq);
    else fprintf(fpout,"NA");
    if(Echisq >= 0.0) fprintf(fpout," %.04f\n",Echisq);
    else fprintf(fpout," NA\n");

    if(NSAMPLES*m > MAXSIZE)
    {
      fprintf(stderr,"OOPS genotype file has > %d genotypes\n",MAXSIZE);
      fprintf(fpout,"OOPS genotype file has > %d genotypes\n",MAXSIZE);
      exit(1);
    }
  }
}
コード例 #24
0
ファイル: qpBound.c プロジェクト: b1234561/AdmixTools
int main(int argc, char **argv)
{

  char sss[MAXSTR] ;
  int **snppos ;
  int *snpindx ;
  char **snpnamelist, **indnamelist ;
  int  lsnplist, lindlist ;
  int i, j, k, k1, k2, k3, k4, kk ; 
  SNP *cupt, *cupt1, *cupt2, *cupt3 ;
  Indiv *indx ;
  double y1, y2, y, sig, tail, yy1, yy2 ;
  char ss[11] ;
  int *blstart, *blsize, nblocks ;
  int  xnblocks ; /* for xsnplist */
  int *bcols ;
  int **subsets ;
  double maxgendis ;
  char **eglist ;
  int numeg ;

  int ch1, ch2 ;
  int fmnum , lmnum ;
  int num, n1, n2 ;

  int nindiv = 0, e, f, lag=1  ;
  double xc[9], xd[4], xc2[9] ;
  int nignore, numrisks = 1 ;
  double  *xrow, *xpt ; 
  SNP **xsnplist  ;
  int *tagnums  ;
  Indiv **xindlist ;
  int *xindex, *xtypes ;
  int  nedge, m, nc ;
  double zn, zvar ;
  int weightmode = NO ;
  double chisq, ynrows ;
  int *numhits, t ;  
  double *xmean, *xfancy ;
  double *divans, *divsd ; 
  double *hettop, *hetbot ; 
  int chrom,  numclear ;
  double gdis ;
  int outliter, *badlist, nbad ;
  int ***counts ;

  char ***plists ; 
  int nplist, trun ;
  int nrows, ncols ;

  readcommands(argc, argv) ;
  printf("## qpBound version: %s\n", WVERSION) ;
  if (parname == NULL) return 0 ;
  if (xchrom == 23) noxdata = NO ;
  if (outpop == NULL) fatalx("no outpop\n") ;  
  setinbreed(inbreed) ;

  numsnps = 
    getsnps(snpname, &snpmarkers, 0.0, badsnpname, &nignore, numrisks) ;

  numindivs = getindivs(indivname, &indivmarkers) ;
  setindm(indivmarkers) ;
  k = getgenos(genotypename, snpmarkers, indivmarkers, 
    numsnps, numindivs, nignore) ;

  for (i=0; i<numsnps; i++)  
  {  
    cupt = snpmarkers[i] ; 
    chrom = cupt -> chrom ;
    if ((xchrom>0) && (chrom != xchrom)) cupt -> ignore = YES ;
    if ((noxdata) && (chrom == 23)) cupt-> ignore = YES ;
    if (chrom == 0) cupt -> ignore = YES ;
    if (chrom > 23) cupt -> ignore = YES ;
    if (chrom == zchrom) cupt -> ignore = YES ;
  }

  nplist = numlines(popfilename) ;
  ZALLOC(plists, nplist, char **) ;
  ZALLOC(lines, nplist, char *) ;
  num = readpopx(popfilename, plists, 3) ;
  nplist = num ;
  printf("nplist: %d\n", nplist) ;
  if (nplist == 0) return 0;


  ZALLOC(eglist, nplist*3, char *)  ;  
  numeg = 0 ;
  for (trun=0; trun<nplist; ++trun) {  
   for (k=0; k<3; ++k) { 
    t = indxindex(eglist,  numeg, plists[trun][k]) ;
    if (t<0) {  
     eglist[numeg] = strdup(plists[trun][k]) ;
     ++numeg ;
    }
   }
  }

  if (popsizelimit > 0) {  
   setplimit(indivmarkers, numindivs, eglist, numeg, popsizelimit) ; 
  }
  
  if (outputname != NULL) openit (outputname, &ofile, "w") ;
  outnum = 0 ;
  ZALLOC(xindex, numindivs, int) ;
  ZALLOC(xindlist, numindivs, Indiv *) ;
  nrows = loadindx(xindlist, xindex, indivmarkers, numindivs) ;
  ZALLOC(xtypes, nrows, int) ;
  for (i=0; i<nrows; i++) {
   indx = xindlist[i] ;
   k = indxindex(eglist, numeg, indx -> egroup) ;
   xtypes[i] = k+1 ; // dangerous bend
   t = strcmp(indx -> egroup, outpop) ;
   if (t==0) xtypes[i] = outnum ;
   else fatalx("outpop bug\n") ;
  }
  ZALLOC(xsnplist, numsnps, SNP *) ;
  ncols = loadsnpx(xsnplist, snpmarkers, numsnps, indivmarkers) ;



/**
  ZALLOC(counts, ncols, int **) ;
  for (k=0; k<ncols; ++k) {
   counts[k] = initarray_2Dint( numeg, 2, 0) ;
  }
  countpops(counts, xsnplist, xindex, xtypes, nrows, ncols) ;
*/

  for (trun=0; trun<nplist; ++trun) {  
   dopop3out(plists[trun], xsnplist, ncols, lines[trun], outpop) ;
  }

  if (outputname != NULL) fclose(ofile) ;

  printf("##end of qpBound\n") ;
  return 0 ;
  
}
コード例 #25
0
ファイル: qpDstat.c プロジェクト: b1234561/AdmixTools
int main(int argc, char **argv)
{

  char sss[MAXSTR] ;
  int **snppos ;
  int *snpindx ;
  char **snpnamelist, **indnamelist ;
  char **eglist ;
  int *nsamppops ;
  int *ztypes ;
  int  lsnplist, lindlist, numeg ;
  int i, j, k, k1, k2, k3, k4, kk; 
  SNP *cupt, *cupt1, *cupt2, *cupt3 ;
  Indiv *indx ;
  double y1, y2, y, sig, tail, yy1, yy2 ;
  char ss[11] ;
  int *blstart, *blsize, nblocks ;
  int  xnblocks ; /* for xsnplist */
  int *bcols ;
  double maxgendis ;
  int xind[4] ;

  int ch1, ch2 ;
  int fmnum , lmnum ;
  int num, n1, n2 ;

  int nindiv = 0, e, f, lag=1  ;
  double xc[9], xd[4], xc2[9] ;
  int nignore, numrisks = 1 ;
  double  *xrow, *xpt ; 
  SNP **xsnplist  ;
  int *tagnums  ;
  Indiv **xindlist ;
  int *xindex, *xtypes ;
  int nrows, ncols, m, nc ;
  double zn, zvar ;
  int weightmode = NO ;
  double chisq, ynrows ;
  int *numhits, t ;  
  double *xmean, *xfancy ;
  double *divans, *divsd ; 
  double *hettop, *hetbot ; 
  int chrom,  numclear ;
  double gdis ;
  int outliter, *badlist, nbad ;
  double **zdata, *z1, *z2 ;
  int maxtag = -1 ;
  double **zz ; 
  double *pmean, *pnum, rscore[3], dstat[3], hscore[3], rrr[3], ww[3], serr[3] ;
  int ssize[3][3], *sz ;
  int tpat[3][4] , rpat[3][4], *rrtmp, *rp ;
  int  *rawcol ; ;
  int a, b, c, d, col  ;
  int aa, bb, cc, dd  ;
  double *qpscores ;
  double *hest, *hsig ;
  double mingenpos, maxgenpos ;
  int *qhit  ;  /* number of times pair is clade in quartet */
  int *qmiss ;  /* number of times pair migration event implied */
  int **qplist, numqp = 0, maxqp=10000 ;
  double *qpscore ;
  char ***qlist, *sx ;
  int nqlist = 0  ;
  int bbest[3] ;
  double absscore[3] ; 
  double ascore[4], astat[4] ;


  double **dsctop, **dscbot ;
  double **abx, **bax, **f2 ;
  int popx[4] ;
  double tn[4*5], td[4*4] ;
  double zzsig[5], zzest[5], zsc[5] ;
  double ymin ;

  double *f3, *f4, *f3sig, *f4sig ;
  int t1, t2, tt ;
  int ***counts, **ccc ; 

  double tlenz[5], tlen[5] ;
  int lenz[5] ;  


  readcommands(argc, argv) ;
  printf("## qpDstat version: %s\n", WVERSION) ;
  if (parname == NULL) return 0 ;
  if ((poplistname == NULL) && (popfilename == NULL)) fatalx("poplistname, popfilename both null\n") ;

  if (!bankermode) forceclade = NO ;
//if (fancynorm) printf("fancynorm used\n") ;
//else printf("no fancynorm used\n") ;
  setjquart(NO, jackweight, jackquart) ;

  nostatslim = MAX(nostatslim, 3) ;

   setinbreed(inbreed) ;

  if (outputname != NULL)  openit(outputname, &ofile, "w") ;

  numsnps = 
    getsnps(snpname, &snpmarkers, 0.0, badsnpname, &nignore, numrisks) ;

  numindivs = getindivs(indivname, &indivmarkers) ;
  if (id2pops != NULL) { 
   setid2pops(id2pops, indivmarkers, numindivs) ;
  }
  setindm(indivmarkers) ;

  k = getgenos(genotypename, snpmarkers, indivmarkers, 
    numsnps, numindivs, nignore) ;

  for (i=0; i<numsnps; i++)  {  
	  cupt = snpmarkers[i] ;
	  if (cupt -> chrom >= 23) cupt -> ignore = YES ;
	  if (cupt -> chrom == zchrom) cupt -> ignore = YES ;
  }

   ZALLOC(eglist, numindivs, char *) ; 
   ZALLOC(ztypes, numindivs, int) ;
   if (popfilename == NULL) {
   if (bankermode == NO)
     numeg = loadlist(eglist, poplistname) ;
   else { 
     numeg = loadlist_type(eglist, poplistname, ztypes, 0) ;
     numbanker = 0 ;
     for (k=0; k<numeg; ++k) { 
      if (ztypes[k] == 2) ++numbanker ;
     }
     printf("bankermode: ") ; 
     printimat(ztypes, 1, numeg) ;
   }
   }
   if (popfilename != NULL) { 
    bbestmode = NO ;
    nqlist = numlines(popfilename) ;
    ZALLOC(qlist, 4, char **) ;
    for (k=0; k<4; ++k) {  
     ZALLOC(qlist[k], nqlist, char *) ;
    }
    nqlist = getnamesstripcolon(&qlist, nqlist, 4, popfilename, locount, hicount) ;
    numeg = 0 ;
    printf("number of quadruples %d\n", nqlist) ;
    fflush(stdout) ;
    for (k=0; k<4; ++k) { 
     for (j=0; j<nqlist; ++j) { 
      sx = qlist[k][j] ;
      t1 = indxstring(eglist, numeg, sx) ;
      if (t1 >=0) continue ;
      eglist[numeg] = strdup(sx) ;
      ++numeg ;
      setstatus(indivmarkers, numindivs, sx) ;
     }
    }
   }