Esempio n. 1
0
Word QepcadCls::ACCCVBCR(Word k, Word c, Word B1, Word b, Word* B1h)
{
  Word d, nnf, dV, IV, cp, i, I_i, d_i, c_i, L, Q, Qb, Qbs, F, Fp, a;

Step1: /* Initialization **********************************************/
  a = NIL; /* this is the pseudo-sample point we're building up *******/
  F = NIL; /* Useless now, could be usefull later. ********************/
  d = 0;   /* dimension of cell c_i. **********************************/
  nnf = 0; /* number of variables not fixed. **************************/
  dV = CINV(RED(PDEGV(k+1,B1))); /* vector of degrees of first k ******
				    variables of B1. ******************/
  IV = LELTI(c,INDX);            /* vector of indices of cell c. ******/


Step2: /* Loop over each level from 1 to k ****************************/
  c_i = GVPC;
  for(i = 1; i <= k; i++) {
    I_i = LELTI(IV,i);
    d_i = LELTI(dV,i);
    c_i = LELTI(LELTI(c_i,CHILD),I_i);
    
Step3: /* c_i is a section over a 0-dimensional cell ******************/
    if ((I_i % 2 == 0) && d == 0) {
      a = SUFFIX(a,LELTI(b,i));
      continue; }
    
Step4: /* c_i is a section over a cell of dimension greater than zero */
    if ((I_i % 2 == 0) && d > 0) {
      for(L=SECTIONPOLS(i,c_i,GVPF),Qbs=1,Fp=NIL; L != NIL; L=RED(L)) {
	Q = RPFIP(i,LELTI(FIRST(L),PO_POLY));
	Qb = SPECIALSUBSR(i,a,Q); /* Qb can't be zero, by definition of 
				     SECTIONPOLS */
	Qbs = RPEMV(nnf + 1,Qb,LELTI(b,i));
	if (Qbs == 0) {
	  a = SUFFIX(a,LELTI(b,i));
	  break; }
	else
	  Fp = COMP(Qb,Fp); }
      if (L == NIL) {
	F = CCONC(F,Fp);
	nnf++;
	a = SUFFIX(a,NIL);
      } }
    
Step5: /* c_i is a sector *********************************************/
    if (I_i % 2 == 1) {
      d++;
      nnf++;
      a = SUFFIX(a,NIL); }
  }

/*Step6: a is the psuedo-sample point, check that B1 is univariate at a. */
  bool uniq = true;
  Word B1b = SPECIALSUBSR(k+1,a,RPFIP(k+1,B1));
  for(Word B1s = B1b; uniq && B1s != 0; B1s = PRED(B1s))
    uniq = IPCONST(nnf,PLDCF(B1s));
  if (B1h != 0) *B1h = B1b;

  return uniq ? TRUE : UNDET;
}
Esempio n. 2
0
/* Initialize all the necessary variables, start the event loop,
   register readline, and stdin, start the loop. */
void
cli_command_loop (void *data /* unused */)
{
  int length;
  char *a_prompt;
  char *gdb_prompt = get_prompt ();

  /* If we are using readline, set things up and display the first
     prompt, otherwise just print the prompt. */
  if (async_command_editing_p)
    {
      /* Tell readline what the prompt to display is and what function it
         will need to call after a whole line is read. This also displays
         the first prompt. */
      length = strlen (PREFIX (0)) + strlen (gdb_prompt) + strlen (SUFFIX (0)) + 1;
      a_prompt = (char *) xmalloc (length);
      strcpy (a_prompt, PREFIX (0));
      strcat (a_prompt, gdb_prompt);
      strcat (a_prompt, SUFFIX (0));
      rl_callback_handler_install (a_prompt, input_handler);
    }
  else
    display_gdb_prompt (0);

  /* Now it's time to start the event loop. */
  start_event_loop ();
}
/*
* Read the genotype for all the individuals in iidList at the SNP specified by iSNP
*   and store the results in pvOut
*/
void SUFFIX(CBedFile)::ReadGenotypes(size_t iSnp, bool count_A1, const vector< size_t >& idxIndividualList, REAL* pvOut, uint64_t_ startpos, uint64_t_  outputNumSNPs)
{
	//fprintf(stdout,"reading iSnp=%d w/ cIndividuals=%d and startpos=%d\n",iSnp,cIndividuals,startpos);
	ReadLine( &rgBytes[0], iSnp );
	// 'decompress' the genotype information
	size_t iIndividual = 0;
	for ( size_t ib = 0; ib < cbStride; ++ib )
	{
		BYTE genotypeByte = rgBytes[ ib ];

		// manually unrolled loop to decompress this byte
		if ( iIndividual < cIndividuals ) rgBedGenotypes[ iIndividual++ ] = (BedGenotype)( genotypeByte       & 0x03);
		if ( iIndividual < cIndividuals ) rgBedGenotypes[ iIndividual++ ] = (BedGenotype)((genotypeByte >> 2) & 0x03);
		if ( iIndividual < cIndividuals ) rgBedGenotypes[ iIndividual++ ] = (BedGenotype)((genotypeByte >> 4) & 0x03);
		if ( iIndividual < cIndividuals ) rgBedGenotypes[ iIndividual++ ] = (BedGenotype)((genotypeByte >> 6) & 0x03);
	}
	for ( size_t i=0; i<idxIndividualList.size(); ++i )
	{
		size_t idx = idxIndividualList[ i ];
		//fprintf(stdout,"iSnp=%d, iIID=%d\n",iSnp,idx);
#ifdef ORDERF
		uint64_t_ out_idx = startpos + i;
#else
		uint64_t_ out_idx = startpos + i * outputNumSNPs;
#endif
		if (count_A1)
		{
			pvOut[out_idx] = SUFFIX(mapBedGenotypeToRealAlleleCountA1)[rgBedGenotypes[idx]];
		}
		else {
			pvOut[out_idx] = SUFFIX(mapBedGenotypeToRealAlleleNoCountA1)[rgBedGenotypes[idx]];
		}

	}
}
Esempio n. 4
0
/**
 * go_accumulator_addl: (skip)
 **/
