Exemplo n.º 1
0
void benchmark() {
    srand(time(NULL));
    char key[9], value[13];
    int i;

    printf("> Benchmarking dispertion with %d buckets and %d entry\n", DISPERS_BENCH_BUCKET, DISPERS_BENCH_ENTRY);
    hashtable defaultTable = init_hashtable(DISPERS_BENCH_BUCKET);
    hashtable idxTable = init_hashtable(DISPERS_BENCH_BUCKET);
    set_hfunc(&idxTable, &idx_hashfunction);

    for (i=0; i < DISPERS_BENCH_ENTRY; i++) {
        randomString(key, 9);
        randomString(value, 13);

/*
        printf("%s:%s\n", key, value);
*/

        put(&defaultTable, key, value);
        put(&idxTable, key, value);
    }

/*
    printf(":: Default hash function\n");
    displayHashTable(defaultTable);
    displayStats(get_stats(defaultTable));
    printf(":: Idx hash function\n");
    displayHashTable(defaultTable);
    displayStats(get_stats(idxTable));
*/

}
Exemplo n.º 2
0
exchange_t *declare_exchange(int *status,
			     vhost_t *vhost,
			     amqp_bytes_t name,
			     exchange_type_t *type,
			     amqp_boolean_t durable,
			     amqp_boolean_t auto_delete,
			     amqp_table_t arguments)
{
  exchange_t *x = internal_lookup_exchange(vhost, name);

  if (x == NULL) {
    x = malloc(sizeof(exchange_t));
    x->name = amqp_bytes_malloc_dup(name);
    x->type = type;
    x->type_data = NULL;
    x->durable = durable;
    x->auto_delete = auto_delete;
    x->arguments = AMQP_EMPTY_TABLE; /* TODO: copy arguments */
    init_hashtable(&x->fanout, 127, NULL, NULL);
    init_hashtable(&x->direct, 127, NULL, NULL);
    type->init(x);
    info("Exchange \"%.*s\" of type %.*s created",
	 name.len, name.bytes,
	 type->name.len, type->name.bytes);
    hashtable_put(&vhost->exchanges, name, x);
  }

  return x;
}
Exemplo n.º 3
0
void testSuite() {
    hashtable table = init_hashtable(7);
    printf(":: Table elems: %d\n", table->p);

    printf(":: Inserting elements in hashtable\n");

    put(&table, "toto", "hey");
    put(&table, "lablab", "monk");
    put(&table, "blabla", "plop");
    put(&table, "toto", "ho!");
    put(&table, "tops", "hahah");
    put(&table, "pots", "huhuh");

    displayHashTable(table);

    printf(":: Seeking for hello: %s\n", get(table, "hello"));
    printf(":: Seeking for toto: %s\n", get(table, "toto"));
    printf(":: Removing elem tops, toto and lablab\n");
    rmove(&table, "tops");
    rmove(&table, "toto");
    rmove(&table, "lablab");

    displayHashTable(table);

    printf(":: Changing hash function and adding two elems\n");
    hashtable table2 = init_hashtable(7);
    set_hfunc(&table2, &idx_hashfunction);
    put(&table2, "toto", "hey");
    put(&table2, "blabla", "plop");
    put(&table2, "lablab", "monk");

    displayHashTable(table2);

    printf(":: Fonction for first hashtable: %p\n", get_hfunc(table));
    printf(":: Fonction for second hashtable: %p\n", get_hfunc(table2));

    printf(":: Stats for first table\n");
    put(&table, "lablab", "monk");
    put(&table, "toto", "ho!");
    put(&table, "tops", "hahah");
    displayStats(get_stats(table));
    printf(":: Stats for second table\n");
    displayStats(get_stats(table2));

    printf(":: Rehash table with 11 buckets\n");
    set_hfunc(&table, &idx_hashfunction);
    rehash_table(&table, 11);
    displayHashTable(table);
}
Exemplo n.º 4
0
xsbBucket *search_bucket(Cell name,
			 xsbHashTable *table,
			 enum xsbHashSearchOp search_op)
{
  xsbBucket *bucket, *prev;

  if (! table->initted) init_hashtable(table);

