int gehash_load(gehash_t * the_table, const char fname []) { int i, read_length; char magic_chars[8]; magic_chars[7]=0; the_table -> index_gap = 0; FILE * fp = f_subr_open(fname, "rb"); if (!fp) { SUBREADprintf ("Table file `%s' is not found.\n", fname); return 1; } fread(magic_chars,1,8,fp); if(memcmp(magic_chars, "2subindx",8)!=0) { print_in_box(80,0,0,""); print_in_box(80,0,0,"WARNING your reference index was built under an old version of subread"); print_in_box(80,0,0," package. Please rebuild the index for the reference genome."); print_in_box(80,0,0,""); } if(memcmp(magic_chars+1, "subindx",7)==0) { if('1'==magic_chars[0]) the_table -> version_number = SUBINDEX_VER1; else if('2'==magic_chars[0]) the_table -> version_number = SUBINDEX_VER2; else assert(0); if(SUBINDEX_VER2 == the_table -> version_number) { while(1) { short option_key, option_length; fread(&option_key, 2, 1, fp); if(!option_key) break; fread(&option_length, 2, 1, fp); if(option_key == SUBREAD_INDEX_OPTION_INDEX_GAP) fread(&(the_table -> index_gap),2,1,fp); else fseek(fp, option_length, SEEK_CUR); } assert(the_table -> index_gap); } else if(SUBINDEX_VER1 == the_table -> version_number) the_table -> index_gap = 3; the_table -> current_items = load_int64(fp); the_table -> buckets_number = load_int32(fp); the_table -> buckets = (struct gehash_bucket * )malloc(sizeof(struct gehash_bucket) * the_table -> buckets_number); if(!the_table -> buckets) { SUBREADputs(MESSAGE_OUT_OF_MEMORY); return 1; } for (i=0; i<the_table -> buckets_number; i++) { struct gehash_bucket * current_bucket = &(the_table -> buckets[i]); current_bucket -> current_items = load_int32(fp); current_bucket -> space_size = load_int32(fp); current_bucket -> space_size = current_bucket -> current_items; current_bucket -> new_item_keys = (short *) malloc ( sizeof(short) * current_bucket -> space_size); current_bucket -> item_values = (gehash_data_t *) malloc ( sizeof(gehash_data_t) * current_bucket -> space_size); if(!(current_bucket -> new_item_keys&¤t_bucket -> item_values)) { SUBREADputs(MESSAGE_OUT_OF_MEMORY); return 1; } if(current_bucket -> current_items > 0) { read_length = fread(current_bucket -> new_item_keys, sizeof(short), current_bucket -> current_items, fp); assert(read_length>0); read_length = fread(current_bucket -> item_values, sizeof(gehash_data_t), current_bucket -> current_items, fp); assert(read_length>0); } } read_length = fread(&(the_table -> is_small_table), sizeof(char), 1, fp); assert(read_length>0); fclose(fp); return 0; } else { fclose(fp); the_table -> index_gap = 3; fp = f_subr_open(fname, "rb"); the_table -> version_number = SUBINDEX_VER0; the_table -> current_items = load_int64(fp); the_table -> buckets_number = load_int32(fp); the_table -> buckets = (struct gehash_bucket * )malloc(sizeof(struct gehash_bucket) * the_table -> buckets_number); if(!the_table -> buckets) { SUBREADputs(MESSAGE_OUT_OF_MEMORY); return 1; } for (i=0; i<the_table -> buckets_number; i++) { struct gehash_bucket * current_bucket = &(the_table -> buckets[i]); current_bucket -> current_items = load_int32(fp); current_bucket -> space_size = load_int32(fp); current_bucket -> space_size = current_bucket -> current_items; current_bucket -> item_keys = (gehash_key_t *) malloc ( sizeof(gehash_key_t) * current_bucket -> space_size); current_bucket -> item_values = (gehash_data_t *) malloc ( sizeof(gehash_data_t) * current_bucket -> space_size); if(!(current_bucket -> item_keys&¤t_bucket -> item_values)) { SUBREADputs(MESSAGE_OUT_OF_MEMORY); return 1; } if(current_bucket -> current_items > 0) { read_length = fread(current_bucket -> item_keys, sizeof(gehash_key_t), current_bucket -> current_items, fp); assert(read_length>0); read_length = fread(current_bucket -> item_values, sizeof(gehash_data_t), current_bucket -> current_items, fp); assert(read_length>0); } } read_length = fread(&(the_table -> is_small_table), sizeof(char), 1, fp); assert(read_length>0); fclose(fp); return 0; } }
/*read the data contain in the file */ int32_t macsim_read(GenericReader_T* genreader,glu_item_t* item) { char data_var[LG_MAX_STRING_MACSIM]; uint32_t indice_data=0, rep=EOF, dimension=0; uint8_t continuer=1; TSP_sample_symbol_info_list_t ssi_list; ssi_list=*genreader->ssi_list; if(NULL!=genreader->handler->file) { /*TYPE_CHAR or TYPE_UCHAR is a string of LG_MAX_STRING_MACSIM length */ if( (TSP_TYPE_CHAR==ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].type) || (TSP_TYPE_UCHAR==ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].type) ) { item->size=ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].dimension; /*calculate the real dimension for the string symbol*/ dimension=ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].dimension/LG_MAX_STRING_MACSIM; } else { item->size=ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].dimension; dimension=ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].dimension; } item->size*=tsp_type_size[ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].type]; while( continuer && (indice_data<dimension)) { memset(data_var,'\0',LG_MAX_STRING_MACSIM); /*read one data of the file*/ rep=read_data_file(genreader->handler->file,data_var); if(EOF!=rep) { /*end of line*/ if(END_SAMPLE_SET==rep) { continuer=0; } /*load retrieve data in the raw value*/ switch(ssi_list.TSP_sample_symbol_info_list_t_val[item->provider_global_index].type) { case TSP_TYPE_DOUBLE : load_double(data_var,item->raw_value,indice_data); break; case TSP_TYPE_FLOAT : load_float(data_var,item->raw_value,indice_data); break; case TSP_TYPE_INT8 : load_int8(data_var,item->raw_value,indice_data); break; case TSP_TYPE_INT16: load_int16(data_var,item->raw_value,indice_data); break; case TSP_TYPE_INT32 : load_int32(data_var,item->raw_value,indice_data); break; case TSP_TYPE_INT64 : load_int64(data_var,item->raw_value,indice_data); break; case TSP_TYPE_UINT8: load_uint8(data_var,item->raw_value,indice_data); break; case TSP_TYPE_UINT16: load_uint16(data_var,item->raw_value,indice_data); break; case TSP_TYPE_UINT32: load_uint32(data_var,item->raw_value,indice_data); break; case TSP_TYPE_UINT64: load_uint64(data_var,item->raw_value,indice_data); break; case TSP_TYPE_CHAR: load_char(data_var,item->raw_value,indice_data); break; case TSP_TYPE_UCHAR: load_uchar(data_var,item->raw_value,indice_data); break; case TSP_TYPE_RAW: load_type_raw(data_var,item->raw_value,indice_data); break; default: break; } ++indice_data; } else { continuer=0; } } } return(rep); }