void
SUFFIX(go_accumulator_add) (ACC *acc, DOUBLE x)
{
	unsigned ui = 0, uj;

	g_return_if_fail (acc != NULL);

	for (uj = 0; uj < acc->partials->len; uj++) {
		DOUBLE y = g_array_index (acc->partials, DOUBLE, uj);
		DOUBLE hi, lo;
		if (SUFFIX(fabs)(x) < SUFFIX(fabs)(y)) {
			DOUBLE t = x;
			x = y;
			y = t;
		}
		hi = x + y;
		lo = y - (hi - x);
		if (lo != 0) {
			g_array_index (acc->partials, DOUBLE, ui) = lo;
			ui++;
		}
		x = hi;
	}
	g_array_set_size (acc->partials, ui + 1);
	g_array_index (acc->partials, DOUBLE, ui) = x;
}
Esempio n. 5
0
// Beta and LogBeta
/// <summary>Computes the log beta function</summary>
double SUFFIX(LogBeta)(REAL x, REAL y)
{
	if (x <= 0.0 || y <= 0.0){
		printf("LogBeta args must be > 0.");
		throw(1);
	}
	return SUFFIX(logGamma)(x) + SUFFIX(logGamma)(y) - SUFFIX(logGamma)(x + y);
}
Esempio n. 6
0
grub_err_t
SUFFIX (grub_macho_readfile) (grub_macho_t macho, void *dest)
{
  grub_ssize_t read;
  if (! SUFFIX (grub_macho_contains_macho) (macho))
    return grub_error (GRUB_ERR_BAD_OS,
		       "couldn't read architecture-specific part");

  if (grub_file_seek (macho->file, macho->offsetXX) == (grub_off_t) -1)
    {
      grub_error_push ();
      return grub_error (GRUB_ERR_BAD_OS,
			 "invalid offset in program header");
    }

  read = grub_file_read (macho->file, dest,
			 macho->endXX - macho->offsetXX);
  if (read != (grub_ssize_t) (macho->endXX - macho->offsetXX))
    {
      grub_error_push ();
      return grub_error (GRUB_ERR_BAD_OS,
			 "couldn't read architecture-specific part");
    }
  return GRUB_ERR_NONE;
}
Esempio n. 7
0
void Rsuave(int *pndim, int *pncomp,
	     void ** integrand, void *env,
  real *lower, real *upper, real *prdbounds,
  double *pepsrel, double *pepsabs,
   int *pmersenneseed, int *pflags, int *pmineval, int *pmaxeval,
  int *pnnew, double *pflatness, 
  int *pnregions, int *pneval, int *pfail,
  double *integral, double *erreur, double *prob)
{
  /* store the R function and its environment  dans un global*/
  rho= (SEXP)(env);
  globf= (SEXP)(integrand);
  lower_ = lower;
  upper_ = upper;
  prdbounds_ = *prdbounds;

   if (NA_INTEGER != *pmersenneseed) 
     SUFFIX(mersenneseed)= *pmersenneseed;

 /* call suave */
  suave((ccount *)pndim, (ccount *)pncomp,
	(Integrand)RIntegrand,
  (ctreal *)pepsrel, (ctreal *)pepsabs,
	(cint *)pflags, (cnumber *)pmineval, (cnumber *)pmaxeval,
  (cnumber *)pnnew, (ctreal *)pflatness, 
	(count *) pnregions,
	(number *)pneval, (int *)pfail,
	(real *)integral, (real *)erreur, (real *)prob);

} // End Rsuave
Esempio n. 8
0
grub_size_t
SUFFIX (grub_macho_filesize) (grub_macho_t macho)
{
  if (SUFFIX (grub_macho_contains_macho) (macho))
    return macho->endXX - macho->offsetXX;
  return 0;
}
Esempio n. 9
0
/* ___mkd_emblock()
 */