  prev = NULL;
  bucket = get_top_bucket(table,table_hash(name,table->length));
  while (bucket && bucket->name) {
    if (bucket->name == name) {
      if (search_op == hashtable_delete) {
	if (!prev) {
	  /* if deleting a top bucket, copy the next bucket into the top one
	     and delete that next bucket. If no next, then just nullify name */
	  prev = bucket;
	  bucket=bucket->next;
	  if (bucket) {
	    /* use memcpy() because client bucket might have extra fields */
	    memcpy(prev, bucket, table->bucket_size);
	    free(bucket);
	  } else {
	    mark_bucket_free(prev,table->bucket_size);
	    xsb_dbgmsg((LOG_HASHTABLE,
		       "SEARCH_BUCKET: Destroying storage handle for %s\n",
		       string_val(name)));
	    xsb_dbgmsg((LOG_HASHTABLE, 
		       "SEARCH_BUCKET: Bucket nameptr is %p, next bucket %p\n",
		       prev->name, prev->next));
	  }
	} else {
	  /* Not top bucket: rearrange pointers & free space */
	  prev->next = bucket->next;
	  free(bucket);
	}
	return NULL;
      } else
	return bucket;
    }
    prev = bucket;
    bucket = bucket->next;
  }
  /* not found */
  if (search_op != hashtable_insert) return NULL;
  /* else create new bucket */
  /* calloc nullifies the allocated space; CLIENTS RELY ON THIS */
  if (!bucket) { /* i.e., it is not a top bucket */
    bucket = (xsbBucket *)calloc(1,table->bucket_size);
    if (!bucket)
      xsb_exit("Out of Memory: Can't allocate hash bucket");
    prev->next = bucket;
    /* NOTE: not necessary to nullify bucket->next because of calloc() */
  }
  bucket->name = name;
  return bucket;
}
Exemplo n.º 5
0
Arquivo: node.c Projeto: tonyg/hop
void init_node(cmsg_bytes_t container_name) {
  if (container_name.len == 0) {
    unsigned char buf[CMSG_UUID_BUF_SIZE];
    gen_uuid(buf);
    _container_name = cmsg_bytes_malloc_dup(CMSG_BYTES(CMSG_UUID_BUF_SIZE, buf));
  } else {
    _container_name = cmsg_bytes_malloc_dup(container_name);
  }
  info("Local container name is <<%.*s>>\n", _container_name.len, _container_name.bytes);

  init_hashtable(&node_class_table,
		 31,
		 NULL,
		 NULL);
  init_hashtable(&directory,
		 10007,
		 node_incref,
		 node_decref);
}
Exemplo n.º 6
0
int main(int argc, char **argv)
{
    list_node *hashtable[HASHTABLE_SIZE];
    init_hashtable(hashtable);

    // Determining the file size
    struct stat st;
    if(stat("names.txt", &st) == -1)
        return EXIT_FAILURE;

    // Reading all contents to memory
    char contents[st.st_size + 1];
    FILE *h = fopen("names.txt", "r");
    size_t n = fread(contents, sizeof(char), st.st_size, h);
    fclose(h);

    // Extracting names and inserting in hashtable
    int j;
    char aux[NAME_LENGTH+1];
    for(int i = 0; i < n; i++) {
        bzero(aux, NAME_LENGTH);

        j = 0;
        while(contents[i] != ',' && i < n) {
            if(contents[i] != '"')
                aux[j++] = contents[i];
            i++;
        }
        aux[j] = '\0';

        insert_name(hashtable, aux, strlen(aux));
    }

    // Reading names
    long total = 0;
    int pos = 1;
    list_node *aux_node;
    for(int i = 0; i < HASHTABLE_SIZE; i++) {
        if(hashtable[i] != NULL) {
            aux_node = hashtable[i];
            while(aux_node != NULL) {
                total += name_score(
                        aux_node->name, 
                        strlen(aux_node->name), 
                        pos++);
                aux_node = aux_node->next;
            }
        }
    }

    printf("%ld\n", total);

    return EXIT_SUCCESS;
}
Exemplo n.º 7
0
int main()
{
    Status status;
    char buff[100];

    // Setup configuration for validating alphabetic characters
    Hashtable *config = init_hashtable();
    config->add(config, "min_chars", "4");
    config->add(config, "max_chars", "10");

    // Instantiate the validation class with configuration and validation type
    IOValidate *v = init_validate(config, VALIDATE_ALPHA);

    /*
    // Setup configuration for validating alphanum characters with specific chars
    Hashtable *config = init_hashtable();
    config->add(config, "min_chars", "4");
    config->add(config, "max_chars", "10");
    config->add(config, "allowed_chars", "abcd");

    // Instantiate the validation class with configuration and validation type
    IOValidate *v = init_validate(config, VALIDATE_ALPHANUM);
    */

    /*
    // Setup configuration for validating numbers
    Hashtable *config = init_hashtable();
    config->add(config, "min_num", "10");
    config->add(config, "max_num", "1000");

    // Instantiate the validation class with configuration and validation type
    IOValidate *v = init_validate(config, VALIDATE_NUM);
    */

    // Get user input
    fgets(buff, sizeof(buff), stdin);

    // Test the user provided input with our validation
    if (v->isvalid(v, &status, buff)) {
        printf("Validated!\n");
    }
    else {
        printf("Status code: %d\n", status.code);
        printf("Status msg: %s\n", status.msg);
    }

    release(v);
    free_hashtable(config);

    return 0;
}
Exemplo n.º 8
0
int main(int argc, char *argv[])
{
	struct hash_functions funcs;
	struct hashtable table;

	INIT_HASH_FUNCTIONS(&funcs, init_hash_descriptor,
			    resize_hash_modulus, hash);

	init_hashtable(&table, &funcs, 1, 2);

	dealloc_hashtable(&table);

	

}
Exemplo n.º 9
0
//read kmer file, the first line of the kmer file contains the number of (distinct) kmers as kmer_index (Note the total number of kmers would be (2*kmer_index) including reverse complementary pairs)
//for a pair of reverse complementary kmers kmer1 and kmer2, if kmer1 < kmer2 (dictionary order) then (the index of kmer2) = (the index of kmer1) + kmer_index
int read_kmer_file(char * kmer_file, struct kmer_state ** kmer, int* hashtable, int kmerlength, int * kmer_index1){
	FILE * fr_kmer;
	int file_end_tag;
        int temp_kmer_index, kmer_index, temp_hash_index, i;
	char temp_char[1000];
        char line[Length];
	fr_kmer = fopen(kmer_file, "r");	
	if (fr_kmer != NULL){			
		file_end_tag = 1;
		init_hashtable(hashtable);
		fgets(line, Length, fr_kmer);
		sscanf(line, "%s %d", temp_char, &kmer_index);
	        (*kmer) = (struct kmer_state *) malloc((kmer_index*2+2)*sizeof(struct kmer_state));
                init_kmer((*kmer), kmer_index);
		temp_kmer_index = 1;
		while((file_end_tag!=0)){ // read the reads file
			line[0] = 'X';
			if (fgets(line, Length, fr_kmer) == NULL){
				file_end_tag = 0;
			};
			if (line[0] == 'X')
				file_end_tag = 0;
			if (file_end_tag != 0){
				sscanf(line, "%s %d", (*kmer)[temp_kmer_index].seq, &(*kmer)[temp_kmer_index].cov);
				(*kmer)[temp_kmer_index].seq[kmerlength] = '\0';
				temp_hash_index = get_hash_index((*kmer)[temp_kmer_index].seq);
				if (hashtable[temp_hash_index] == -1){
					hashtable[temp_hash_index] = temp_kmer_index;
				}
                                for (i=0;i<kmerlength;i++){
					if ((*kmer)[temp_kmer_index].seq[kmerlength-1-i] == 'A') (*kmer)[temp_kmer_index+kmer_index].seq[i] = 'T';
                                        if ((*kmer)[temp_kmer_index].seq[kmerlength-1-i] == 'T') (*kmer)[temp_kmer_index+kmer_index].seq[i] = 'A';
                                        if ((*kmer)[temp_kmer_index].seq[kmerlength-1-i] == 'C') (*kmer)[temp_kmer_index+kmer_index].seq[i] = 'G';
                                        if ((*kmer)[temp_kmer_index].seq[kmerlength-1-i] == 'G') (*kmer)[temp_kmer_index+kmer_index].seq[i] = 'C';
				}
                                (*kmer)[temp_kmer_index+kmer_index].seq[kmerlength] = '\0';
                                (*kmer)[temp_kmer_index+kmer_index].cov = (*kmer)[temp_kmer_index].cov;
				temp_kmer_index++;
				if (temp_kmer_index % 10000 == -1)
					printf("Kmer %d %s count %d\n", temp_kmer_index-1, (*kmer)[temp_kmer_index-1].seq, (*kmer)[temp_kmer_index-1].cov);
			}			
		}
		hashtable[1048576] = kmer_index-1;
		fclose(fr_kmer);
	}
	(*kmer_index1) = kmer_index;
}
Exemplo n.º 10
0
/*
 * Funzione di inizializzazione del superpeer.
 */
