Exemple #1
0
bfun* complement (bfun* b_initial) {
  // does not free argument.  

  bfun* b = try_simplify(b_initial);
  if (b_initial != b) {
    return b;
  } else {
    int x = best_split(b);

    bfun* pc = pos_co(b,x);
    bfun* nc = neg_co(b,x);

    bfun* p = complement(pc);
    bfun* n = complement(nc);

    del_bfun(pc);
    del_bfun(nc);

    // and_var modifies the passed cube_list
    and_var(p, x);
    and_var(n, x * -1);

    // or allocates a new cube & copies the cubelists over
    bfun* result = or(p,n);
    del_bfun(p);
    del_bfun(n);
    
    return result;
  }
}
Exemple #2
0
SNPposition::SNPposition(int position, char* letters, const char* strand, const char* ref)
{
    position_=position;
    char* strs[4];
	unsigned strs_cnt = split(letters, '/', strs);
	bool reverse = strcmp(strand, "-") == 0;

	char c_ref;
    if (reverse) {
	  c_ref = complement(ref[0]);
    } else {
	  c_ref = ref[0];
	}
    if (strs[0][0]==c_ref) {
        nucleotide_ = strs[1][0];
    } else {
        nucleotide_=strs[0][0];
    }

    if (reverse) {
        nucleotide_ = complement(nucleotide_);
    }

	freq_ = 0; // EV: must be initialized
	status_ = 0; // EV: must be initialized
}
  BigInt BigInt::operator*(BigInt b) {
    if (*this == 0 || b == 0)
      return 0;

    BigInt a = *this;
    bool negative = 0 xor a.negative_ xor b.negative_;

    if (a.negative_) {
      complement(a.value_);
      a.negative_ = false;
    }
    if (b.negative_) {
      complement(b.value_);
      b.negative_ = false;
    }

    match_size_of_digits(a, b);

    a = karatsuba(a, b);
    a.negative_ = (a != 0) and negative ;

    if (a.negative_)
      complement(a.value_);

    return a;
  }
Exemple #4
0
bfun* and(bfun* b, bfun* g) {
  bfun* m_not = complement(b);
  bfun* n_not = complement(g);
  bfun* mn_or = or(m_not, n_not);
  bfun* to_return = complement(mn_or);
  del_bfun(m_not);
  del_bfun(n_not);
  del_bfun(mn_or);
  return to_return;
}
Exemple #5
0
void reverse_complement(char *p, size_t len)
{
	char *pp = p + len - 1;
	while (p <= pp) {
		char tmp = *p;
		*p = complement(*pp);
		*pp = complement(tmp);
		p++;
		pp--;
	}
}
Exemple #6
0
void reverse_complement(char *string, unsigned len)
{
     int i;
     for (i = 0, len = len -1; len > i; ++i, --len) {
          *(string+i) ^= *(string+len);
          *(string+len) ^= *(string+i);
          *(string+i) ^= *(string+len);
          *(string+i) = complement(*(string+i));
          *(string+len) = complement(*(string+len));
     }
}
Exemple #7
0
void reverseP(Args *args, Sequence *seq, FILE *snp) {
  int i, pos, optStart;
  char *snpId, *alt, *hsName, *chr, *primer;

  hsName = emalloc(256);
  chr = emalloc(256);
  snpId = emalloc(256);
  alt = emalloc(256);
  
  primer = emalloc(args->M + 1);
  /* get name of hotspot */
  strcpy(hsName, tabField(0));


  while(fscanf(snp,"%s %d %s %*s %s %*s %*s %*s",chr,&pos,snpId,alt) != EOF){
    /* zero-based counting within progr. */
    pos--;
    if (strchr(alt, ',')) 
      continue;
    for (i = 0; i < args->M; i++)
      primer[i] = seq->seq[pos + i];

    primer[args->M] = '\0';
    reverse(primer);
    complement(primer);

    /* print first primer */
    optStart = optimalStartPos(args, primer, args->M - args->m);
    printf("%s\t%s\t%s\t%d\t", hsName, snpId, chr, pos + 1);

    for (i = optStart; i < args->M; i++)
      printf("%c", primer[i]);

    printf("\t%.2f\t%.1f\t", gc(primer, optStart), tm(primer, optStart));
    complement(alt);
    primer[args->M - 1] = alt[0];
		
    /* print second primer */
    optStart = optimalStartPos(args, primer, args->M - args->m);

    for (i = optStart; i < args->M; i++)
      printf("%c", primer[i]);

    printf("\t%.2f\t%.1f\n", gc(primer, optStart), tm(primer, optStart));
  }
  free(chr);
  free(snpId);
  free(alt);
  free(hsName);
  free(primer);
}
Exemple #8
0
 RealType operator()(const RealType& df)
 {
    if(df <= tools::min_value<RealType>())
    { // 
       return 1;
    }
    students_t_distribution<RealType, Policy> t(df);
    RealType qa = quantile(complement(t, alpha));
    RealType qb = quantile(complement(t, beta));
    qa += qb;
    qa *= qa;
    qa *= ratio;
    qa -= (df + 1);
    return qa;
 }