void
___mkd_emblock(MMIOT *f)
{
    int i;
    block *p;

    for (i=0; i < S(f->Q); i++) {
	p = &T(f->Q)[i];
	
	if ( p->b_type != bTEXT ) emmatch(f, i);

	if ( S(p->b_post) ) { SUFFIX(f->out, T(p->b_post), S(p->b_post));
			      DELETE(p->b_post); }
	if ( S(p->b_text) ) { SUFFIX(f->out, T(p->b_text), S(p->b_text));
			      DELETE(p->b_text); }
    }
    S(f->Q) = 0;
}
// wrapper to be used from cython
void SUFFIX(readPlinkBedFile)(std::string bed_fn, int inputNumIndividuals, int inputNumSNPs, bool count_A1, std::vector<size_t> individuals_idx, std::vector<int> snpIdxList, REAL* out)
{
	uint64_t_ N = inputNumIndividuals;
	uint64_t_ outputNumSNPs = snpIdxList.size();

	SUFFIX(CBedFile) bedFile = SUFFIX(CBedFile)();
	bedFile.Open(bed_fn, inputNumIndividuals, inputNumSNPs);

	for (size_t i = 0; i != snpIdxList.size(); i++){
		int idx = snpIdxList[i];

#ifdef ORDERF
		uint64_t_ startpos = ((uint64_t_)i) * individuals_idx.size();
#else
		uint64_t_ startpos = ((uint64_t_)i);
#endif
		bedFile.ReadGenotypes(idx, count_A1, individuals_idx, out, startpos, outputNumSNPs);
	}
}
Esempio n. 11
0
/* reparse() into a cstring
 */
void
Csreparse(Cstring *iot, char *buf, int size, int flags)
{
    MMIOT f;
    ___mkd_initmmiot(&f, 0);
    ___mkd_reparse(buf, size, 0, &f, 0);
    ___mkd_emblock(&f);
    SUFFIX(*iot, T(f.out), S(f.out));
    ___mkd_freemmiot(&f, 0);
}
Esempio n. 12
0
/* ___mkd_emblock() -- emblock a string of blocks, then concatenate the
 *                     resulting text onto f->out.
 */
void
___mkd_emblock(MMIOT *f)
{
    int i;
    block *p;

    emblock(f, 0, S(f->Q)-1);
    
    for (i=0; i < S(f->Q); i++) {
	p = &T(f->Q)[i];
	emfill(p);
	
	if ( S(p->b_post) ) { SUFFIX(f->out, T(p->b_post), S(p->b_post));
			      DELETE(p->b_post); }
	if ( S(p->b_text) ) { SUFFIX(f->out, T(p->b_text), S(p->b_text));
			      DELETE(p->b_text); }
    }
    
    S(f->Q) = 0;
} /* ___mkd_emblock */
Esempio n. 13
0
/// <summary>Probability distribution function</summary>
/// <param name="x">Value at which to compute the pdf</param>
/// <param name="a">Shape parameter (alpha)</param>
/// <param name="b">Shape parameter (beta)</param>
REAL SUFFIX(BetaPdf)(REAL x, REAL a, REAL b){
   if (a <= 0 || b <= 0){
      printf("Beta.Pdf parameters, a and b, must be > 0");
      throw(1);
   }

   if (x > 1) return 0;
   if (x < 0) return 0;

   REAL lnb = SUFFIX(LogBeta)(a, b);
   return exp((a - 1) * log(x) + (b - 1) * log(1 - x) - lnb);
}
Esempio n. 14
0
/* Used when the user requests a different annotation level, with
   'set annotate'. It pushes a new prompt (with prefix and suffix) on top
   of the prompt stack, if the annotation level desired is 2, otherwise
   it pops the top of the prompt stack when we want the annotation level
   to be the normal ones (1 or 0). */
