Beispiel #1
0
LVAL xlc_seq_get(void)
{
    seq_type arg1 = getseq(xlgaseq());
    long arg2 = 0;
    long arg3 = 0;
    long arg4 = 0;
    long arg5 = 0;
    long arg6 = 0;
    long arg7 = 0;
    long arg8 = 0;
    LVAL result;

    xllastarg();
    seq_get(arg1, &arg2, &arg3, &arg4, &arg5, &arg6, &arg7, &arg8);
    {	LVAL *next = &getvalue(RSLT_sym);
	*next = cons(NIL, NIL);
	car(*next) = cvfixnum(arg2);	next = &cdr(*next);
	*next = cons(NIL, NIL);
	car(*next) = cvfixnum(arg3);	next = &cdr(*next);
	*next = cons(NIL, NIL);
	car(*next) = cvfixnum(arg4);	next = &cdr(*next);
	*next = cons(NIL, NIL);
	car(*next) = cvfixnum(arg5);	next = &cdr(*next);
	*next = cons(NIL, NIL);
	car(*next) = cvfixnum(arg6);	next = &cdr(*next);
	*next = cons(NIL, NIL);
	car(*next) = cvfixnum(arg7);	next = &cdr(*next);
	*next = cons(NIL, NIL);
	car(*next) = cvfixnum(arg8);
    }
    result = getvalue(RSLT_sym);
    return result;
}
Beispiel #2
0
LVAL xlc_seq_reset(void)
{
    seq_type arg1 = getseq(xlgaseq());

    xllastarg();
    seq_reset(arg1);
    return NIL;
}
Beispiel #3
0
LVAL xlc_seq_write_smf(void)
{
    seq_type arg1 = getseq(xlgaseq());
    FILE * arg2 = getfile(xlgastream());

    xllastarg();
    seq_write_smf(arg1, arg2);
    return NIL;
}
Beispiel #4
0
LVAL xlc_seq_copy(void)
{
    seq_type arg1 = getseq(xlgaseq());
    seq_type result;

    xllastarg();
    result = seq_copy(arg1);
    return cvseq(result);
}
Beispiel #5
0
LVAL xlc_seq_next(void)
{
    seq_type arg1 = getseq(xlgaseq());
    boolean result;

    xllastarg();
    result = seq_next(arg1);
    return cvboolean(result);
}
Beispiel #6
0
LVAL xlc_seq_write(void)
{
    seq_type arg1 = getseq(xlgaseq());
    FILE * arg2 = getfile(xlgastream());
    int arg3 = getboolean(xlgetarg());

    xllastarg();
    seq_write(arg1, arg2, arg3);
    return NIL;
}
Beispiel #7
0
main(int argc, char **argv) {

  char *aa0;
  char libstr[MAX_FN];
  char qname[MAX_FN];
  int sq0off;
  int i, n0;
  FILE *fp;
  struct pstruct pst, *ppst;

  /* stuff from initfa.c/h_init() */

  memcpy(qascii,aascii,sizeof(qascii));

  /* initialize a pam matrix */
  ppst = &pst;
  strncpy(ppst->pamfile,"BL50",MAX_FN);
  standard_pam(ppst->pamfile,ppst,0,0);

  /* this is always protein by default */
  ppst->nsq = naa;
  ppst->nsqx = naax;
  for (i=0; i<=ppst->nsqx; i++) {
    ppst->sq[i] = aa[i];
    ppst->hsq[i] = haa[i];
    ppst->sqx[i]=aax[i];	/* sq = aa */
    ppst->hsqx[i]=haax[i];	/* hsq = haa */
  }
  ppst->sq[ppst->nsqx+1] = ppst->sqx[ppst->nsqx+1] = '\0';

  if ((aa0 = calloc(MAXTST,sizeof(char)))==NULL) {
    fprintf(stderr,"Cannot allocate aa0\n");
    exit(1);
  }

  initenv(argc, argv, &pst, qname);
  alloc_pam(pst.nsq+1,pst.nsq+1, &pst);
  initpam2(&pst);

  n0 = getseq (qname, qascii, aa0, MAXTST, libstr,&sq0off);

  if (!pst.pam_pssm) {
    fprintf(stderr," ** ERROR ** No -P PSSM provided\n");
  }
  else {
    ppst->pam2p[0] = alloc_pam2p(n0,pst.nsq);
    ppst->pam2p[1] = alloc_pam2p(n0,pst.nsq);
    if ((fp = fopen(pst.pgpfile,"rb"))!=NULL) {
      read_pssm(aa0, n0, pst.nsq, pst.pamscale,fp,ppst);
    }
  }
}
Beispiel #8
0
LVAL xlc_seq_insert_macctrl(void)
{
    seq_type arg1 = getseq(xlgaseq());
    long arg2 = getfixnum(xlgafixnum());
    long arg3 = getfixnum(xlgafixnum());
    long arg4 = getfixnum(xlgafixnum());
    long arg5 = getfixnum(xlgafixnum());
    long arg6 = getfixnum(xlgafixnum());

    xllastarg();
    insert_macctrl(arg1, arg2, arg3, arg4, arg5, arg6);
    return NIL;
}
Beispiel #9
0
int
main(int argc, char * argv[])
{
	if (argc != 3)
		usage(argv[0]);

	int n = atol(argv[2]);
	srand(701888);

	env = sp_env();
	sp_ctl(env, SPDIR, SPO_CREAT|SPO_RDWR, "./sophia_bench_data");
	db = sp_open(env);
	if (db == NULL) {
		printf("open: %s\n", sp_error(env));
		return 1;
	}
	
	int rc = 0;
	unsigned long long start = now();
	
	switch (benchof(argv[1]))
	{
	case SETSEQ: rc = setseq(n);
		break;
	case SETRAND: rc = setrand(n);
		break;
	case GETSEQ:rc = getseq(n);
		break;
	case GETRAND: rc = getrand(n);
		break;
	case RANGEFWD: rc = rangefwd(n);
		break;
	case UNKNOWN:
		printf("unknown operation\n");
	}

	if (rc == 0) {
		unsigned long long diff = now() - start;
		float rps = n / (diff / 1000.0);
		printf("%d rps\n", (int)rps);
	}
	if (keytraversed > 0 && keytraversed != n)
		printf("(%d keys traversed)\n", keytraversed);

	sp_destroy(db);
	sp_destroy(env);
	return rc;
}
Beispiel #10
0
LVAL xlc_seq_insert_ramp(void)
{
    seq_type arg1 = getseq(xlgaseq());
    long arg2 = getfixnum(xlgafixnum());
    long arg3 = getfixnum(xlgafixnum());
    long arg4 = getfixnum(xlgafixnum());
    long arg5 = getfixnum(xlgafixnum());
    long arg6 = getfixnum(xlgafixnum());
    long arg7 = getfixnum(xlgafixnum());
    long arg8 = getfixnum(xlgafixnum());
    long arg9 = getfixnum(xlgafixnum());

    xllastarg();
    insert_ctrlramp(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
    return NIL;
}
Beispiel #11
0
static void elcount( int *npnts, int *npols )
{
   int i, apts, apls, bpts, bpls, ppts, ppls;

   getseq();

   for ( i = 0, bpls = 0; i < seqlen; i++ )
      bpls += bond_count( seq[ i ] );

   if ( bond_type == BTYPE_LINE ) {
      for ( i = 0, bpts = 0; i < seqlen; i++ )
         bpts += point_count( seq[ i ] ) - 4;
      bpts += 2;
   }
   else {
      bpts = bpls * bond_nsides * ( 1 + bond_nsegments );
      bpls *= bond_nsides * bond_nsegments + 2;
   }

   for ( i = 0, apls = 0; i < seqlen; i++ )
      apls += atom_count( seq[ i ] );

   if ( atom_type == ATYPE_POINT )
      apts = ( bond_type == BTYPE_LINE ) ? 0 : apls;
   else if ( atom_type == ATYPE_SPHERE ) {
      apts = apls * ( atom_nsides * ( atom_nsegments - 1 ) + 2 );
      apls *= atom_nsides * atom_nsegments;
   }
   else {
      apts = 20 * apls;
      apls *= 12;
   }

   if ( do_plates ) {
      ppts = ( atom_type == ATYPE_POINT || bond_type == BTYPE_LINE ) ?
         0 : 15 * seqlen;
      ppls = 2 * seqlen;
   }
   else ppts = ppls = 0;

   if ( npnts ) *npnts = apts + bpts + ppts;
   if ( npols ) *npols = apls + bpls + ppls;
}
Beispiel #12
0
static void
join (
     FILE *fp1,
     FILE *fp2 )
{
  struct seq seq1, seq2;
  struct line line;
  int diff, i, j, eof1, eof2;

  /* Read the first line of each file. */
  initseq (&seq1);
  getseq (fp1, &seq1);
  initseq (&seq2);
  getseq (fp2, &seq2);

  while (seq1.count && seq2.count)
    {
      diff = keycmp (&seq1.lines[0], &seq2.lines[0]);
      if (diff < 0)
	{
	  if (print_unpairables_1)
	    prline (&seq1.lines[0]);
	  freeline (&seq1.lines[0]);
	  seq1.count = 0;
	  getseq (fp1, &seq1);
	  continue;
	}
      if (diff > 0)
	{
	  if (print_unpairables_2)
	    prline (&seq2.lines[0]);
	  freeline (&seq2.lines[0]);
	  seq2.count = 0;
	  getseq (fp2, &seq2);
	  continue;
	}

      /* Keep reading lines from file1 as long as they continue to
	 match the current line from file2. */
      eof1 = 0;
      do
	if (!getseq (fp1, &seq1))
	  {
	    eof1 = 1;
	    ++seq1.count;
	    break;
	  }
      while (!keycmp (&seq1.lines[seq1.count - 1], &seq2.lines[0]));

      /* Keep reading lines from file2 as long as they continue to
	 match the current line from file1. */
      eof2 = 0;
      do
	if (!getseq (fp2, &seq2))
	  {
	    eof2 = 1;
	    ++seq2.count;
	    break;
	  }
      while (!keycmp (&seq1.lines[0], &seq2.lines[seq2.count - 1]));

      if (print_pairables)
	{
	  for (i = 0; i < seq1.count - 1; ++i)
	    for (j = 0; j < seq2.count - 1; ++j)
	      prjoin (&seq1.lines[i], &seq2.lines[j]);
	}

      for (i = 0; i < seq1.count - 1; ++i)
	freeline (&seq1.lines[i]);
      if (!eof1)
	{
	  seq1.lines[0] = seq1.lines[seq1.count - 1];
	  seq1.count = 1;
	}
      else
	seq1.count = 0;

      for (i = 0; i < seq2.count - 1; ++i)
	freeline (&seq2.lines[i]);
      if (!eof2)
	{
	  seq2.lines[0] = seq2.lines[seq2.count - 1];
	  seq2.count = 1;
	}
      else
	seq2.count = 0;
    }

  if (print_unpairables_1 && seq1.count)
    {
      prline (&seq1.lines[0]);
      freeline (&seq1.lines[0]);
      while (getline (fp1, &line))
	{
	  prline (&line);
	  freeline (&line);
	}
    }

  if (print_unpairables_2 && seq2.count)
    {
      prline (&seq2.lines[0]);
      freeline (&seq2.lines[0]);
      while (getline (fp2, &line))
	{
	  prline (&line);
	  freeline (&line);
	}
    }

  delseq (&seq1);
  delseq (&seq2);
}
Beispiel #13
0
unsigned long long * get_kmer_counts_from_file(const char *fn, const unsigned int kmer) {

	char *line = NULL;
	size_t len = 0;
	ssize_t read;

	long long i = 0;
	long long position = 0;

	FILE * const fh = fopen(fn, "r");
	if(fh == NULL) {
		fprintf(stderr, "Error opening %s - %s\n", fn, strerror(errno));
		exit(EXIT_FAILURE);
	}

	// width is 4^kmer  
	// there's a sneaky bitshift to avoid pow dependency
	const unsigned long width = pow_four(kmer); 

	// malloc our return array
	unsigned long long * counts = malloc((width+ 1) * sizeof(unsigned long long));
	memset(counts, 0, width * sizeof(unsigned long long));
	if(counts == NULL)  {
		fprintf(stderr, strerror(errno));
		exit(EXIT_FAILURE);
	}

	char *str = malloc(4096);
	if(str == NULL) { 
		fprintf(stderr, strerror(errno));
		exit(EXIT_FAILURE);
	}

	unsigned long long str_size = 4096;

	while ((read = getseq(&line, &len, fh)) != -1) {

		// find our first \n, this should be the end of the header
		char *start = strchr(line, '\n');	
		if(start == NULL) 
			continue;
		
		start = start + 1;

		size_t start_len = strlen(start);


		// if our current str buffer isn't big enough, realloc
		if(start_len + 1 > str_size + 1) { 
			str = realloc(str, start_len + 1);
			if(str == NULL) { 
				exit(EXIT_FAILURE);
				fprintf(stderr, strerror(errno));
			}
		}

		// strip out all other newlines to handle multiline sequences
		str = strnstrip(start, str, '\n',start_len);
		ssize_t seq_length = strlen(str);
		if(seq_length < kmer)
			continue;

		// relace A, C, G and T with 0, 1, 2, 3 respectively
		// everything else is 5 
		for(i = 0; i < seq_length; i++) {
			str[i] = alpha[(int)str[i]];
		}

		// loop through our string to process each k-mer
		for(position = 0; position < (seq_length - kmer + 1); position++) {
			unsigned long mer = 0;
			unsigned long multiply = 1;

			// for each char in the k-mer check if it is an error char
			for(i = position + kmer - 1; i >= position; i--){
				if(str[i] == 5) { 
					mer = width;
					position = i;
					goto next;
				}
				// if it's a newline, we should skip it

				// multiply this char in the mer by the multiply
				// and bitshift the multiply for the next round
				mer += str[i] * multiply;
				multiply = multiply << 2;
			}
			// use this point to get mer of our loop
			next:
			// bump up the mer value in the counts array
			counts[mer]++;
		}
	} 

	free(line);
	free(str);
	fclose(fh);

	return counts;
}