Exemple #9
0
void seqrc( char* seq, int n )
{
    char c;
    int i,j;
    i = 0;
    j = n-1;
    while( i < j ) {
        c = complement(seq[i]);
        seq[i] = complement(seq[j]);
        seq[j] = c;
        i++; j--;
    }

    if( i == j ) seq[i] = complement(seq[i]);
}
T hotelling_t2_1test(
  boost::numeric::ublas::vector<T> mean1,
  boost::numeric::ublas::vector<T> mean2,
  boost::numeric::ublas::matrix<T> cov1,
  unsigned n1
){
  unsigned k=mean1.size();  

  boost::numeric::ublas::vector<T > mean_diff=mean1-mean2;
  boost::numeric::ublas::matrix<T>  cov_inv(cov1);
  invert_matrix(cov1  ,cov_inv);
  T t2_score=
  boost::numeric::ublas::inner_prod(
			      boost::numeric::ublas::prod( cov_inv,mean_diff)
			      ,mean_diff)*n1;
  T f_score= (t2_score*(n1 - k))/(k*(n1-1));

  std::cout << t2_score   << std::endl;
  std::cout << f_score   << std::endl;

  boost::math::fisher_f dist(k, n1-k);
  T p_score =boost::math::cdf(dist, f_score);

  std::cout << p_score << std::endl;
  T p_comp =boost::math::cdf(complement(dist, f_score));
  std::cout << p_comp << std::endl;
  //return p_comp;
  return p_score;
}
Exemple #11
0
TEST(ProbDistributionsBernoulli, chiSquareGoodnessFitTest) {
  boost::random::mt19937 rng;
  int N = 10000;
  boost::math::bernoulli_distribution<>dist (0.4);
  boost::math::chi_squared mydist(1);
 
  int bin[2] = {0, 0};
  double expect [2] = {N * (1 - 0.4), N * (0.4)};

  int count = 0;

  while (count < N) {
    int a = stan::prob::bernoulli_rng(0.4,rng);
    if(a == 1)
      ++bin[1];
    else
      ++bin[0];
    count++;
   }

  double chi = 0;

  for(int j = 0; j < 2; j++)
    chi += ((bin[j] - expect[j]) * (bin[j] - expect[j]) / expect[j]);

  EXPECT_TRUE(chi < quantile(complement(mydist, 1e-6)));
}
extern int tr_main(int argc, char **argv)
{
	register unsigned char *ptr;
	int output_length=0, input_length;
	int idx = 1;
	int i;
	RESERVE_CONFIG_BUFFER(output, BUFSIZ);
	RESERVE_CONFIG_BUFFER(input,  BUFSIZ);
	RESERVE_CONFIG_UBUFFER(vector, ASCII+1);
	RESERVE_CONFIG_BUFFER(invec,  ASCII+1);
	RESERVE_CONFIG_BUFFER(outvec, ASCII+1);

	/* ... but make them available globally */
	poutput = output;
	pinput  = input;
	pvector = vector;
	pinvec  = invec;
	poutvec = outvec;

	if (argc > 1 && argv[idx][0] == '-') {
		for (ptr = (unsigned char *) &argv[idx][1]; *ptr; ptr++) {
			switch (*ptr) {
			case 'c':
				com_fl = TRUE;
				break;
			case 'd':
				del_fl = TRUE;
				break;
			case 's':
				sq_fl = TRUE;
				break;
			default:
				bb_show_usage();
			}
		}
		idx++;
	}
	for (i = 0; i <= ASCII; i++) {
		vector[i] = i;
		invec[i] = outvec[i] = FALSE;
	}

	if (argv[idx] != NULL) {
		input_length = expand(argv[idx++], input);
		if (com_fl)
			input_length = complement(input, input_length);
		if (argv[idx] != NULL) {
			if (*argv[idx] == '\0')
				bb_error_msg_and_die("STRING2 cannot be empty");
			output_length = expand(argv[idx], output);
			map(input, input_length, output, output_length);
		}
		for (i = 0; i < input_length; i++)
			invec[(unsigned char)input[i]] = TRUE;
		for (i = 0; i < output_length; i++)
			outvec[(unsigned char)output[i]] = TRUE;
	}
	convert();
	return (0);
}
Exemple #13
0
int main6(int argc, char *argv[]) {  
  Intstack cell, co;
  int rank, upb, nr = 0;
  assert(argc > 1);
  rank = atoi(argv[1]);
  upb = 1 << rank;
  co = newIntstack(upb, NULL);
  cell = readCell();
  while (cell) {
    nr = getCnr();
    printCell(nr, cell);
    complement(upb, cell, co);
    printf("COM ");
    printCell(0, co);
    freestack(cell);
    printf("\n");
    cell = readCell();
  }
  freestack(cell);
  freestack(co);
#if 0
  reportTime();
  reportCnt();
#endif
  finalizeScanner();
  return 0;
}
Exemple #14
0
SignalSensor::SignalSensor(GarbageCollector &gc,const SignalSensor &other,
			   bool revComp)
  : consensuses(PRIME_HASH_SIZE),
    gc(gc),
    probabilityInverter(NULL)
{
  contextWindowLength=other.contextWindowLength;
  consensusLength=other.consensusLength;
  cutoff=other.cutoff;
  
  if(revComp)
    {
      consensusOffset=
	contextWindowLength-other.consensusOffset-consensusLength;
      strand=complement(other.strand);
      signalType=::reverseComplement(other.signalType);
      BOOM::StringMap<char>::const_iterator cur=other.consensuses.begin(), 
	end=other.consensuses.end();
      for(; cur!=end ; ++cur)
	{
	  const StringMapElem<char> &elem=*cur;
	  BOOM::String reverseConsensus=
	    BOOM::ProteinTrans::reverseComplement(elem.first);
	  consensuses.lookup(reverseConsensus.c_str(),elem.len)=char(1);
	}
    }
  else
    {
      consensusOffset=other.consensusOffset;
      strand=other.strand;
      signalType=other.signalType;
      consensuses=other.consensuses;
    }
}
TEST(ProbDistributionsExponential, chiSquareGoodnessFitTest) {
  boost::random::mt19937 rng;
  int N = 10000;
  int K = boost::math::round(2 * std::pow(N, 0.4));
  boost::math::exponential_distribution<>dist (2.0);
  boost::math::chi_squared mydist(K-1);

  double loc[K - 1];
  for(int i = 1; i < K; i++)
    loc[i - 1] = quantile(dist, i * std::pow(K, -1.0));

  int count = 0;
  int bin [K];
  double expect [K];
  for(int i = 0 ; i < K; i++) {
    bin[i] = 0;
    expect[i] = N / K;
  }

  while (count < N) {
    double a = stan::math::exponential_rng(2.0,rng);
    int i = 0;
    while (i < K-1 && a > loc[i]) 
      ++i;
    ++bin[i];
    count++;
   }

  double chi = 0;

  for(int j = 0; j < K; j++)
    chi += ((bin[j] - expect[j]) * (bin[j] - expect[j]) / expect[j]);

  EXPECT_TRUE(chi < quantile(complement(mydist, 1e-6)));
}
Exemple #16
0
my_type redundant(int *new_clause, int *old_clause) {
  int lit1, lit2, old_clause_diff=0, new_clause_diff=0;
    
  lit1=*old_clause; lit2=*new_clause;
  while ((lit1 != NONE) && (lit2 != NONE)) {
    if (smaller_than(lit1, lit2)) {
      lit1=*(++old_clause); old_clause_diff++;
    }
    else
      if (smaller_than(lit2, lit1)) {
	lit2=*(++new_clause); new_clause_diff++;
      }
      else
	if (complement(lit1, lit2)) {
	  return FALSE; /* old_clause_diff++; new_clause_diff++; j1++; j2++; */
	}
	else {
          lit1=*(++old_clause);  lit2=*(++new_clause);
	}
  }
  if ((lit1 == NONE) && (old_clause_diff == 0))
    /* la nouvelle clause est redondante ou subsumee */
    return NEW_CLAUSE_REDUNDANT;
  if ((lit2 == NONE) && (new_clause_diff == 0))
    /* la old clause est redondante ou subsumee */
    return OLD_CLAUSE_REDUNDANT;
  return FALSE;
}
std::string Breakpoint::rev_complement(std::string seq) {
	std::string tmp;
	for (std::string::reverse_iterator i = seq.rbegin(); i != seq.rend(); i++) {
		tmp += complement((*i));
	}
	return tmp;
}
T hotelling_t2_2test(
  boost::numeric::ublas::vector<T> mean1,
  boost::numeric::ublas::vector<T> mean2,
  boost::numeric::ublas::matrix<T> cov1,
  boost::numeric::ublas::matrix<T> cov2, 
  unsigned n1,
  unsigned n2){
  unsigned k=mean1.size();  
//int n = n1 + n2 -1;
  boost::numeric::ublas::vector<T > mean_diff=mean1-mean2;
  boost::numeric::ublas::matrix<T>  
  pooled_cov=(cov1*(n1-1)+cov2*(n2-1))*1.0/(n1+n2-2) ;
  pooled_cov *= (1.0/n1+1.0/n2 );
  boost::numeric::ublas::matrix<T>  pooled_cov_inv(pooled_cov);
  invert_matrix(   pooled_cov  ,pooled_cov_inv);
//std::cout << mean_diff << std::endl;  
  T t2_score=
  boost::numeric::ublas::inner_prod(
			      boost::numeric::ublas::prod( pooled_cov_inv,mean_diff)
			      ,mean_diff);
  T f_score= (t2_score*(n1 + n2 - 1- k))/(k*(  n1 + n2 - 2));

  std::cout << t2_score   << std::endl;
  std::cout << f_score   << std::endl;

  boost::math::fisher_f dist(k, n1+n2-1-k);
  T p_score =boost::math::cdf(dist, f_score);

  std::cout << p_score << std::endl;
  T p_comp =boost::math::cdf(complement(dist, f_score));
  std::cout << p_comp << std::endl;
  //return p_comp;
  return p_score;
}
char *make_complement_sequence_of(char *sequence, long unsigned length){
  long i;
  for(i=0;i<length;i++){
    sequence[i]=complement((int)sequence[i]);
  }  
  return sequence;
}
TEST(ProbDistributionsScaledInvChiSquare, chiSquareGoodnessFitTest) {
  boost::random::mt19937 rng;
  int N = 10000;
  double K = 5;
  boost::math::inverse_chi_squared_distribution<>dist (2.0);
  boost::math::chi_squared mydist(K-1);

  double loc[4];
  for(int i = 1; i < K; i++)
    loc[i - 1] = quantile(dist, 0.2 * i);

  int count = 0;
  int bin [5] = {0, 0, 0, 0, 0};

  while (count < N) {
    double a = stan::prob::scaled_inv_chi_square_rng(2.0,1.0,rng) / (2.0 * 1.0);
    int i = 0;
    while (i < K-1 && a > loc[i]) 
      ++i;
    ++bin[i];
    count++;
   }

  double chi = 0;
  double expect [5] = {N / K, N / K, N / K, N / K, N / K};

  for(int j = 0; j < K; j++)
    chi += ((bin[j] - expect[j]) * (bin[j] - expect[j]) / expect[j]);

  EXPECT_TRUE(chi < quantile(complement(mydist, 1e-6)));
}
Exemple #21
0
void write_reverse_complement(chunk * begin, chunk * end)
{
   chunk * start = begin;
   char * begin_char = begin->data;
   char * end_char = end->data + end->length - 1;
   while (begin != end || begin_char < end_char)
   {
      char temp = complement(*begin_char);
      *begin_char++ = complement(*end_char);
      *end_char-- = temp;
      if (*begin_char == '\n')
      {
         ++begin_char;
      }
      if (*end_char == '\n')
      {
         --end_char;
      }
      if (begin_char == begin->data + begin->length)
      {
         begin = begin->next;
         begin_char = begin->data;
         if (*begin_char == '\n')
         {
            ++begin_char;
         }
      }
      if (end_char == end->data - 1)
      {
         end = end->previous;
         end_char = end->data + end->length - 1;
         if (*end_char == '\n')
         {
            --end_char;
         }
      }
   }
   while (start)
   {
      std::cout.write(start->data, start->length);
      chunk * last = start;
      start = start->next;
      delete last;
   }
   std::cout.put('\n');
}
Exemple #22
0
T nc_beta_ccdf(T a, T b, T nc, T x)
{
#ifdef NC_BETA_CCDF_FUNCTION_TO_TEST
    return NC_BETA_CCDF_FUNCTION_TO_TEST(a, b, nc, x);
#else
    return cdf(complement(boost::math::non_central_beta_distribution<T>(a, b, nc), x));
#endif
}
double Calculator::rosnerApprox(int n, int s, double alpha, bool two_side) {
    double p = alpha/(n-s+1);
    if(two_side) {
        p /= 2;
    }
    boost::math::students_t stud_t(n-s-1);
    double t = boost::math::quantile(complement(stud_t, p));
    return t*(n-s)/( sqrt((n-s+1)*(n-s-1+pow(t,2))) );
}
  BigInt BigInt::operator-(BigInt b) {
    if (b == 0)
      return *this;

    complement(b.value_);
    b.negative_ = not b.negative_;

    return *this + b;
  }