static void
change_annotation_level (void)
{
  char *prefix, *suffix;

  if (!PREFIX (0) || !PROMPT (0) || !SUFFIX (0))
    {
      /* The prompt stack has not been initialized to "", we are
         using gdb w/o the --async switch */
      warning (_("Command has same effect as set annotate"));
      return;
    }

  if (annotation_level > 1)
    {
      if (!strcmp (PREFIX (0), "") && !strcmp (SUFFIX (0), ""))
	{
	  /* Push a new prompt if the previous annotation_level was not >1. */
	  prefix = (char *) alloca (strlen (async_annotation_suffix) + 10);
	  strcpy (prefix, "\n\032\032pre-");
	  strcat (prefix, async_annotation_suffix);
	  strcat (prefix, "\n");

	  suffix = (char *) alloca (strlen (async_annotation_suffix) + 6);
	  strcpy (suffix, "\n\032\032");
	  strcat (suffix, async_annotation_suffix);
	  strcat (suffix, "\n");

	  push_prompt (prefix, (char *) 0, suffix);
	}
    }
  else
    {
      if (strcmp (PREFIX (0), "") && strcmp (SUFFIX (0), ""))
	{
	  /* Pop the top of the stack, we are going back to annotation < 1. */
	  pop_prompt ();
	}
    }
}
Esempio n. 15
0
// Use GalenA's implementation of LogGamma - it's faster!
/// <summary>Returns the log of the gamma function</summary>
/// <param name="x">Argument of function</param>
/// <returns>Log Gamma(x)</returns>
/// <remarks>Accurate to eight digits for all x.</remarks>
REAL SUFFIX(logGamma)(REAL x)
{
	if (x <= (REAL)0.0){
		printf("LogGamma arg=%f must be > 0.",x);
		throw(1);
	}

	REAL res = (REAL)0.0;
	if (x < (REAL)6.0)
	{
		int toAdd = (int)floor(7 - x);
		REAL v2 = (REAL)1.0;
		for (int i = 0; i < toAdd; i++)
		{
			v2 *= (x + i);
		}
		res = -log(v2);
		x += toAdd;
	}
	x -= (REAL)1.0;

	res += SUFFIX(_halflog2pi) + (x + (REAL)0.5) * log(x) - x;

	// correction terms
	REAL xSquared = x * x;
	REAL pow = x;
	for (int i=0; i<5; ++i)   //the length of the coefficient array is 5.
	{
		REAL newRes = res + (REAL)1.0 / (SUFFIX(coeffsForLogGamma)[i] * pow);
		if (newRes == res)
		{
			return res;
		}
		res = newRes;
		pow *= xSquared;
	}

	return res;
}
Esempio n. 16
0
static void
splitline(Line *t, int cutpoint)
{
    if ( t && (cutpoint < S(t->text)) ) {
	Line *tmp = calloc(1, sizeof *tmp);

	tmp->next = t->next;
	t->next = tmp;

	tmp->dle = t->dle;
	SUFFIX(tmp->text, T(t->text)+cutpoint, S(t->text)-cutpoint);
	S(t->text) = cutpoint;
    }
}
Esempio n. 17
0
/* APPLE LOCAL begin Inform user about debugging optimized code  */
void
adjust_prompts_for_optimized_code (void)
{

  /* Case 1:  gdb_prompt_is_optimized == false.  */
  if (!gdb_prompt_is_optimized)
    {
      /* If we're inside optimized code AND the user wants to be told
	 about it, append '[opt> ' to the prompt.  Actually, create
         a second duplicate prompt, and append to that.  This allows
         for easy removal later.  */
      if (dwarf2_inform_debugging_optimized_code
	  && currently_inside_optimized_code)
	{
	  char *old_prompt = get_prompt ();
	  char *new_prompt;
	  if (strstr (old_prompt, "[opt> ") == 0)
	    {
	      new_prompt = (char *) xmalloc (strlen (old_prompt) + 7);
	      sprintf (new_prompt, "%s[opt> ", old_prompt);
	      push_prompt ("", new_prompt, "");
	      xfree (new_prompt);
	    }
	  gdb_prompt_is_optimized = 1;
	}
    }

  /* Case 2:  gdb_prompt_is_optimized == true.  */

  else if (gdb_prompt_is_optimized)
    {
      /* If we're not inside optimized code, or the user does not
	 want to be told about it, pop the '[opt> ' version of the
         prompt from the prompt stack.  */
      if (!dwarf2_inform_debugging_optimized_code
	  || !currently_inside_optimized_code)
	{
	  if (the_prompts.top > 0
	      && strstr (PROMPT (0), "[opt> ") != 0)
	    {
	      xfree (PREFIX (0));
	      xfree (PROMPT (0));
	      xfree (SUFFIX (0));
	      the_prompts.top--;
	    }
	  gdb_prompt_is_optimized = 0;
	}
    }
}
Esempio n. 18
0
Word PCADCINDEX(Word c)
{
      Word I,Ip,p,i;

Step1: /* Get index of parent cell, and append index of c. */
      i = LELTI(c,SC_INX);
      p = LELTI(c,SC_PAR);
      if (p == NIL)
	I = NIL;
      else {
      Ip = PCADCINDEX(p);
      I = SUFFIX(Ip,i); }

Return: /* Prepare to return. */
      return (I);
}
Esempio n. 19
0
/* Pushes a new prompt on the prompt stack. Each prompt has three
   parts: prefix, prompt, suffix. Usually prefix and suffix are empty
   strings, except when the annotation level is 2. Memory is allocated
   within savestring for the new prompt. */
void
push_prompt (char *prefix, char *prompt, char *suffix)
{
  the_prompts.top++;
  PREFIX (0) = savestring (prefix, strlen (prefix));

  /* Note that this function is used by the set annotate 2
     command. This is why we take care of saving the old prompt
     in case a new one is not specified. */
  if (prompt)
    PROMPT (0) = savestring (prompt, strlen (prompt));
  else
    PROMPT (0) = savestring (PROMPT (-1), strlen (PROMPT (-1)));

  SUFFIX (0) = savestring (suffix, strlen (suffix));
}
Esempio n. 20
0
/* emmatch() -- match emphasis for a single emphasis token.
 */
