/*********************************************************************** * Read an array of unknown length from a file. * Caller is resposbile for freeing array. ***********************************************************************/ ARRAY_T *read_array_from_file(const char* filename) { int array_size = 100; int i_item = 0; int num_read = 0; ATYPE value; FILE *array_file = fopen(filename, "r"); if (array_file == NULL) { die( "Unable to open file: %s.\nError message: %s.\n", filename, strerror(errno) ); } ARRAY_T *array = allocate_array(array_size); while ((num_read = fscanf(array_file, ASCAN, &value)) == 1) { set_array_item(i_item, value, array); ++i_item; if (i_item >= array_size) { resize_array(array, 2 * array_size); array_size = 2 *array_size; } } if (num_read == 0) { die("Error reading array at position %d.\n", i_item); } fclose(array_file); resize_array(array, i_item); return array; }
int darray_insert(darray_t *arr, void *element) { if (!resize_array(arr)) { return 0; } arr->data[arr->size++] = element; return 1; }
void handle_getdir(struct request *req){ int val = req->ret; if(val>MAX_ARRAY_SIZE) val = MAX_ARRAY_SIZE; array_t *ret = allocate_empty_array(val); int i=0; if(val > 0) { struct linux_dirent *de = (struct linux_dirent *)req->buf; for(i=0; i<MAX_ARRAY_SIZE && ((char *)de) - (char *)(req->buf) < val; i++) { svalue_t *vp = &(ret->item[i]); vp->type = T_STRING; vp->subtype = STRING_MALLOC; vp->u.string = string_copy(de->d_name, "encode_stat"); de = (struct linux_dirent *)(((char *)de) + de->d_reclen); } } ret = resize_array(ret, i); ret->size = i; push_refed_array(ret); FREE((void *)req->buf); set_eval(max_cost); safe_call_efun_callback(req->fun, 1); }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sasio::Files:: read_dcd_step(FILE *dcd_infile, int &frame, int &natoms, int &reverseEndian) { int charmm = 0 ; int num_fixed = 0 ; int result ; std::vector<float> vector_x(natoms) ; std::vector<float> vector_y(natoms) ; std::vector<float> vector_z(natoms) ; result = read_dcdstep(dcd_infile,natoms,&vector_x[0],&vector_y[0],&vector_z[0],num_fixed,frame,reverseEndian,charmm) ; if(_x().cols() < frame) { std::cout << "resizing array: cols() = " << _x().cols() << " frame = " << frame << std::endl ; resize_array() ; } for(int i = 0 ; i < _natoms() ; ++i) { _x()(i,frame) = vector_x[i] ; _y()(i,frame) = vector_y[i] ; _z()(i,frame) = vector_z[i] ; } _number_of_frames()++ ; return ; }
BOOLEAN_T dxml_get_bg(void *data, ARRAY_T **bg) { DXML_T *parser; parser = (DXML_T*)data; if (parser->data->fscope.background == NULL) return FALSE; *bg = resize_array(*bg, get_array_length(parser->data->fscope.background)); copy_array(parser->data->fscope.background, *bg); return TRUE; }
/** * Tests the character array with multiple elements. */ void test_character_array_multiple_elements() { fputs("Test character array multiple elements:\n", stdout); // The destination array. void* d = NULL_POINTER; int ds = 22; // Create destination array. create_array((void*) &d, (void*) &ds, (void*) CHARACTER_ARRAY); // The source array. char a[] = {'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 't', 'e', 's', 't', '.', '\n', '\0'}; char* s = a; int ssa[] = {17}; int* ss = ssa; // The destination index to which to copy the source array. set_character_array_elements(d, (void*) ZERO_NUMBER, (void*) s, (void*) ss); fputs((char*) d, stdout); // The source array for overwriting. char oa[] = {'o', 'v', 'e', 'r', 'w', 'r', 'i', 't', 't', 'e', 'n', '.', '\n', '\0'}; char* os = oa; int ossa[] = {14}; int* oss = ossa; set_character_array_elements(d, (void*) EIGHT_NUMBER, (void*) os, (void*) oss); fputs((char*) d, stdout); // The remove index. int ri = 12; remove_character_array_elements(d, (void*) &ds, (void*) &ri, (void*) SEVEN_NUMBER); fputs((char*) d, stdout); // The new array size to cut off remaining elements, // including two places for new line '\n' and c string termination '\0'. int ns = 15; resize_array((void*) &d, (void*) &ns, (void*) CHARACTER_ARRAY); fputs((char*) d, stdout); // The result array. void* r = NULL_POINTER; // Test getting a reference. get_character_array_elements(d, (void*) EIGHT_NUMBER, (void*) &r); fputs((char*) r, stdout); // Destroy destination array. destroy_array((void*) &d, (void*) &ns, (void*) CHARACTER_ARRAY); }
/** * Receives an inline stream and writes it into a byte array. * * @param p0 the destination (byte array) (Hand over as reference!) * @param p1 the destination count * @param p2 the destination size * @param p3 the source (inline data) * @param p4 the source count */ void receive_inline(void* p0, void* p1, void* p2, const void* p3, const void* p4) { if (p4 != NULL_POINTER) { int* sc = (int*) p4; if (p2 != NULL_POINTER) { int* ds = (int*) p2; if (p1 != NULL_POINTER) { int* dc = (int*) p1; if (p0 != NULL_POINTER) { void** d = (void**) p0; // Set new array size. *ds = *sc; // Resize array. resize_array(p0, p2, (void*) CHARACTER_ARRAY); // The destination array index to start writing at. int i = 0; set_array_elements(*d, (void*) &i, p3, p4, (void*) CHARACTER_ARRAY); // Set new array count. *dc = *sc; } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read inline. The array count is null."); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read inline. The array count is null."); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read inline. The array size is null."); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read inline. The inline byte stream count is null."); } }
static void push_token( const char * from, int start, int end ) { struct array *a = Pike_sp[-1].u.array; struct pike_string *token = make_shared_binary_string(from+start, end-start+1); if( a->malloced_size < a->size+1 ) { Pike_sp[-1].u.array = a = resize_array( a, a->size+1 ); a->size--; } a->item[a->size].type = PIKE_T_STRING; a->item[a->size].subtype = 0; a->item[a->size].u.string = token; a->size++; }
//returns last character in array wchar_t pop_dyn_array(DynArray *a) { LIBPREFIX_ASSERT(a->type != UNINITIALIZED, ARR_NOT_INIT); LIBPREFIX_ASSERT(a->total > 0, INSUFFICIENT_TOTAL); int size = a->size; a->total = a->total-1; wchar_t to_return = *((wchar_t **) a->array)[a->total]; while (size / 2 >= a->total && size > MIN_SIZE){ size /= 2; } resize_array(a, size); return to_return; }
int darray_insert_distinct(darray_t *arr, void *element, EQ_COMPARITOR) { //Check if it's already in existance for (int i = 0; i < arr->size; i++) { if (equality_comparitor(element, arr->data[i])) { return 0; } } if (!resize_array(arr)) { return 0; } //Insert item arr->data[arr->size++] = element; return 1; }
Node *pop_dyn_array_node(DynArray *a) { LIBPREFIX_ASSERT(a->type != UNINITIALIZED, ARR_NOT_INIT, NULL); LIBPREFIX_ASSERT(a->total > 0, INSUFFICIENT_TOTAL, NULL); int size = a->size; a->total = a->total-1; Node *to_return = a->array[a->total]; while (size / 2 >= a->total && size > MIN_SIZE){ size /= 2; } resize_array(a, size); return to_return; }
/************************************************************************ * Compute the indices and values of transitions to or from a state. ************************************************************************/ void compute_ins_and_outs (MHMM_T* the_hmm, BOOLEAN_T log_form) /* Is the transition matrix in log form? */ { int i_row, i_col; int n = the_hmm->num_states; MATRIX_T *trans = the_hmm->trans; // // Visit the transition matrix cells just once each // to update ntrans, itrans and trans arrays. // This is quadratic in n. // for (i_row = 0; i_row < n; i_row++) { for (i_col = 0; i_col < n; i_col++) { double p; // The transition probability. int old_n, new_n; // Number of transitions. if (!is_zero((p = get_matrix_cell(i_row, i_col, trans)), log_form)) { MHMM_STATE_T * out_state = &(the_hmm->states[i_row]); MHMM_STATE_T * in_state = &(the_hmm->states[i_col]); // out old_n = out_state->ntrans_out; new_n = ++out_state->ntrans_out; mm_resize(out_state->itrans_out, new_n, int); out_state->trans_out = resize_array(out_state->trans_out, new_n); out_state->itrans_out[old_n] = i_col; set_array_item(old_n, p, out_state->trans_out); // in old_n = in_state->ntrans_in; new_n = ++in_state->ntrans_in; mm_resize(in_state->itrans_in, new_n, int); in_state->trans_in = resize_array(in_state->trans_in, new_n); in_state->itrans_in[old_n] = i_row; set_array_item(old_n, p, in_state->trans_in); } } // col } // row
/** * Tests the character array with multiple elements. */ void test_character_array_multiple_elements() { // The destination array. void* d = NULL_POINTER; int ds = 20; create_array((void*) &d, (void*) &CHARACTER_ARRAY, (void*) &ds); // The constant source array and the pointer to it. char a[] = {'T', 'h', 'i', 's', ' ', 'i', 's', ' ', 'a', ' ', 't', 'e', 's', 't', '.', '\n', '\0'}; char* s = a; int ss = 17; // The destination index to which to copy the source array. int i = 0; set_array_elements((void*) &d, (void*) &CHARACTER_ARRAY, (void*) &i, (void*) &s, (void*) &ss); fputs((char*) d, stdout); // The constant source array for overwriting and the pointer to it. char oa[] = {'o', 'v', 'e', 'r', 'w', 'r', 'i', 't', 't', 'e', 'n', '.', '\n', '\0'}; char* os = oa; int oss = 14; // The destination index to which to copy the source array for overwriting. int oi = 8; set_array_elements((void*) &d, (void*) &CHARACTER_ARRAY, (void*) &oi, (void*) &os, (void*) &oss); fputs((char*) d, stdout); // The remove index. int ri = 12; // The remove count. int rc = 7; remove_array_elements((void*) &d, (void*) &CHARACTER_ARRAY, (void*) &ds, (void*) &ri, (void*) &rc); fputs((char*) d, stdout); // The new array size to cut off remaining elements, // including two places for new line '\n' and c string termination '\0'. int ns = 15; resize_array((void*) &d, (void*) &CHARACTER_ARRAY, (void*) &ns); fputs((char*) d, stdout); destroy_array((void*) &d, (void*) &CHARACTER_ARRAY, (void*) &ns); }
/* * When the parser has been selected do some processing */ static void parser_selected(MREAD_T *mread) { ALPH_T alph; MFORMAT_T* format; format = mread->formats; // get the alphabet alph = format->get_alphabet(mread->formats->data); // get the background if (format->get_bg(format->data, &(mread->motif_bg))) { normalize_subarray(0, alph_size(alph, ALPH_SIZE), 0.0, mread->motif_bg); resize_array(mread->motif_bg, alph_size(alph, ALL_SIZE)); calc_ambigs(alph, FALSE, mread->motif_bg); } else { mread->motif_bg = get_uniform_frequencies(alph, mread->motif_bg); } set_pseudo_bg(mread); }
static guint32 get_type_idx (MonoProfiler *p, MonoClass* klass) { guint32 idx_plus_one; if (!(idx_plus_one = GPOINTER_TO_UINT (g_hash_table_lookup (p->klass_to_table_idx, klass)))) { char* name = mono_type_get_name_full (mono_class_get_type (klass)); g_ptr_array_add (p->klass_table, name); idx_plus_one = p->klass_table->len; g_hash_table_insert (p->klass_to_table_idx, klass, idx_plus_one); if (idx_plus_one > p->type_live_data_size) resize_array (p->type_live_data, p->type_live_data_size, MAX (p->type_live_data_size << 1, idx_plus_one)); } return idx_plus_one - 1; }
static void get_rpts(void) { SaHpiEntryIdT rptentryid, nextrptentryid; SaErrorT rv; SaHpiRptEntryT rptentry; int n; rptentryid = SAHPI_FIRST_ENTRY; while (rptentryid != SAHPI_LAST_ENTRY) { rv = saHpiRptEntryGet(sessionid, rptentryid, &nextrptentryid, &rptentry); if (rv != SA_OK) break; n = nrpts; Rpts = (Rpt_t *)resize_array(Rpts, sizeof(Rpt_t), &nrpts, 1); rptentry.ResourceTag.Data[rptentry.ResourceTag.DataLength] = 0; Rpts[n].Rpt = rptentry; rptentryid = nextrptentryid; } }
int main(){ printf("Hello World!\n"); int first = 5; struct Arraylist arraylist; arraylist.type_size = sizeof(int); new_array(&arraylist); *((int*)arraylist.ptr) = first; printf("Val : %d", *((int*)arraylist.ptr)); arraylist.count = 2; resize_array(&arraylist); *(((int*)arraylist.ptr)+1) = 6; printf("Val : %d", *((int*)arraylist.ptr+1)); destroy(&arraylist); check_arrs(); return 0; }
/** * Reads inline. * * @param p0 the array * @param p1 the array count * @param p2 the array size * @param p3 the inline byte stream * @param p4 the inline byte stream count */ void read_inline(void* p0, void* p1, void* p2, const void* p3, const void* p4) { if (p4 != NULL_POINTER) { int* ic = (int*) p4; if (p2 != NULL_POINTER) { int* as = (int*) p2; if (p1 != NULL_POINTER) { int* ac = (int*) p1; // Set new array size. *as = *ic; // Resize array. resize_array(p0, (void*) &CHARACTER_ARRAY, p2); // The array index to start writing at. int i = 0; set_array_elements(p0, (void*) &CHARACTER_ARRAY, (void*) &i, p3, p4); // Set new array count. *ac = *ic; } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read inline. The array count is null."); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read inline. The array size is null."); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read inline. The inline byte stream count is null."); } }
static void get_rdrs(Rpt_t *Rpt) { SaHpiRdrT rdr; SaErrorT rv; int n; SaHpiEntryIdT entryid; SaHpiEntryIdT nextentryid; SaHpiResourceIdT resourceid; entryid = SAHPI_FIRST_ENTRY; while (entryid !=SAHPI_LAST_ENTRY) { resourceid = Rpt->Rpt.ResourceId; rv = saHpiRdrGet(sessionid, resourceid, entryid, &nextentryid, &rdr); if (rv != SA_OK) break; n = Rpt->nrdrs; Rpt->rdrs = (Rdr_t *)resize_array(Rpt->rdrs, sizeof(Rdr_t), &(Rpt->nrdrs), 1); rdr.IdString.Data[rdr.IdString.DataLength] = 0; Rpt->rdrs[n].Rdr = rdr; entryid = nextentryid; } }
qint64 QUsbHid::writeData(const QByteArray& in_data) { //QByteArray buffer(hidCaps.OutputReportByteLength,0); //memcpy(buffer.data(), in_data.data(), buffer.length()>in_data.length() ? in_data.length(): buffer.length()); QByteArray data = resize_array(in_data, hidCaps.outputReportLength + 1); QMutexLocker lock( mutex ); int retVal = 0; if(handle){ int actLen = 0; int timeout = DEF_TIMEOUT; uint8_t* p = (uint8_t *)data.data(); if(*p == 0){ // report ID is 0, ignore it p++; } int errorCode = libusb_interrupt_transfer(handle, epForWrite, p, hidCaps.outputReportLength, &actLen, timeout); lastErr = errorCode; if(errorCode < 0) retVal = 0; else retVal = actLen; //qDebug()<<formatError(lastErr); } return (qint64)retVal; }
/* {{{1 * Push ‘data’ on the priority queue. */ void priority_queue_push(PriorityQueue *q, pointer data) { invariant(q != null); /* first, resize to fit this element as well, if necessary */ if (q->len > q->size) { q->size *= 2; q->heap = resize_array(q->heap, pointer, q->size + 1); } /* increase the number of elements in queue and add it */ q->heap[++q->len] = data; /* then sift it upwards while it's smaller than its parents */ for (size_t i = q->len, p; i > 1 && q->compare(q->heap[p = i / 2], q->heap[i]) > 0; i = p) { pointer tmp = q->heap[p]; q->heap[p] = q->heap[i]; q->heap[i] = tmp; } }
extern "C" __declspec(dllexport) int d_resize_array(const MKL_INT length, double*& x) { return resize_array(length, x); }
/************************************************************************* * Entry point for pmp_bf *************************************************************************/ int main(int argc, char *argv[]) { char* bg_filename = NULL; char* motif_name = "motif"; // Use this motif name in the output. STRING_LIST_T* selected_motifs = NULL; double fg_rate = 1.0; double bg_rate = 1.0; double purine_pyrimidine = 1.0; // r double transition_transversion = 0.5; // R double pseudocount = 0.1; GAP_SUPPORT_T gap_support = SKIP_GAPS; MODEL_TYPE_T model_type = F81_MODEL; BOOLEAN_T use_halpern_bruno = FALSE; char* ustar_label = NULL; // TLB; create uniform star tree int i; program_name = "pmp_bf"; /********************************************** * COMMAND LINE PROCESSING **********************************************/ // Define command line options. (FIXME: Repeated code) // FIXME: Note that if you add or remove options you // must change n_options. int n_options = 12; cmdoption const pmp_options[] = { {"hb", NO_VALUE}, {"ustar", REQUIRED_VALUE}, {"model", REQUIRED_VALUE}, {"pur-pyr", REQUIRED_VALUE}, {"transition-transversion", REQUIRED_VALUE}, {"bg", REQUIRED_VALUE}, {"fg", REQUIRED_VALUE}, {"motif", REQUIRED_VALUE}, {"motif-name", REQUIRED_VALUE}, {"bgfile", REQUIRED_VALUE}, {"pseudocount", REQUIRED_VALUE}, {"verbosity", REQUIRED_VALUE} }; int option_index = 0; // Define the usage message. char usage[1000] = ""; strcat(usage, "USAGE: pmp [options] <tree file> <MEME file>\n"); strcat(usage, "\n"); strcat(usage, " Options:\n"); // Evolutionary model parameters. strcat(usage, " --hb\n"); strcat(usage, " --model single|average|jc|k2|f81|f84|hky|tn"); strcat(usage, " (default=f81)\n"); strcat(usage, " --pur-pyr <float> (default=1.0)\n"); strcat(usage, " --transition-transversion <float> (default=0.5)\n"); strcat(usage, " --bg <float> (default=1.0)\n"); strcat(usage, " --fg <float> (default=1.0)\n"); // Motif parameters. strcat(usage, " --motif <id> (default=all)\n"); strcat(usage, " --motif-name <string> (default from motif file)\n"); // Miscellaneous parameters strcat(usage, " --bgfile <background> (default from motif file)\n"); strcat(usage, " --pseudocount <float> (default=0.1)\n"); strcat(usage, " --ustar <label>\n"); // TLB; create uniform star tree strcat(usage, " --verbosity [1|2|3|4] (default 2)\n"); strcat(usage, "\n Prints the FP and FN rate at each of 10000 score values.\n"); strcat(usage, "\n Output format: [<motif_id> score <score> FPR <fpr> TPR <tpr>]+\n"); // Parse the command line. if (simple_setopt(argc, argv, n_options, pmp_options) != NO_ERROR) { die("Error processing command line options: option name too long.\n"); } while (TRUE) { int c = 0; char* option_name = NULL; char* option_value = NULL; const char * message = NULL; // Read the next option, and break if we're done. c = simple_getopt(&option_name, &option_value, &option_index); if (c == 0) { break; } else if (c < 0) { (void) simple_getopterror(&message); die("Error processing command line options (%s)\n", message); } if (strcmp(option_name, "model") == 0) { if (strcmp(option_value, "jc") == 0) { model_type = JC_MODEL; } else if (strcmp(option_value, "k2") == 0) { model_type = K2_MODEL; } else if (strcmp(option_value, "f81") == 0) { model_type = F81_MODEL; } else if (strcmp(option_value, "f84") == 0) { model_type = F84_MODEL; } else if (strcmp(option_value, "hky") == 0) { model_type = HKY_MODEL; } else if (strcmp(option_value, "tn") == 0) { model_type = TAMURA_NEI_MODEL; } else if (strcmp(option_value, "single") == 0) { model_type = SINGLE_MODEL; } else if (strcmp(option_value, "average") == 0) { model_type = AVERAGE_MODEL; } else { die("Unknown model: %s\n", option_value); } } else if (strcmp(option_name, "hb") == 0){ use_halpern_bruno = TRUE; } else if (strcmp(option_name, "ustar") == 0){ // TLB; create uniform star tree ustar_label = option_value; } else if (strcmp(option_name, "pur-pyr") == 0){ purine_pyrimidine = atof(option_value); } else if (strcmp(option_name, "transition-transversion") == 0){ transition_transversion = atof(option_value); } else if (strcmp(option_name, "bg") == 0){ bg_rate = atof(option_value); } else if (strcmp(option_name, "fg") == 0){ fg_rate = atof(option_value); } else if (strcmp(option_name, "motif") == 0){ if (selected_motifs == NULL) { selected_motifs = new_string_list(); } add_string(option_value, selected_motifs); } else if (strcmp(option_name, "motif-name") == 0){ motif_name = option_value; } else if (strcmp(option_name, "bgfile") == 0){ bg_filename = option_value; } else if (strcmp(option_name, "pseudocount") == 0){ pseudocount = atof(option_value); } else if (strcmp(option_name, "verbosity") == 0){ verbosity = atoi(option_value); } } // Must have tree and motif file names if (argc != option_index + 2) { fprintf(stderr, "%s", usage); exit(EXIT_FAILURE); } /********************************************** * Read the phylogenetic tree. **********************************************/ char* tree_filename = NULL; TREE_T* tree = NULL; tree_filename = argv[option_index]; option_index++; tree = read_tree_from_file(tree_filename); // get the species names STRING_LIST_T* alignment_species = make_leaf_list(tree); char *root_label = get_label(tree); // in case target in center if (strlen(root_label)>0) add_string(root_label, alignment_species); //write_string_list(" ", alignment_species, stderr); // TLB; Convert the tree to a uniform star tree with // the target sequence at its center. if (ustar_label != NULL) { tree = convert_to_uniform_star_tree(tree, ustar_label); if (tree == NULL) die("Tree or alignment missing target %s\n", ustar_label); if (verbosity >= NORMAL_VERBOSE) { fprintf(stderr, "Target %s placed at center of uniform (d=%.3f) star tree:\n", ustar_label, get_total_length(tree) / get_num_children(tree) ); write_tree(tree, stderr); } } /********************************************** * Read the motifs. **********************************************/ char* meme_filename = argv[option_index]; option_index++; int num_motifs = 0; MREAD_T *mread; ALPH_T alph; ARRAYLST_T *motifs; ARRAY_T *bg_freqs; mread = mread_create(meme_filename, OPEN_MFILE); mread_set_bg_source(mread, bg_filename); mread_set_pseudocount(mread, pseudocount); // read motifs motifs = mread_load(mread, NULL); alph = mread_get_alphabet(mread); bg_freqs = mread_get_background(mread); // check if (arraylst_size(motifs) == 0) die("No motifs in %s.", meme_filename); // TLB; need to resize bg_freqs array to ALPH_SIZE items // or copy array breaks in HB mode. This throws away // the freqs for the ambiguous characters; int asize = alph_size(alph, ALPH_SIZE); resize_array(bg_freqs, asize); /************************************************************** * Compute probability distributions for each of the selected motifs. **************************************************************/ int motif_index; for (motif_index = 0; motif_index < arraylst_size(motifs); motif_index++) { MOTIF_T* motif = (MOTIF_T*)arraylst_get(motif_index, motifs); char* motif_id = get_motif_id(motif); char* bare_motif_id = motif_id; // We may have specified on the command line that // only certain motifs were to be used. if (selected_motifs != NULL) { if (*bare_motif_id == '+' || *bare_motif_id == '-') { // The selected motif id won't included a strand indicator. bare_motif_id++; } if (have_string(bare_motif_id, selected_motifs) == FALSE) { continue; } } if (verbosity >= NORMAL_VERBOSE) { fprintf( stderr, "Using motif %s of width %d.\n", motif_id, get_motif_length(motif) ); } // Build an array of evolutionary models for each position in the motif. EVOMODEL_T** models = make_motif_models( motif, bg_freqs, model_type, fg_rate, bg_rate, purine_pyrimidine, transition_transversion, use_halpern_bruno ); // Get the frequencies under the background model (row 0) // and position-dependent scores (rows 1..w) // for each possible alignment column. MATRIX_T* pssm_matrix = build_alignment_pssm_matrix( alph, alignment_species, get_motif_length(motif) + 1, models, tree, gap_support ); ARRAY_T* alignment_col_freqs = allocate_array(get_num_cols(pssm_matrix)); copy_array(get_matrix_row(0, pssm_matrix), alignment_col_freqs); remove_matrix_row(0, pssm_matrix); // throw away first row //print_col_frequencies(alph, alignment_col_freqs); // // Get the position-dependent null model alignment column frequencies // int w = get_motif_length(motif); int ncols = get_num_cols(pssm_matrix); MATRIX_T* pos_dep_bkg = allocate_matrix(w, ncols); for (i=0; i<w; i++) { // get the evo model corresponding to this column of the motif // and store it as the first evolutionary model. myfree(models[0]); // Use motif PSFM for equilibrium freqs. for model. ARRAY_T* site_specific_freqs = allocate_array(asize); int j = 0; for(j = 0; j < asize; j++) { double value = get_matrix_cell(i, j, get_motif_freqs(motif)); set_array_item(j, value, site_specific_freqs); } if (use_halpern_bruno == FALSE) { models[0] = make_model( model_type, fg_rate, transition_transversion, purine_pyrimidine, site_specific_freqs, NULL ); } else { models[0] = make_model( model_type, fg_rate, transition_transversion, purine_pyrimidine, bg_freqs, site_specific_freqs ); } // get the alignment column frequencies using this model MATRIX_T* tmp_pssm_matrix = build_alignment_pssm_matrix( alph, alignment_species, 2, // only interested in freqs under bkg models, tree, gap_support ); // assemble the position-dependent background alignment column freqs. set_matrix_row(i, get_matrix_row(0, tmp_pssm_matrix), pos_dep_bkg); // chuck the pssm (not his real name) free_matrix(tmp_pssm_matrix); } // // Compute and print the score distribution under the background model // and under the (position-dependent) motif model. // int range = 10000; // 10^4 gives same result as 10^5, but 10^3 differs // under background model PSSM_T* pssm = build_matrix_pssm(alph, pssm_matrix, alignment_col_freqs, range); // under position-dependent background (motif) model PSSM_T* pssm_pos_dep = build_matrix_pssm(alph, pssm_matrix, alignment_col_freqs, range); get_pv_lookup_pos_dep( pssm_pos_dep, pos_dep_bkg, NULL // no priors used ); // print FP and FN distributions int num_items = get_pssm_pv_length(pssm_pos_dep); for (i=0; i<num_items; i++) { double pvf = get_pssm_pv(i, pssm); double pvt = get_pssm_pv(i, pssm_pos_dep); double fpr = pvf; double fnr = 1 - pvt; if (fpr >= 0.99999 || fnr == 0) continue; printf("%s score %d FPR %.3g FNR %.3g\n", motif_id, i, fpr, fnr); } // free stuff free_pssm(pssm); free_pssm(pssm_pos_dep); if (models != NULL) { int model_index; int num_models = get_motif_length(motif) + 1; for (model_index = 0; model_index < num_models; model_index++) { free_model(models[model_index]); } myfree(models); } } // motif arraylst_destroy(destroy_motif, motifs); /********************************************** * Clean up. **********************************************/ // TLB may have encountered a memory corruption bug here // CEG has not been able to reproduce it. valgrind says all is well. free_array(bg_freqs); free_tree(TRUE, tree); free_string_list(selected_motifs); return(0); } // main
extern "C" __declspec(dllexport) int i32_resize_array(const MKL_INT length, int*& x) { return resize_array(length, x); }
/** * Reads file. * * @param p0 the array * @param p1 the array count * @param p2 the array size * @param p3 the file name * @param p4 the file name count */ void read_file(void* p0, void* p1, void* p2, const void* p3, const void* p4) { if (p4 != NULL_POINTER) { int* nc = (int*) p4; if (p3 != NULL_POINTER) { void** n = (void**) p3; if (p2 != NULL_POINTER) { int* as = (int*) p2; if (p1 != NULL_POINTER) { int* ac = (int*) p1; // Initialize terminated file name and its size. char* tn = CHARACTER_NULL_POINTER; int tns = *nc + 1; // Create terminated file name. create_array((void*) &tn, (void*) &CHARACTER_ARRAY, (void*) &tns); // Initialize destination array index. int i = 0; // Set terminated file name by first copying the actual name and then // adding the null termination character. set_array_elements((void*) &tn, (void*) &CHARACTER_ARRAY, (void*) &i, p3, p4); set_array_element((void*) &tn, (void*) &CHARACTER_ARRAY, p4, (void*) &NULL_CHARACTER); fprintf(stderr, "read file name: %s\n", tn); fprintf(stderr, "read file name size: %i\n", tns); // Open file. // CAUTION! The file name cannot be handed over as is. // CYBOI strings are NOT terminated with the null character '\0'. // Since 'fopen' expects a null terminated string, the termination character // must be added to the string before that is used to open the file. FILE* f = fopen(tn, "r"); if (f != NULL_POINTER) { // Read first character. char c = fgetc(f); while (1) { if (c == EOF) { break; } if (*ac == *as) { // Increase size. *as = *as * FILE_RESIZE_FACTOR + 1; // Resize array. resize_array(p0, (void*) &CHARACTER_ARRAY, p2); } if (*ac < *as) { // Set character in destination array. // The array count serves as index for setting the character. set_array_element(p0, (void*) &CHARACTER_ARRAY, p1, (void*) &c); // Increase array count. (*ac)++; } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The index exceeds the array size."); } // Read next character. c = fgetc(f); } // Close file. fclose(f); // Destroy terminated file name. destroy_array((void*) &tn, (void*) &CHARACTER_ARRAY, (void*) &tns); } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The file is null."); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The array count is null."); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The array size is null."); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The file name is null."); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &"Could not read file. The file name count is null."); } }
int allocman_configure_max_freed_untyped_chunks(allocman_t *alloc, uint32_t num) { return resize_array(alloc, num, (void**)&alloc->freed_utspace_chunks, &alloc->desired_freed_utspace_chunks, &alloc->num_freed_utspace_chunks, sizeof(struct allocman_freed_utspace_chunk)); }
static int resize_slots_array(allocman_t *alloc, uint32_t num, cspacepath_t **slots, uint32_t *size, uint32_t *count) { return resize_array(alloc, num, (void**)slots, size, count, sizeof(cspacepath_t)); }
extern "C" __declspec(dllexport) int ui16_resize_array(const MKL_INT length, unsigned short*& x) { return resize_array(length, x); }
/** * Parses the byte stream and creates a string model from it. * * @param p0 the destination (Hand over as reference!) * @param p1 the destination count * @param p2 the destination size * @param p3 the source * @param p4 the source count */ void parse_string(void* p0, void* p1, void* p2, const void* p3, const void* p4) { if (p4 != NULL_POINTER) { int* sc = (int*) p4; if (p2 != NULL_POINTER) { int* ds = (int*) p2; if (p1 != NULL_POINTER) { int* dc = (int*) p1; if (p0 != NULL_POINTER) { void** d = (void**) p0; if (*dc >= 0) { log_message_debug("Parse string."); // The new destination string size. // (Not exactly the size, but the destination string index // increased by the source array count.) *ds = *dc + *sc; // Resize destination string. resize_array(p0, p2, (void*) CHARACTER_ARRAY); if (*dc <= (*ds - *sc)) { // Set source into destination string. set_array_elements(*d, p1, p3, p4, (void*) CHARACTER_ARRAY); // Increment count. // Example: // d = "helloworld" // dc (as index) = 5 // s = "universe" // sc = 8 // d (after set) = "hellouniverse" // dc = dc + sc = 13 *dc = *dc + *sc; } else { log_message_debug("Could not parse string. The destination count exceeds the size."); } } else { log_message_debug("Could not parse string. The destination count is negative."); } } else { log_message_debug("Could not parse string. The destination is null."); } } else { log_message_debug("Could not parse string. The destination count is null."); } } else { log_message_debug("Could not parse string. The destination size is null."); } } else { log_message_debug("Could not parse string. The source count is null."); } }
/** * Serializes the integer model and creates a byte stream from it. * * @param p0 the destination (Hand over as reference!) * @param p1 the destination count * @param p2 the destination size * @param p3 the source * @param p4 the source count */ void serialize_integer(void* p0, void* p1, void* p2, const void* p3, const void* p4) { if (p2 != NULL_POINTER) { int* ds = (int*) p2; if (p1 != NULL_POINTER) { int* dc = (int*) p1; if (p0 != NULL_POINTER) { char** d = (char**) p0; log_message_debug("Serialize integer."); // The integer value. int* v = INTEGER_NULL_POINTER; // Get integer value. get_array_elements(p3, (void*) INTEGER_VALUE_INDEX, (void*) &v, (void*) INTEGER_ARRAY); //?? TODO: set_array_elements is missing! //?? The get_array_elements procedure does NOT copy values; //?? it returns just a reference to the corresponding value! // Transform source integer to destination string. *dc = snprintf(*d, *ds, "%i", *v); // Set destination string size one greater than the count // to have space for the terminating null character. *ds = *dc + 1; // Resize destination string. resize_array(p0, p2, (void*) CHARACTER_ARRAY); // Transform source integer to destination string. *dc = snprintf(*d, *ds, "%i", *v); // CAUTION! Recalculate string count because only in versions // of the GNU C library prior to 2.1, the snprintf function // returns the number of characters stored, not including the // terminating null; unless there was not enough space in the // string to store the result in which case -1 is returned. // This was CHANGED in order to comply with the ISO C99 standard. // As usual, the string count does NOT contain the terminating // null character. *dc = strlen(*d); } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &COULD_NOT_PARSE_INTEGER_THE_DESTINATION_IS_NULL_MESSAGE, (void*) &COULD_NOT_PARSE_INTEGER_THE_DESTINATION_IS_NULL_MESSAGE_COUNT); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &COULD_NOT_PARSE_INTEGER_THE_DESTINATION_COUNT_IS_NULL_MESSAGE, (void*) &COULD_NOT_PARSE_INTEGER_THE_DESTINATION_COUNT_IS_NULL_MESSAGE_COUNT); } } else { //?? log_message((void*) &ERROR_LOG_LEVEL, (void*) &COULD_NOT_PARSE_INTEGER_THE_DESTINATION_SIZE_IS_NULL_MESSAGE, (void*) &COULD_NOT_PARSE_INTEGER_THE_DESTINATION_SIZE_IS_NULL_MESSAGE_COUNT); } }