Exemple #25
0
// Complement a sequence
std::string complement(const std::string& seq)
{
    std::string out(seq.length(), 'A');
    size_t l = seq.length();
    for(size_t i = 0; i < l; ++i)
    {
        out[i] = complement(seq[i]);
    }
    return out;
}
ContentSensor *ThreePeriodicMarkovChain::reverseComplement()
{
  ThreePeriodicMarkovChain *other=
    new ThreePeriodicMarkovChain(complement(getStrand()),
				 ::reverseComplement(getContentType()));
  for(int i=0 ; i<3 ; ++i)
    other->chains[i]=
      static_cast<MarkovChain*>(chains[i]->reverseComplement());
  return other;
}
Exemple #27
0
/* db_restart - restart the current game */
int db_restart()
{
    glk_stream_set_position(datafd,saveoff,seekmode_Start);
    if (glk_get_buffer_stream(datafd,save,slen) != slen)
		return (NIL);
    complement(save,slen);
    setvalue(V_OCOUNT,ocount);
    
	longjmp(restart,1);
}
Exemple #28
0
/* is_complement: True if base1 is the complement of base2.
 * Not case sensitive */
int is_complement(char base1, char base2)
{
    if (complement(toupper(base1)) == toupper(base2))
    {
        return TRUE;
    } else
    {
        return FALSE;
    }
}
void process_edge(int x, int y)
{
  // y already has a color
  if (color[x] == color[y]) {
    bipartite = FALSE;
    printf("Warning: graph not bipartite, due to (%d,%d)\n",x,y);
  } 

  color[y] = complement(color[x]);
}
Exemple #30
0
int gt_reverse_complement(char *dna_seq, unsigned long seqlen, GtError *err)
{
  char *front_char, *back_char, tmp_char;
  int had_err = 0;
  gt_error_check(err);
  gt_assert(dna_seq);
  for (front_char = dna_seq, back_char = dna_seq + seqlen - 1;
       front_char <= back_char;
       front_char++, back_char--) {
    had_err = complement(&tmp_char, *front_char, err);
    if (!had_err)
      had_err = complement(front_char, *back_char, err);
    if (!had_err)
      *back_char = tmp_char;
    if (had_err)
      break;
  }
  return had_err;
}