static void
emmatch(MMIOT *f, int first, int last)
{
    block *start = &T(f->Q)[first];
    int e, e2, match;

    switch (start->b_count) {
    case 2: if ( e = empair(f,first,last,match=2) )
		break;
    case 1: e = empair(f,first,last,match=1);
	    break;
    case 0: return;
    default:
	    e = empair(f,first,last,1);
	    e2= empair(f,first,last,2);

	    if ( e2 >= e ) {
		e = e2;
		match = 2;
	    } 
	    else
		match = 1;
	    break;
    }

    if ( e ) {
	/* if we found emphasis to match, match it, recursively call
	 * emblock to match emphasis inside the new html block, add
	 * the emphasis markers for the block, then (tail) recursively
	 * call ourself to match any remaining emphasis on this token.
	 */
	block *end = &T(f->Q)[e];

	end->b_count -= match;
	start->b_count -= match;

	emblock(f, first, e);

	PREFIX(start->b_text, emtags[match-1].open, emtags[match-1].size-1);
	SUFFIX(end->b_post, emtags[match-1].close, emtags[match-1].size);

	emmatch(f, first, last);
    }
} /* emmatch */
Esempio n. 21
0
static inline grub_err_t
read_headers (grub_file_t file, Elf_Ehdr *e, char **shdr)
{
 if (grub_file_seek (file, 0) == (grub_off_t) -1)
    return grub_errno;

  if (grub_file_read (file, (char *) e, sizeof (*e)) != sizeof (*e))
    {
      if (grub_errno)
	return grub_errno;
      else
	return grub_error (GRUB_ERR_BAD_OS, "file is too short");
    }

  if (e->e_ident[EI_MAG0] != ELFMAG0
      || e->e_ident[EI_MAG1] != ELFMAG1
      || e->e_ident[EI_MAG2] != ELFMAG2
      || e->e_ident[EI_MAG3] != ELFMAG3
      || e->e_ident[EI_VERSION] != EV_CURRENT
      || e->e_version != EV_CURRENT)
    return grub_error (GRUB_ERR_BAD_OS, "invalid arch independent ELF magic");

  if (e->e_ident[EI_CLASS] != SUFFIX (ELFCLASS))
    return grub_error (GRUB_ERR_BAD_OS, "invalid arch dependent ELF magic");

  *shdr = grub_malloc (e->e_shnum * e->e_shentsize);
  if (! *shdr)
    return grub_errno;

  if (grub_file_seek (file, e->e_shoff) == (grub_off_t) -1)
    return grub_errno;

  if (grub_file_read (file, *shdr, e->e_shnum * e->e_shentsize)
      != e->e_shnum * e->e_shentsize)
    {
      if (grub_errno)
	return grub_errno;
      else
	return grub_error (GRUB_ERR_BAD_OS, "file is truncated");
    }

  return GRUB_ERR_NONE;
}
Esempio n. 22
0
/* Pops the top of the prompt stack, and frees the memory allocated for it. */
void
pop_prompt (void)
{
  /* If we are not during a 'synchronous' execution command, in which
     case, the top prompt would be empty. */
  if (strcmp (PROMPT (0), ""))
    /* This is for the case in which the prompt is set while the
       annotation level is 2. The top prompt will be changed, but when
       we return to annotation level < 2, we want that new prompt to be
       in effect, until the user does another 'set prompt'. */
    if (strcmp (PROMPT (0), PROMPT (-1)))
      {
	xfree (PROMPT (-1));
	PROMPT (-1) = savestring (PROMPT (0), strlen (PROMPT (0)));
      }

  xfree (PREFIX (0));
  xfree (PROMPT (0));
  xfree (SUFFIX (0));
  the_prompts.top--;
}
#define HEAD_CRC	0x02
#define EXTRA_FIELD	0x04
#define ORIG_NAME	0x08
#define COMMENT		0x10

#define OS_CODE		3	/* Unix */