int init_superpeer(const struct sockaddr_in *sp_addr_list, int list_len) {
	int rc, ret = 0;

	is_sp = 0;
	nsock = 0;
	curr_p_count = 0;
	have_child = 0; 
	child_miss_pong = 0;
	curr_child_redirect = 0; 
	join_ov_try = 0;
	
	
	max_tcp_sock = MAX_TCP_SOCKET;
	if (near_str != NULL) {
		free(near_str);
	}
	near_str = (char *)malloc(max_tcp_sock * ADDR_STR_LEN);
	memset(near_str, 0, max_tcp_sock * ADDR_STR_LEN);
	//inizializzo socket di ascolto
	if (set_listen_socket(conf.udp_port) < 0) {
		fprintf(stderr, "init_superpeer error - set_listen_socket failed\n");
		return -1;
	}

	if ((rc = pthread_mutex_init(&NEAR_LIST_LOCK, NULL)) != 0) {
		fprintf(stderr, "init_superpeer error - can't initialize lock: %s\n", strerror(rc));
		return -1;
	}


	if (sp_addr_list != NULL) {
		//provo a connettermi agli altri superpeer
		if ((ret = join_overlay(sp_addr_list, list_len)) < 0) {
			fprintf(stderr, "init_superpeer error - join_overlay failed\n");
			return -1;
		} 
		myaddr.sin_port = conf.udp_port;
		printf("MIO INDIRIZZO: %s:%d\n", inet_ntoa(myaddr.sin_addr), ntohs(myaddr.sin_port));
	} 


	init_hashtable();	
	return ret;
	
}
Exemplo n.º 11
0
Arquivo: devfs.c Projeto: csko/yaosp
__init int init_devfs( void ) {
    int error;

    error = init_hashtable(
        &devfs_node_table, 256,
        devfs_node_key, hash_int64,
        compare_int64
    );

    if ( error < 0 ) {
        goto error1;
    }

    devfs_mutex = mutex_create( "devfs mutex", MUTEX_NONE );

    if ( devfs_mutex < 0 ) {
        error = devfs_mutex;
        goto error2;
    }

    error = register_filesystem( "devfs", &devfs_calls );

    if ( error < 0 ) {
        goto error3;
    }

    return 0;

 error3:
    mutex_destroy( devfs_mutex );

 error2:
    destroy_hashtable( &devfs_node_table );

 error1:
    return error;
}
Exemplo n.º 12
0
int main(int argc,char **argv) {
	INFO(char *dbg="Main(init): ");

	native_startup(argc, argv);

	/*** init modules ***/

	INFO(printf("%sSharedMemory\n",dbg));
	init_sharedmem(&dope);

	INFO(printf("%sTimer\n",dbg));
	init_timer(&dope);

	INFO(printf("%sTick\n",dbg));
	init_tick(&dope);

	INFO(printf("%sRelax\n",dbg));
	init_relax(&dope);

	INFO(printf("%sKeymap\n",dbg));
	init_keymap(&dope);

	INFO(printf("%sThread\n",dbg));
	init_thread(&dope);

	INFO(printf("%sCache\n",dbg));
	init_cache(&dope);

	INFO(printf("%sHashTable\n",dbg));
	init_hashtable(&dope);

	INFO(printf("%sApplication Manager\n",dbg));
	init_appman(&dope);

	INFO(printf("%sTokenizer\n",dbg));
	init_tokenizer(&dope);

	INFO(printf("%sMessenger\n",dbg));
	init_messenger(&dope);

	INFO(printf("%sScript\n",dbg));
	init_script(&dope);

	INFO(printf("%sClipping\n",dbg));
	init_clipping(&dope);

	INFO(printf("%sScreen Driver\n",dbg));
	init_scrdrv(&dope);

	INFO(printf("%sInput\n",dbg));
	init_input(&dope);

	INFO(printf("%sViewManager\n",dbg));
	init_viewman(&dope);

	INFO(printf("%sConvertFNT\n",dbg));
	init_conv_fnt(&dope);

	INFO(printf("%sFontManager\n",dbg));
	init_fontman(&dope);

	INFO(printf("%sGfxScreen16\n",dbg));
	init_gfxscr16(&dope);

	INFO(printf("%sGfxImage16\n",dbg));
	init_gfximg16(&dope);

	INFO(printf("%sGfxImage32\n",dbg));
	init_gfximg32(&dope);

	INFO(printf("%sGfxImageYUV420\n",dbg));
	init_gfximgyuv420(&dope);

	INFO(printf("%sGfx\n",dbg));
	init_gfx(&dope);

	INFO(printf("%sRedrawManager\n",dbg));
	init_redraw(&dope);

	INFO(printf("%sUserState\n",dbg));
	init_userstate(&dope);

	INFO(printf("%sWidgetManager\n",dbg));
	init_widman(&dope);

	INFO(printf("%sScope\n",dbg));
	init_scope(&dope);

	INFO(printf("%sButton\n",dbg));
	init_button(&dope);

	INFO(printf("%sEntry\n",dbg));
	init_entry(&dope);

	INFO(printf("%sVariable\n",dbg));
	init_variable(&dope);

	INFO(printf("%sLabel\n",dbg));
	init_label(&dope);

	INFO(printf("%sLoadDisplay\n",dbg));
	init_loaddisplay(&dope);

	INFO(printf("%sBackground\n",dbg));
	init_background(&dope);

	INFO(printf("%sScrollbar\n",dbg));
	init_scrollbar(&dope);

	INFO(printf("%sScale\n",dbg));
	init_scale(&dope);

	INFO(printf("%sFrame\n",dbg));
	init_frame(&dope);

	INFO(printf("%sContainer\n",dbg));
	init_container(&dope);

	INFO(printf("%sGrid\n",dbg));
	init_grid(&dope);

	INFO(printf("%sWinLayout\n",dbg));
	init_winlayout(&dope);

	INFO(printf("%sWindow\n",dbg));
	init_window(&dope);

	INFO(printf("%sScreen\n",dbg));
	init_screen(&dope);

	INFO(printf("%sScheduler\n",dbg));
	if (config_don_scheduler)
        {
	//	init_don_scheduler(&dope);
          printf("NOOOOOOOOOOOOOOOOOOO\n");
        }
	else
		init_simple_scheduler(&dope);

	INFO(printf("%sVScreenServer\n",dbg));
	init_vscr_server(&dope);

	INFO(printf("%sVScreen\n",dbg));
	init_vscreen(&dope);
	
	INFO(printf("%sVTextScreen\n",dbg));
	init_vtextscreen(&dope);

	INFO(printf("%sServer\n",dbg));
	init_server(&dope);

	INFO(printf("%screate screen\n",dbg));
	{
		static GFX_CONTAINER *scr_ds;
		gfx       = pool_get("Gfx 1.0");
		screen    = pool_get("Screen 1.0");
		userstate = pool_get("UserState 1.0");

		scr_ds = gfx->alloc_scr("default");
		curr_scr = screen->create();
		curr_scr->scr->set_gfx(curr_scr, scr_ds);
		userstate->set_max_mx(gfx->get_width(scr_ds));
		userstate->set_max_my(gfx->get_height(scr_ds));
	}
	
	INFO(printf("%sstarting server\n",dbg));
	if ((server = pool_get("Server 1.0")))
		server->start();
	
	INFO(printf("%sstarting scheduler\n",dbg));
	if ((sched  = pool_get("Scheduler 1.0")))
		sched->process_mainloop();

	return 0;
}
Exemplo n.º 13
0
Arquivo: node.c Projeto: tonyg/hop
static void init_node_names(node_t *n) {
  init_hashtable(&n->names, 5, NULL, NULL);
}
Exemplo n.º 14
0
int main (int argc, char** argv)
{
	char samfile[1024]; char bamfile[1024]; char variantfile[1024]; char fastafile[1024]; char maskfile[1024];
	strcpy(samfile,"None"); strcpy(bamfile,"None"); strcpy(variantfile,"None"); strcpy(fastafile,"None"); strcpy(maskfile,"None");
	GROUPNAME = NULL;
	int readsorted = 0;
	char* sampleid = (char*)malloc(1024); sampleid[0] = '-'; sampleid[1] = '\0';
	int samplecol=10; // default if there is a single sample in the VCF file
	int i=0,variants=0,hetvariants=0;
	char** bamfilelist = NULL; int bamfiles =0; 

	logfile = NULL; fragment_file = stdout; // write fragments to this file if it is present
	for (i=1;i<argc;i+=2)
	{
		if (strcmp(argv[i],"--bam") ==0 || strcmp(argv[i],"--bamfile") ==0)        bamfiles++; 
		else if (strcmp(argv[i],"--variants") ==0)        strcpy(variantfile,argv[i+1]);
		else if (strcmp(argv[i],"--reffile") ==0 || strcmp(argv[i],"--ref") ==0)        strcpy(fastafile,argv[i+1]);
		else if (strcmp(argv[i],"--mask") ==0 || strcmp(argv[i],"--mappability") ==0)        strcpy(maskfile,argv[i+1]);
		else if (strcmp(argv[i],"--VCF") ==0 || strcmp(argv[i],"--vcf") ==0)    {     strcpy(variantfile,argv[i+1]); VCFformat =1; }
		else if (strcmp(argv[i],"--sorted") ==0)       readsorted = atoi(argv[i+1]);
		else if (strcmp(argv[i],"--mbq") ==0)       MINQ = atoi(argv[i+1]);
		else if (strcmp(argv[i],"--mmq") ==0)       MIN_MQ = atoi(argv[i+1]);
		else if (strcmp(argv[i],"--maxIS") ==0)       MAX_IS = atoi(argv[i+1]);
		else if (strcmp(argv[i],"--minIS") ==0)       MIN_IS = atoi(argv[i+1]);
		else if (strcmp(argv[i],"--PEonly") ==0)       PEONLY = 1;  // discard single end mapped reads 
		else if (strcmp(argv[i],"--indels") ==0)       PARSEINDELS = atoi(argv[i+1]);  // allow indels in hairs
		else if (strcmp(argv[i],"--pflag") ==0)      IFLAG  = atoi(argv[i+1]);  // allow indels in hairs
		else if (strcmp(argv[i],"--qvoffset") ==0)       QVoffset = atoi(argv[i+1]);
		else if (strcmp(argv[i],"--out") == 0 || strcmp(argv[i],"-o") ==0) fragment_file = fopen(argv[i+1],"w");
		else if (strcmp(argv[i],"--logfile")==0 || strcmp(argv[i],"--log") ==0) logfile = fopen(argv[i+1],"w");  
		else if (strcmp(argv[i],"--singlereads")==0) SINGLEREADS = atoi(argv[i+1]);  
		else if (strcmp(argv[i],"--maxfragments")==0) MAXFRAG = atoi(argv[i+1]);  
		else if (strcmp(argv[i],"--noquality")==0) MISSING_QV = atoi(argv[i+1]);  
		else if (strcmp(argv[i],"--triallelic")==0) TRI_ALLELIC = atoi(argv[i+1]);  
		//else if (strcmp(argv[i],"--fosmids") == 0 || strcmp(argv[i],"--fosmid") ==0) FOSMIDS = 1;
		//else if (strcmp(argv[i],"--prior") == 0) PRIOR = atoi(argv[i+1]); 
		//else if (strcmp(argv[i],"--comparephase") == 0 || strcmp(argv[i],"--compare") ==0) COMPARE_PHASE = atoi(argv[i+1]); 
		else if (strcmp(argv[i],"--groupname") == 0) 
		{
			GROUPNAME = (char*)malloc(1024); strcpy(GROUPNAME,argv[i+1]); 
		}
	}
	if (bamfiles > 0 && strcmp(variantfile,"None") !=0)
	{
		bamfilelist = (char**)malloc(sizeof(char*)*bamfiles); 
		for (i=0;i<bamfiles;i++) bamfilelist[i] = (char*)malloc(1024);
		bamfiles=0;
		for (i=1;i<argc;i+=2)
		{
			if (strcmp(argv[i],"--bam") ==0 || strcmp(argv[i],"--bamfile") ==0)     strcpy(bamfilelist[bamfiles++],argv[i+1]);
		}
		fprintf(stderr,"\n extracting haplotype informative reads from bamfiles %s minQV %d minMQ %d maxIS %d \n\n",bamfilelist[0],MINQ,MIN_MQ,MAX_IS);
	}
	else
	{
		print_options(); return -1;
	}

	HASHTABLE ht; ht.htsize = 7919;  init_hashtable(&ht);
	VARIANT* varlist;
	int chromosomes=0;

	if (VCFformat ==1)
	{
		variants = count_variants(variantfile,sampleid,&samplecol); 
		if (variants < 0) return -1; 
		varlist = (VARIANT*)malloc(sizeof(VARIANT)*variants);
		chromosomes = read_variantfile(variantfile,varlist,&ht,&hetvariants,samplecol); 
	}
	else
	{
		variants = count_variants_oldformat(variantfile);
		if (variants < 0) return -1; 
		varlist = (VARIANT*)malloc(sizeof(VARIANT)*variants);
		chromosomes = read_variantfile_oldformat(variantfile,varlist,&ht,variants);
	}
	// variants is set to hetvariants only, but this is not correct since 
	VARIANTS = variants;  
	// there are two options, we include all variants in the chromvars datastructure but only use heterozygous variants for outputting HAIRS 
	// variant-id should correspond to line-number in VCF file since that will be used for printing out variants in Hapcut 

	//	fprintf(stderr,"read %d variants from file %s chromosomes %d\n",snps,argv[1],chromosomes);
	CHROMVARS* chromvars  = (CHROMVARS*)malloc(sizeof(CHROMVARS)*chromosomes);
	build_intervalmap(chromvars,chromosomes,varlist,VARIANTS);

	// read reference fasta file for INDELS, currently reads entire genome in one go, need to modify to read chromosome by chromosome 
	REFLIST* reflist = (REFLIST*)malloc(sizeof(REFLIST)); 
	reflist->ns = 0; reflist->names = NULL; reflist->lengths = NULL; reflist->sequences = NULL; reflist->current = -1;
	if (strcmp(fastafile,"None") != 0)
	{
		if (read_fastaheader(fastafile,reflist) > 0) 
		{
			reflist->sequences = calloc(reflist->ns,sizeof(char*)); //(char**)malloc(sizeof(char*)*reflist->ns);
			if (FOSMIDS ==0)
			{
				for (i=0;i<reflist->ns;i++)
				{
					reflist->sequences[i] = calloc(reflist->lengths[i]+1,sizeof(char));
					if (i < 5) fprintf(stderr,"contig %s length %d\n",reflist->names[i],reflist->lengths[i]);
				}
				read_fasta(fastafile,reflist);
			}
			else // 10.27.14 new code to read one chromosome at a time 
			{
				fprintf(stderr,"opening fasta file %s \n",fastafile);
				reflist->fp = fopen(fastafile,"r");
			}
		}
	}
	//return 1;
	if (readsorted ==0 && bamfiles > 0)
	{
		for (i=0;i<bamfiles;i++) 
		{
			if (FOSMIDS ==0) parse_bamfile_sorted(bamfilelist[i],&ht,chromvars,varlist,reflist);
			//else parse_bamfile_fosmid(bamfilelist[i],&ht,chromvars,varlist,reflist,maskfile); // fosmid pool bam file 
		}
	}
	if (logfile != NULL) fclose(logfile);
	if (fragment_file != NULL && fragment_file != stdout) fclose(fragment_file);


	// need to free up all memory before we exit the program 
	/*
	int xor = pow(2,16)-1;
	for (i=0;i<variants;i++)
	{
		//if (varlist[i].type ==0) continue;
		if (varlist[i].genotype[0] == varlist[i].genotype[2]) continue;
		fprintf(stdout,"variant %d %s %d %d %s %s %d:%d %d:%d \n",i+1,varlist[i].genotype,varlist[i].position-1,varlist[i].type,varlist[i].RA,varlist[i].AA,varlist[i].A1>>16,varlist[i].A1 & xor,varlist[i].A2>>16,varlist[i].A2 & xor);
	}
	*/
	return 0;
}
Exemplo n.º 15
0
int init_cgi_local()
{
	init_hashtable();

	return  load_funSet_from_web();
}
Exemplo n.º 16
0
void init_exchange(void) {
  init_hashtable(&all_exchange_types, 53, NULL, NULL);
  init_exchange_direct();
  init_exchange_fanout();
  init_exchange_topic();
}