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
long get_min_seq(seq_t seqs, long min) {
	int i, n = seq_length(seqs);

	for (i = 0; i < n; ++i)
		min = MIN(min, seq_get(&seqs[i]));
	return min;
}
Beispiel #3
0
int driver (int t_num)
{

    int i, j;

    /* Actually, WaitTimes are needed... */
    while( activate_transaction ){
      switch(seq_get()){
      case 0:
	do_neword(t_num);
	break;
      case 1:
	do_payment(t_num);
	break;
      case 2:
	do_ordstat(t_num);
	break;
      case 3:
	do_delivery(t_num);
	break;
      case 4:
	do_slev(t_num);
	break;
      default:
	printf("Error - Unknown sequence.\n");
      }
    }

    return(0);

}
Beispiel #4
0
void c_seq::seek(uint32 keyId, int index, wisdom_IOStream& io)
 {
	SEQ_INIT();

	if (is_clean())
	{
		wisdom_IOStream os = new c_ostream_array;
		remove(os);
	}

	c_rlock lock(&m_lock);
	io->push(ZRESULT_OK);

	if (keyId == 0)
	{
		keyId = m_seq_head.g_index();
	}

	bool down_up = index > 0 ? true : false;
	index = abs(index);

	for (int i = 0; i < index; i++)
	{
		string value;
		if (!seq_get(keyId, value))
		{
			break;
		}
		char* ptr = (char*)value.c_str() + sizeof(_zmsg_head);
		int len = value.length() - sizeof(_zmsg_head);
		_zmsg_head* h = (_zmsg_head*)value.c_str();
		c_time t(h->g_effective());
		io->push(__tos(keyId << "," << t.time_stamp() << ","));
		io->push(ptr, len);

		if (down_up)
			keyId++;
		else
			keyId--;
	}
}
Beispiel #5
0
int main(int argc, char *argv[])
{
	SEQ *sf;
	uchar *s;
	FILE *f;
	char buf[10000];
	char head[MAX_LEN];
	char cur[LEN_NAME], chr_name[LEN_NAME], annot[LEN_NAME], gname[LEN_NAME], filter[LEN_NAME];
	int gid = -1;
	int rid = -1;
	int i = 0;
	int b = 0, e = 1, num_cds = 0;
	char dir[3];
	struct exons_list *exons;
	char annot_name[LEN_NAME];
	float qual = (float)0;
	char ref[LEN_NAME], alt[LEN_NAME];
	int rest = 0;
	char codon[4], alt_codon[4];
	char aa1 = '\0', aa2 = '\0';
	int num_rmsk = 0;
	struct exons_list *rmsk;
	int num_snps = 0, num_pass = 0, num_filter = 0, num_coding1 = 0, num_syn1 = 0, num_non1 = 0, num_repeats1 = 0, num_coding_repeats1 = 0;
	int num_coding = 0, num_syn = 0, num_non = 0, num_repeats = 0, num_coding_repeats = 0;
	bool is_num_print = false;

	strcpy(buf, "");
	strcpy(head, "");
	strcpy(cur, "");
	strcpy(chr_name, "");
	strcpy(annot, "");
	strcpy(gname, "");
	strcpy(annot_name, "");
	strcpy(ref, "");
	strcpy(alt, "");
	strcpy(codon, "");
	strcpy(alt_codon, "");
	strcpy(dir, "");
	codon[3] = '\0';
	alt_codon[3] = '\0';

	if( argc != 7 ) {
		printf("link_to_annot vcf_file gff_file seq_file annot_type(exon, gene, ...) rmsk_file print_mode(NUM or SITES)\n");
		return EXIT_FAILURE;
	}
	else {
		if(!(f = ckopen(argv[2], "r"))) {
			printf("no file %s exists\n", argv[2]);
			return EXIT_FAILURE;
		}

		strcpy(annot_name, argv[4]);
		if( strcmp(annot_name, "exon") != 0 ) {
			fatalf("seq file is required only when the annot type is exon, but %s here\n", annot_name);
		}
		sf = seq_get(argv[3]);
		s = SEQ_CHARS(sf) - 1;
		if( strcmp(argv[6], "NUM") == 0 ) {
			is_num_print = true;
		}
		else if( strcmp(argv[6], "SITES") == 0 ) {
			is_num_print = false;
		}
		else {
			fatalf("unsupported print option: %s\n", argv[6]);
		}
	}

  compl['a'] = compl['A'] = 'T';
  compl['c'] = compl['C'] = 'G';
  compl['g'] = compl['G'] = 'C';
  compl['t'] = compl['T'] = 'A';

	while(fgets(buf, 10000, f))
	{
		if( (buf[0] == '#') || (buf[0] == '>') ) {}
		else if( sscanf(buf, "%*s %*s %s %d %d %*s", annot, &b, &e) != 3 ) {
			fatalf("line in wrong gff format: %s\n", buf);
		}
		else {
			if( strcmp(annot, annot_name) == 0 ) {
				num_cds++;
			}
		}
	}

	if( num_cds > 0 ) exons = (struct exons_list *) ckalloc(num_cds * sizeof(struct exons_list));

	initialize_exons_list(exons, 0, num_cds);

	fseek(f, 0, SEEK_SET);

	i = 0;
	
	while(fgets(buf, 10000, f))
	{
		if( (buf[0] == '#') || (buf[0] == '>') ) {}
		else if( sscanf(buf, "%s %*s %s %d %d %*s %s %*s %s", chr_name, annot, &b, &e, dir, cur) != 6 ) {
			fatalf("line in wrong gff format: %s\n", buf);
		}
		else {
			if( strcmp(annot, annot_name) == 0 ) {
				get_gene_name(cur, gname);
				strcpy(exons[i].name, gname);
				exons[i].reg = assign_I(b, e);
				exons[i].dir = dir[0];
				strcpy(exons[i].chr, chr_name);
				i++;
			}	
		}
	}

	if( i != num_cds ) {
		fatalf("%s counting error: %d - %d\n", annot_name, num_cds, i);
	}
	fclose(f);

	if(!(f = ckopen(argv[5], "r"))) {
		fatalf("%s file not found\n", argv[5]);
	}

	rmsk = 0;
	while(fgets(buf, 10000, f))
	{
		if( (buf[0] == '#') || (buf[0] == '>') ) {}
		else if( sscanf(buf, "%*s %*s %s %d %d %*s", annot, &b, &e) != 3 ) {
			fatalf("line in wrong gff format: %s\n", buf);
		}
		else {
			num_rmsk++;
		}
	}

	if( num_rmsk > 0 ) rmsk = (struct exons_list *) ckalloc(num_rmsk * sizeof(struct exons_list));

	initialize_exons_list(rmsk, 0, num_rmsk);

	fseek(f, 0, SEEK_SET);

	i = 0;
	
	while(fgets(buf, 10000, f))
	{
		if( (buf[0] == '#') || (buf[0] == '>') ) {}
		else if( sscanf(buf, "%s %*s %s %d %d %*s %s %*s %s", chr_name, annot, &b, &e, dir, cur) != 6 ) {
			fatalf("line in wrong gff format: %s\n", buf);
		}
		else {
			strcpy(rmsk[i].name, annot);
			rmsk[i].reg = assign_I(b, e);
			rmsk[i].dir = dir[0];
			strcpy(rmsk[i].chr, chr_name);
			i++;
		}
	}

	if( i != num_rmsk ) {
		fatalf("%s counting error: %d - %d\n", annot_name, num_cds, i);
	}
	fclose(f);

	if(!(f = ckopen(argv[1], "r"))) {
		printf("no file %s exists\n", argv[1]);
		return EXIT_FAILURE;
	}

	i = 0;
	while(fgets(buf, 10000, f))
	{
		if( buf[0] != '#' ) {
			num_snps++;
			if( sscanf(buf, "%s %d %*s %s %s %f %s %*s", chr_name, &b, ref, alt, &qual, filter) != 6 ) {
				fatalf("bad format in %s\n", buf);
			}
			else 
			{
				if( strstr(filter, "PASS") == 0 ) {
					num_pass++;
				}
				else if( strstr(filter, "filter") == 0 ) {
					num_filter++;
				}

				rid = -1;
				rid = find_overlap_gene(chr_name, b, rmsk, num_rmsk);
				if( rid != -1 ) {
					num_repeats++;
					if( strstr(filter, "filter") == 0 ) {}
					else if( strstr(filter, "PASS") == 0 ) {
						num_repeats1++;
					}
					else {
						fatalf("unexpected filter option: %s\n", filter);
					}
				}

				if( (gid = find_overlap_gene(chr_name, b, exons, num_cds)) != -1 ) {
					num_coding++;
					if( strstr(filter, "PASS") == 0 ) {
						num_coding1++;
					}

					if( ref[0] != s[b] ) {
						fatalf("nucleotides not match: %c - %c\n", alt, s[b]);
					}

					if( exons[gid].dir == '+' ) {
						rest = (b - exons[gid].reg.lower)%3;
						if( rest == 0 ) {
							sprintf(codon, "%c%c%c", s[b], s[b+1], s[b+2]);
							sprintf(alt_codon, "%c%c%c", alt[0], s[b+1], s[b+2]);
						}
						else if( rest == 1 ) {
							sprintf(codon, "%c%c%c", s[b-1], s[b], s[b+1]);
							sprintf(alt_codon, "%c%c%c", s[b-1], alt[0], s[b+1]);
						}
						else {
							sprintf(codon, "%c%c%c", s[b-2], s[b-1], s[b]);
							sprintf(alt_codon, "%c%c%c", s[b-2], s[b-1], alt[0]);
						}
					}
					else if( exons[gid].dir == '-' ) {
						rest = (b - exons[gid].reg.upper)%3;
						if( rest == 0 ) {
							sprintf(codon, "%c%c%c", compl[s[b]], compl[s[b-1]], compl[s[b-2]]);
							sprintf(alt_codon, "%c%c%c", compl[alt[0]], compl[s[b-1]], compl[s[b-2]]);
						}
						else if( rest == 1 ) {
							sprintf(codon, "%c%c%c", compl[s[b+1]], compl[s[b]], compl[s[b-1]]);
							sprintf(alt_codon, "%c%c%c", compl[s[b+1]], compl[alt[0]], compl[s[b-1]]);
						}
						else {
							sprintf(codon, "%c%c%c", compl[s[b+2]], compl[s[b+1]], compl[s[b]]);
							sprintf(alt_codon, "%c%c%c", compl[s[b+2]], compl[s[b+1]], compl[alt[0]]);
						}
					}
					else {
						fatalf("%c unsupported\n", exons[gid].dir);
					}
					aa1 = dna2oneaa(codon);
					aa2 = dna2oneaa(alt_codon);
					
					if( aa1 == aa2 ) {
						num_syn++;
						if( strstr(filter, "filter") == 0) {
						}
						else if( strstr(filter, "PASS") == 0 ) {
							num_syn1++;
						}
						else {
							fatalf("unexpected filter option: %s\n", filter);
						}
					}
					else {
						num_non++;
						if( strstr(filter, "filter") == 0) {
						}
						else if( strstr(filter, "PASS") == 0 ) {
							num_non1++;
						}
						else {
							fatalf("unexpected filter option: %s\n", filter);
						}
					}
					
					if( rid != -1 ) {
						num_coding_repeats++;
						if( strstr(filter, "PASS") == 0 ) {
							num_coding_repeats1++;
						}
					}

					if( is_num_print == false ) {
						if( rid == -1 ) {
							printf("%s\t%d\t%s\t%s\t%f\t%s\t%s\t%d\t%d\t%c\t%c\t%c\t.\n", chr_name, b, ref, alt, qual, filter, exons[gid].name, exons[gid].reg.lower, exons[gid].reg.upper, exons[gid].dir, aa1, aa2);
						}
						else {
							printf("%s\t%d\t%s\t%s\t%f\t%s\t%s\t%d\t%d\t%c\t%c\t%c\t%s\n", chr_name, b, ref, alt, qual, filter, exons[gid].name, exons[gid].reg.lower, exons[gid].reg.upper, exons[gid].dir, aa1, aa2, rmsk[rid].name);
						}
					}
				}
				else {
				}
			}
		}
	}
	
	if( is_num_print == true ) {
		printf("%s\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", chr_name, num_snps, num_pass, num_filter, num_coding, num_coding1, num_non, num_syn, num_non1, num_syn1, num_repeats, num_repeats1, num_coding_repeats, num_coding_repeats1);
	}

	if( num_cds > 0 ) {
		free(exons);
	}
	fclose(f);

	return EXIT_SUCCESS;
}
Beispiel #6
0
int driver (int t_num)
{
    int i, j;

    double current_seconds = 0;
    long current_transactions = 0;
    double current_tps = 0;
    struct timeval currentTV;
    

    

    /* Actually, WaitTimes are needed... */
    while( activate_transaction ){
    
        // tmc : add rate limiting    
        if (t_num == 0)
        {
          gettimeofday(&currentTV, NULL); 
          current_seconds = currentTV.tv_sec + (currentTV.tv_usec/1000000);
          if (current_seconds > (rate_last_seconds + transaction_interval))
          { 
            rate_last_seconds = current_seconds; 
            rate_last_transactions = success[0];
          } 
        }

        // check current rate and tarpit if necessary
        gettimeofday(&currentTV, NULL); 
        current_seconds = currentTV.tv_sec + (currentTV.tv_usec/1000000);
        current_transactions = success[0];
        current_tps = ((current_transactions - rate_last_transactions) / (current_seconds - rate_last_seconds) * transaction_interval);

//            if (t_num == 1)
//            {
//              printf("thread %d : tps = %f\n",t_num,current_tps);
//              printf("thread %d : tps = %f : cur_secs = %f : last_secs = %f : cur_txn = %f : last_txn = %f\n",t_num,current_tps,current_seconds,rate_last_seconds,current_transactions,rate_last_transactions);
//            }

        while (current_tps > num_neword_per_10_sec)
        {
          usleep(100000);
          gettimeofday(&currentTV, NULL); 
          current_seconds = currentTV.tv_sec + (currentTV.tv_usec/1000000);
          current_transactions = success[0];
          current_tps = ((current_transactions - rate_last_transactions) / (current_seconds - rate_last_seconds) * transaction_interval);
        }
    
    
    
      switch(seq_get()){
      case 0:
	do_neword(t_num);
	break;
      case 1:
	do_payment(t_num);
	break;
      case 2:
	do_ordstat(t_num);
	break;
      case 3:
	do_delivery(t_num);
	break;
      case 4:
	do_slev(t_num);
	break;
      default:
	printf("Error - Unknown sequence.\n");
      }

    }

    return(0);

}
Beispiel #7
0
bool c_seq::seq_exists(uint32 keyId)
{
	string value;
	return seq_get(keyId, value);
}
Beispiel #8
0
int main(int argc, char **argv) {
	SEQ *sf;
	uchar *s;
	FILE *f;
	char chr_name[100], info[1000], dir;
	int i = 0, j = 0, k = 0, B = 0, E = 0;
	int max_len = 0;
	char *cur_seq;
	int seq_len = 0;
	bool is_correct_splicing = false;
	int num_genes = 0;
	int num_exons = 0;
	int num = 0;
	struct g_list *genes;
	struct exons_list *exons;
	bool no_branchpoint = false;

	if( argc == 5 ) {
		
	}	
	else if( argc == 4 ) {
		if( strcmp( argv[3], "NO_BRANCHPOINT") == 0 ) {
			no_branchpoint = true;
		}
		else {
			fatalf("args: fasta gff (NO_BRANCHPOINT)");
		}
	}
	else if (argc != 3)
		fatalf("args: fasta gff (NO_BRANCHPOINT)");

	if((f = ckopen(argv[2], "r")) == NULL )
	{
		fatalf("Cannot open file %s\n", argv[1]);
	}
	else {
		num_genes = count_genes_in_gff(f, &num_exons);
		if( num_genes > 0 ) {
			genes = (struct g_list *) ckalloc(num_genes * sizeof(struct g_list));	
			if( num_exons < num_genes ) num_exons = num_genes;
			exons = (struct exons_list *) ckalloc(num_exons * sizeof(struct exons_list));	
			initialize_genes(genes, num_genes);
			initialize_exons(exons, num_exons);
		}
	}
	fseek(f, 0, SEEK_SET);
	
	branchpoints = (char **) ckalloc(sizeof(char *) * NUM_BP_SEQ);
	for( i = 0; i < NUM_BP_SEQ; i++ ) {
		branchpoints[i] = (char *) ckalloc(sizeof(char) * 8);	
	}
	
	strcpy(branchpoints[0], "AACTAAC");
	strcpy(branchpoints[1], "AATTAAC");
	strcpy(branchpoints[2], "CACTAAC");
	strcpy(branchpoints[3], "GACTAAC");
	strcpy(branchpoints[4], "TACTAAC");
	strcpy(branchpoints[5], "TACTAAT");
	strcpy(branchpoints[6], "TATTAAC");
	strcpy(branchpoints[7], "TGCTAAC");
	strcpy(branchpoints[8], "GATTAAC");

	num = input_genes_in_gff(f, genes, exons);	
	if( num != num_genes ) {
		fatalf("gene counter error in %s\n", argv[1]);
	}

	if( num_genes > 0 ) {
		quick_sort_inc_genes(genes, 0, num_genes-1, POS_BASE);
	}

	i = 0;
	while( i < num_genes ) {
		j = 0;
    while( ((i+j) < num_genes) && (genes[i].txStart == genes[i+j].txStart )) j++;
    quick_sort_dec_genes(genes, i, i+j-1, LEN_BASE);
    i = i+j;
	}
	fclose(f);

	compl['a'] = compl['A'] = 'T';
	compl['c'] = compl['C'] = 'G';
	compl['g'] = compl['G'] = 'C';
	compl['t'] = compl['T'] = 'A';
	sf = seq_get(argv[1]);
	s = SEQ_CHARS(sf) - 1;
	seq_len = SEQ_LEN(sf);

	for( i = 0; i < num_genes; i++ ) {
		B = genes[i].txStart;
		E = genes[i].txEnd;
		if( E > seq_len ) {
			fatalf("gene boundary [%d,%d] over the sequence length %d\n", B, E, seq_len);
		}

		if( (E - B + 1) > max_len ) {
			max_len = E - B + 1;
		}
	}

	cur_seq = (char *) ckalloc(sizeof(char) * (max_len+1));
	for( i = 0; i < num_genes; i++ ) {
		if( genes[i].exonCount >= 2 ) {
			strcpy(chr_name, genes[i].sname);
			B = genes[i].txStart;
			E = genes[i].txEnd;
			dir = genes[i].strand;
			strcpy(info, genes[i].gname);	

			k = 0;
			if( dir == '+' ) {
				for (j = B; j <= E; j++) {
					cur_seq[k] = s[j];
					k++;
				}
				cur_seq[k] = '\0';
			}
			else {
				k = 0;
				for (j = E; j >= B; j--) {
					cur_seq[k] = compl[s[j]];
					k++;
				}
				cur_seq[k] = '\0';
			}

			is_correct_splicing = true;
			is_correct_splicing = check_introns(genes, i, exons, cur_seq, k);
			if( is_correct_splicing == false ) {
				if( no_branchpoint == false ) {
					genes[i].type = REDUN;
				}
			}
			else {
				if( no_branchpoint == true ) {
					genes[i].type = REDUN;
				}
			}
		}
	}

  num_genes = rm_redun_genes(genes, 0, num_genes-1);
  write_in_gff(genes, num_genes, exons, num_exons);
	
	free(cur_seq);
	for( i = 0; i < NUM_BP_SEQ; i++ ) free(branchpoints[i]);
	free(branchpoints);
	seq_close(sf);
	return EXIT_SUCCESS;
}
Beispiel #9
0
int driver (int t_num)
{
    int i, j;
#ifdef OUT_PERIOD
 outputLog("d0|");
#endif

    /* Actually, WaitTimes are needed... */
    while( activate_transaction ){
      switch(seq_get()){
      case 0:
#ifdef OUT_PERIOD
 outputLog("d1|");
#endif
	do_neword(t_num);
#ifdef OUT_PERIOD
 outputLog("d1e|");
#endif
	break;
      case 1:
#ifdef OUT_PERIOD
 outputLog("d2|");
#endif
	do_payment(t_num);
#ifdef OUT_PERIOD
 outputLog("d2e|");
#endif
	break;
      case 2:
#ifdef OUT_PERIOD
 outputLog("d3|");
#endif
	do_ordstat(t_num);
#ifdef OUT_PERIOD
 outputLog("d3e|");
#endif
	break;
      case 3:
#ifdef OUT_PERIOD
 outputLog("d4|");
#endif
	do_delivery(t_num);
#ifdef OUT_PERIOD
 outputLog("d4e|");
#endif
	break;
      case 4:
#ifdef OUT_PERIOD
 outputLog("d5|");
#endif
	do_slev(t_num);
#ifdef OUT_PERIOD
 outputLog("d5e|");
#endif
	break;
      default:
#ifdef OUT_PERIOD
 outputLog("d6|");
#endif
	printf("Error - Unknown sequence.\n");
      }

    }

    return(0);

}