typedef struct {
    const char	*zipped;
    int		ziplen;
    const char	*normal;	/* for unzip - must not be longer than zipped */
} suffixes_t;
static suffixes_t suffixes[] = {
#define	SUFFIX(Z, N) {Z, sizeof Z - 1, N}
	SUFFIX(GZ_SUFFIX,	""),	/* Overwritten by -S .xxx */
#ifndef SMALL
	SUFFIX(GZ_SUFFIX,	""),
	SUFFIX(".z",		""),
	SUFFIX("-gz",		""),
	SUFFIX("-z",		""),
	SUFFIX("_z",		""),
	SUFFIX(".taz",		".tar"),
	SUFFIX(".tgz",		".tar"),
#ifndef NO_BZIP2_SUPPORT
	SUFFIX(BZ2_SUFFIX,	""),
#endif
#ifndef NO_COMPRESS_SUPPORT
	SUFFIX(Z_SUFFIX,	""),
#endif
#ifndef NO_XZ_SUPPORT
Esempio n. 24
0
* Include Files
*/
#include "CPlinkBedFileT.h"
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <stdlib.h>

// 0 and 2 are flipped (wrt C++ fastlmm) in order to agree to python code
REAL SUFFIX(unknownOrMissing) = std::numeric_limits<REAL>::quiet_NaN();  // now used by SnpInfo
REAL SUFFIX(homozygousPrimaryAllele) = 2;                // Major Allele
REAL SUFFIX(heterozygousAllele) = 1;                     
REAL SUFFIX(homozygousSecondaryAllele) = 0;              // Minor Allele ()

REAL SUFFIX(mapBedGenotypeToRealAllele)[4] = { 
	SUFFIX(homozygousSecondaryAllele),       // look-up 0
	SUFFIX(unknownOrMissing),                // look-up 1
	SUFFIX(heterozygousAllele),              // look-up 2
	SUFFIX(homozygousPrimaryAllele),         // look-up 3
};

SUFFIX(CBedFile)::SUFFIX(CBedFile)()
{
	layout = LayoutUnknown;    // layout describes the matrix layout on disk
	// 0=RowMajor(all snps per individual together);
	// 1=ColumnMajor(all individuals per SNP together in memory)
	cIndividuals = 0;
	cSnps        = 0;
	cbStride     = 0;

}
Esempio n. 25
0
static void
emopen(Cstring *s, int level)
{
    SUFFIX(*s, emtags[level-1].open, emtags[level-1].size-1);
}
Esempio n. 26
0
/**
 * go_accumulator_startl: (skip)
 **/
void *
SUFFIX(go_accumulator_start) (void)
{
	return SUFFIX(go_quad_start) ();
}
Esempio n. 27
0
grub_err_t
SUFFIX (grub_freebsd_load_elfmodule) (struct grub_relocator *relocator,
				      grub_file_t file, int argc, char *argv[],
				      grub_addr_t *kern_end)
{
  Elf_Ehdr e;
  Elf_Shdr *s;
  char *shdr = 0;
  grub_addr_t curload, module;
  grub_err_t err;
  grub_size_t chunk_size = 0;
  void *chunk_src;

  err = read_headers (file, &e, &shdr);
  if (err)
    return err;

  curload = module = ALIGN_PAGE (*kern_end);

  for (s = (Elf_Shdr *) shdr; s < (Elf_Shdr *) ((char *) shdr
						+ e.e_shnum * e.e_shentsize);
       s = (Elf_Shdr *) ((char *) s + e.e_shentsize))
    {
      if (s->sh_size == 0)
	continue;

      if (! (s->sh_flags & SHF_ALLOC))
	continue;
      if (chunk_size < s->sh_addr + s->sh_size)
	chunk_size = s->sh_addr + s->sh_size;
    }

  if (chunk_size < sizeof (e))
    chunk_size = sizeof (e);
  chunk_size += e.e_phnum * e.e_phentsize;
  chunk_size += e.e_shnum * e.e_shentsize;

  {
    grub_relocator_chunk_t ch;

    err = grub_relocator_alloc_chunk_addr (relocator, &ch,
					   module, chunk_size);
    if (err)
      return err;

    chunk_src = get_virtual_current_address (ch);
  }

  for (s = (Elf_Shdr *) shdr; s < (Elf_Shdr *) ((char *) shdr
						+ e.e_shnum * e.e_shentsize);
       s = (Elf_Shdr *) ((char *) s + e.e_shentsize))
    {
      if (s->sh_size == 0)
	continue;

      if (! (s->sh_flags & SHF_ALLOC))
	continue;

      grub_dprintf ("bsd", "loading section to %x, size %d, align %d\n",
		    (unsigned) curload, (int) s->sh_size,
		    (int) s->sh_addralign);

      switch (s->sh_type)
	{
	default:
	case SHT_PROGBITS:
	  err = load (file, (grub_uint8_t *) chunk_src + module
		      + s->sh_addr - *kern_end,
		      s->sh_offset, s->sh_size);
	  if (err)
	    return err;
	  break;
	case SHT_NOBITS:
	  grub_memset ((grub_uint8_t *) chunk_src + module
		      + s->sh_addr - *kern_end, 0, s->sh_size);
	  break;
	}
      if (curload < module + s->sh_addr + s->sh_size)
	curload = module + s->sh_addr + s->sh_size;
    }

  load (file, UINT_TO_PTR (module), 0, sizeof (e));
  if (curload < module + sizeof (e))
    curload = module + sizeof (e);

  load (file, UINT_TO_PTR (curload), e.e_shoff,
	e.e_shnum * e.e_shentsize);
  e.e_shoff = curload - module;
  curload +=  e.e_shnum * e.e_shentsize;

  load (file, UINT_TO_PTR (curload), e.e_phoff,
	e.e_phnum * e.e_phentsize);
  e.e_phoff = curload - module;
  curload +=  e.e_phnum * e.e_phentsize;

  *kern_end = curload;

  grub_freebsd_add_meta_module (argv[0], FREEBSD_MODTYPE_ELF_MODULE,
				argc - 1, argv + 1, module,
				curload - module);
  return SUFFIX (grub_freebsd_load_elf_meta) (relocator, file, kern_end);
}
Esempio n. 28
0
/*
* Parameters: 
* SNPs [nIndividuals by nSNPs]:
*                       Matrix stored in column-major order. 
*                       This will hold the result.
*                       NaNs will be set to 0.0 in the result.
*/
void SUFFIX(ImputeAndZeroMeanSNPs)( 
	REAL *SNPs, 
	const size_t nIndividuals, 
	const size_t nSNPs, 
	const bool betaNotUnitVariance,
	const REAL betaA,
	const REAL betaB
	)
{
	bool seenSNC = false; //Keep track of this so that only one warning message is reported
#ifdef ORDERF

	for ( size_t iSnp = 0; iSnp < nSNPs; ++iSnp )
	{

		REAL n_observed = 0.0;
		REAL sum_s  = 0.0;      //the sum of a SNP over all observed individuals
		REAL sum2_s = 0.0;      //the sum of the squares of the SNP over all observed individuals

		size_t end = nIndividuals;
		size_t delta = 1;
		for( size_t ind = 0; ind < end; ind+=delta )
		{
			if (SNPs[ind] == SNPs[ind])
			{
				//check for not NaN
				sum_s += SNPs[ ind ];
				sum2_s+= SNPs[ ind ] * SNPs[ ind ];
				++n_observed;
			}
		}

		if ( n_observed < 1.0 )
		{
			printf( "No individual observed for the SNP.\n");
		}

		REAL mean_s  = sum_s  / n_observed;    //compute the mean over observed individuals for the current SNP
		REAL mean2_s = sum2_s / n_observed;    //compute the mean of the squared SNP

		//When beta standardization is being done, check that data is 0,1,2
		if (betaNotUnitVariance && sum_s <= (REAL)0.0)
		{
			REAL freqT = sum_s/n_observed;
			fprintf(stderr, "Observed SNP freq is %.2f. for a SNPs[:][%i]\n", freqT, iSnp );
			exit(1);
		}


		//The SNP frequency
		REAL freq = (sum_s) / (n_observed * (REAL)2.0);   //compute snp-freq as in the Visscher Height paper (Nat Gen, Yang et al 2010).

		if ((freq != freq) || betaNotUnitVariance && ((freq >= (REAL)1.0) || (freq <= (REAL)0.0)))
		{
			if (!seenSNC)
			{
				seenSNC = true;
				fprintf(stderr, "Illegal SNP frequency: %.2f for SNPs[:][%i]\n", freq, iSnp);
			}
		}


		REAL variance = mean2_s-mean_s * mean_s;        //By the Cauchy Shwartz inequality this should always be positive
		REAL std = sqrt( variance );                    //The SNP frequency

		bool isSNC = false;
		if ( (std != std) || (std <= (REAL)0.0) )
		{
			// a std == 0.0 means all SNPs have the same value (no variation or Single Nucleotide Constant (SNC))
			//   however ALL SNCs should have been removed in previous filtering steps
			//   This test now prevents a divide by zero error below
			std = 1.0;
			isSNC = true;
			if (!seenSNC)
			{
				seenSNC = true;
				fprintf(stderr, "std=.%2f has illegal value for SNPs[:][%i]\n", std, iSnp );
			}

		}

		if (betaNotUnitVariance && freq > .5)
		{
			freq = 1.0 - freq;
		}

		for( size_t ind = 0; ind < end; ind+=delta )
		{
			//check for NaN
			if ( (SNPs[ ind ]!=SNPs[ ind ]) || isSNC)
			{
				SNPs[ ind ] = 0.0;
			}
			else
			{
				SNPs[ ind ] -= mean_s;     //subtract the mean from the data
				if (betaNotUnitVariance )
				{
					REAL rT = SUFFIX(BetaPdf)( freq, betaA, betaB );
					//fprintf(stderr, "BetaPdf(%f,%f,%f)=%f\n",  freq, betaA, betaB, rT);
					SNPs[ ind ] *= rT;
				}
				else
				{
					SNPs[ ind ] /= std;        //unit variance as well
				}

			}
		}

		SNPs += nIndividuals;
	}

#else //Order C


	// Make one pass through the data (by individual, because that is how it is laid out), collecting statistics
	std::vector<REAL> n_observed(nSNPs); //                                                C++ inits to 0's
	std::vector<REAL> sum_s(nSNPs);      //the sum of a SNP over all observed individuals. C++ inits to 0's
	std::vector<REAL> sum2_s(nSNPs);     //the sum of the squares of the SNP over all observed individuals.     C++ inits to 0's

	for( size_t ind = 0; ind < nIndividuals; ++ind)
	{
		size_t rowStart = ind * nSNPs;
		for ( size_t iSnp = 0; iSnp < nSNPs; ++iSnp )
		{
			REAL value = SNPs[rowStart+iSnp];
			if ( value == value )
			{
				sum_s[iSnp] += value;
				sum2_s[iSnp] += value * value;
				++n_observed[iSnp];
			}
		}
	}


	std::vector<REAL> mean_s(nSNPs);  //compute the mean over observed individuals for the current SNP
	std::vector<REAL> mean2_s(nSNPs); //compute the mean of the squared SNP
	std::vector<REAL> std(nSNPs); //the standard deviation
	std::vector<REAL> freq(nSNPs); //The SNP frequency
	std::vector<bool> isSNC(nSNPs); // Is this a SNC (C++ inits to false)

	for ( size_t iSnp = 0; iSnp < nSNPs; ++iSnp )
	{
		if ( n_observed[iSnp] < 1.0 )
		{
			printf( "No individual observed for the SNP.\n");
		}

		mean_s[iSnp]  = sum_s[iSnp]  / n_observed[iSnp];    //compute the mean over observed individuals for the current SNP
		mean2_s[iSnp] = sum2_s[iSnp] / n_observed[iSnp];    //compute the mean of the squared SNP

		//When beta standardization is being done, check that data is 0,1,2
		if (betaNotUnitVariance && sum_s[iSnp] <= (REAL)0.0)
		{
			REAL freqT = sum_s[iSnp]/n_observed[iSnp];
			fprintf(stderr, "Observed SNP freq is %.2f. for a SNPs[:][%i]\n", freqT, iSnp );
			exit(1);
		}

		freq[iSnp] = (sum_s[iSnp]) / (n_observed[iSnp] * (REAL)2.0);   //compute snp-freq[iSnp] as in the Visscher Height paper (Nat Gen, Yang et al 2010).

		if ((freq[iSnp] != freq[iSnp]) || betaNotUnitVariance && ((freq[iSnp] >= (REAL)1.0) || (freq[iSnp] <= (REAL)0.0)))
		{
			if (!seenSNC)
			{
				seenSNC = true;
				fprintf(stderr, "Illegal SNP frequency: %.2f for SNPs[:][%i]\n", freq[iSnp], iSnp);
			}
		}


		REAL variance = mean2_s[iSnp]-mean_s[iSnp] * mean_s[iSnp];        //By the Cauchy Shwartz inequality this should always be positive
		std[iSnp] = sqrt( variance );

		if ( (std[iSnp] != std[iSnp]) || (std[iSnp] <= (REAL)0.0) )
		{
			// a std == 0.0 means all SNPs have the same value (no variation or Single Nucleotide Constant (SNC))
			//   however ALL SNCs should have been removed in previous filtering steps
			//   This test now prevents a divide by zero error below
			std[iSnp] = 1.0;
			isSNC[iSnp] = true;
			if (!seenSNC)
			{
				seenSNC = true;
				fprintf(stderr, "std=.%2f has illegal value for SNPs[:][%i]\n", std[iSnp], iSnp );
			}
		}

		if (betaNotUnitVariance && freq[iSnp] > .5)
		{
			freq[iSnp] = 1.0 - freq[iSnp];
		}
	}

	for( size_t ind = 0; ind < nIndividuals; ++ind)
	{
		size_t rowStart = ind * nSNPs;
		for ( size_t iSnp = 0; iSnp < nSNPs; ++iSnp )
		{
			REAL value = SNPs[rowStart+iSnp];
			//check for NaN
			if ( (value != value) || isSNC[iSnp])
			{
				value = 0.0;
			}
			else
			{
				value -= mean_s[iSnp];     //subtract the mean from the data
				if (betaNotUnitVariance )
				{
					REAL rT = SUFFIX(BetaPdf)( freq[iSnp], betaA, betaB );
					//fprintf(stderr, "BetaPdf(%f,%f,%f)=%f\n",  freq, betaA, betaB, rT);
					value *= rT;
				}
				else
				{
					value /= std[iSnp];        //unit variance as well
				}
			}
			SNPs[rowStart+iSnp] = value;
		}
	}
#endif
}
Esempio n. 29
0
/* Displays the prompt. The prompt that is displayed is the current
   top of the prompt stack, if the argument NEW_PROMPT is
   0. Otherwise, it displays whatever NEW_PROMPT is. This is used
   after each gdb command has completed, and in the following cases:
   1. when the user enters a command line which is ended by '\'
   indicating that the command will continue on the next line.
   In that case the prompt that is displayed is the empty string.
   2. When the user is entering 'commands' for a breakpoint, or
   actions for a tracepoint. In this case the prompt will be '>'
   3. Other????
   FIXME: 2. & 3. not implemented yet for async. */
void
display_gdb_prompt (char *new_prompt)
{
  int prompt_length = 0;
  char *gdb_prompt = get_prompt ();
  static int stdin_handler_removed = 0;

  /* APPLE LOCAL begin Inform user about debugging optimized code  */
  if (strcmp (gdb_prompt, "") != 0)
    {
      adjust_prompts_for_optimized_code ();
      gdb_prompt = get_prompt ();
    }
  /* APPLE LOCAL end Inform user about debugging optimized code  */

  /* Each interpreter has its own rules on displaying the command
     prompt.  */
  if (!current_interp_display_prompt_p ())
    return;

  if (target_executing && sync_execution)
    {
      /* This is to trick readline into not trying to display the
         prompt.  Even though we display the prompt using this
         function, readline still tries to do its own display if we
         don't call rl_callback_handler_install and
         rl_callback_handler_remove (which readline detects because a
         global variable is not set). If readline did that, it could
         mess up gdb signal handlers for SIGINT.  Readline assumes
         that between calls to rl_set_signals and rl_clear_signals gdb
         doesn't do anything with the signal handlers. Well, that's
         not the case, because when the target executes we change the
         SIGINT signal handler. If we allowed readline to display the
         prompt, the signal handler change would happen exactly
         between the calls to the above two functions.
         Calling rl_callback_handler_remove(), does the job. */

      delete_file_handler (input_fd);
      stdin_handler_removed = 1;
      rl_callback_handler_remove ();
      return;
    }

  if (!new_prompt)
    {
      /* Just use the top of the prompt stack. */
      prompt_length = strlen (PREFIX (0)) +
	strlen (SUFFIX (0)) +
	strlen (gdb_prompt) + 1;

      new_prompt = (char *) alloca (prompt_length);

      /* Prefix needs to have new line at end. */
      strcpy (new_prompt, PREFIX (0));
      strcat (new_prompt, gdb_prompt);
      /* Suffix needs to have a new line at end and \032 \032 at
         beginning. */
      strcat (new_prompt, SUFFIX (0));
    }

  if (async_command_editing_p)
    {
      /* Claim the terminal before we reset it.  It is quick if the
	 terminal is already ours, and if not, we are going to lose
	 when we try to install the callback handler otherwise.  We
	 can get here with the terminal still belonging to the
	 inferior if it dies an unexpected death, and somebody forgets
	 to clean up properly.  Better safe than sorry... */

      target_terminal_ours ();
      if (stdin_handler_removed)
	{
	  add_file_handler (input_fd, stdin_event_handler, 0);
	  stdin_handler_removed = 0;
	}

      rl_callback_handler_remove ();
      rl_callback_handler_install (new_prompt, input_handler);
    }
  /* new_prompt at this point can be the top of the stack or the one passed in */
  else if (new_prompt)
    {
      /* Don't use a _filtered function here.  It causes the assumed
         character position to be off, since the newline we read from
         the user is not accounted for.  */
      fputs_unfiltered (new_prompt, gdb_stdout);
      gdb_flush (gdb_stdout);
    }
}
Esempio n. 30
0
void
SUFFIX(go_accumulator_end) (void *state)
{
	SUFFIX(go_quad_end) (state);
}