Link create_view(){ View self = malloc(sizeof(*self)); self->items = im_new(); self->fog_parameters[0]=0.0; //Densisty self->fog_parameters[1]=0.0; //Start self->fog_parameters[2]=0.0; //End self->origin = 0; //left, right, bottom, top, near, far self->bounds[0] = 0.0; self->bounds[1] = 100.0; self->bounds[2] = 0.0; self->bounds[3] = 100.0; self->bounds[4] = 0.0; self->bounds[5] = 100.0; self->projection = 1;// 0 is Perspective , 1 is Orthographic self->camera_pos = NULL; //~ return lnk; Link obj = object_create(view_type); obj->value.vptr = self; return obj; }
static NATIVECALL(bwindow_new){ BWindow self = malloc(sizeof(*self)); self->items = im_new(); self->width = 500; self->height = 500; self->title = NULL; self->x = self->y = 0; self->clear_color[0] = 1; self->clear_color[1] = 1; self->clear_color[2] = 1; self->clear_color[3] = 1; self->bindings = NULL; self->update = 0; self->onClose = NULL; self->onKeyDown = NULL; self->onKeyUp = NULL; Link obj = object_create(window_type); obj->value.vptr = self; bwindow_create(obj); return obj; }
/* create a new birth-death phylo-HMM based on parameter values */ BDPhyloHmm *bd_new(TreeModel *source_mod, double rho, double mu, double nu, double phi, double alpha_c, double beta_c, double tau_c, double alpha_n, double beta_n, double tau_n, int estim_gamma, int estim_omega, int estim_phi) { int i, state; int nleaves = (source_mod->tree->nnodes + 1) / 2; int nstates = 2 + 2 * (2*nleaves - 3); /* number of states */ HMM *hmm; TreeModel **models = smalloc(nstates * sizeof(void*)); TreeNode *n; CategoryMap *cm; List *inside = lst_new_ptr(source_mod->tree->nnodes), *outside = lst_new_ptr(source_mod->tree->nnodes); BDPhyloHmm *bdphmm; double *alpha = smalloc(source_mod->tree->nnodes * sizeof(double)), *beta = smalloc(source_mod->tree->nnodes * sizeof(double)), *tau = smalloc(source_mod->tree->nnodes * sizeof(double)); if (rho <= 0 || rho >= 1) die("ERROR bd_new: rho (%e) out of bound (0, 1)\n", rho); if (mu <= 0 || 2*mu >=1) die("ERROR bd_new: mu (%e) out of bound (0, 0.5)\n", mu); if (nu <= 0 || nu >= 1) die("ERROR bd_new: nu (%e) out of bound (0, 1)\n", nu); bdphmm = smalloc(sizeof(BDPhyloHmm)); bdphmm->state_to_branch = smalloc(nstates * sizeof(int)); bdphmm->branch_to_state_birth = smalloc(source_mod->tree->nnodes * sizeof(int)); bdphmm->branch_to_state_death = smalloc(source_mod->tree->nnodes * sizeof(int)); bdphmm->rho = rho; bdphmm->mu = mu; bdphmm->nu = nu; bdphmm->phi = phi; bdphmm->estim_gamma = estim_gamma; bdphmm->estim_omega = estim_omega; bdphmm->estim_phi = estim_phi; /* set up mappings between states and branches. Branches are indexed by ids of child nodes; "birth" means functional element arose on branch, "death" means element was lost on branch. */ state = 0; for (i = 0; i < source_mod->tree->nnodes; i++) { n = lst_get_ptr(source_mod->tree->nodes, i); bdphmm->state_to_branch[state] = n->id; bdphmm->branch_to_state_death[n->id] = state; state++; } for (i = 0; i < source_mod->tree->nnodes; i++) { n = lst_get_ptr(source_mod->tree->nodes, i); if (n->parent == source_mod->tree) { bdphmm->branch_to_state_birth[n->id] = -1; continue; /* branches beneath root ignored -- events can't be distinguished from death events on opposite branch */ } bdphmm->state_to_branch[state] = n->id; bdphmm->branch_to_state_birth[n->id] = state; state++; } if (state != nstates) die("ERROR bd_new state (%i) != nstates (%i)\n", state, nstates); /* note: this is structured so that state 0 is the nonconserved model (like element "died" prior to root) and state nnodes is the fully conserved model (like element was "born" prior to root) */ /* now make copies of models and scale branches as needed */ models[0] = source_mod; for (state = 1; state < nstates; state++) { /* skip state == 0 */ models[state] = tm_create_copy(source_mod); n = lst_get_ptr(models[state]->tree->nodes, bdphmm->state_to_branch[state]); tr_partition_nodes(models[state]->tree, n, inside, outside); if (state < models[state]->tree->nnodes) /* death */ for (i = 0; i < lst_size(outside); i++) ((TreeNode*)lst_get_ptr(outside, i))->dparent *= rho; else /* birth */ for (i = 0; i < lst_size(inside); i++) ((TreeNode*)lst_get_ptr(inside, i))->dparent *= rho; tm_reinit(models[state], models[state]->subst_mod, models[state]->nratecats, models[state]->alpha, NULL, NULL); } /* Require informative sites for all but state 0 */ for (state = 1; state < nstates; state++) models[state]->inform_reqd = TRUE; /* set up HMM transitions */ hmm = hmm_new_nstates(nstates, TRUE, FALSE); /* build category map */ cm = cm_create_trivial(nstates - 1, NULL); for (state = 0; state < nstates; state++) { String *name = lst_get_ptr(cm->ranges[state]->feature_types, 0); if (state == 0) str_cpy_charstr(name, "nonconserved"); else if (state == source_mod->tree->nnodes) str_cpy_charstr(name, "conserved"); else { n = lst_get_ptr(source_mod->tree->nodes, bdphmm->state_to_branch[state]); str_cpy_charstr(name, n->name); if (state < source_mod->tree->nnodes) str_append_charstr(name, "-death"); else str_append_charstr(name, "-birth"); } } bdphmm->phmm = phmm_new(hmm, models, cm, NULL, MISSING_DATA); bd_set_transitions(bdphmm); /* set up indel model, if necessary */ if (alpha_c > 0) { bdphmm->indel_mods = smalloc(nstates * sizeof(void*)); for (state = 0; state < nstates; state++) { List *l; n = lst_get_ptr(models[state]->tree->nodes, bdphmm->state_to_branch[state]); tr_partition_nodes(models[state]->tree, n, inside, outside); /* initialize alpha, beta, tau with nonconserved params */ for (i = 0; i < models[state]->tree->nnodes; i++) { alpha[i] = alpha_n; beta[i] = beta_n; tau[i] = tau_n; } /* now change to conserved params for conserved branches */ if (state < models[state]->tree->nnodes) l = outside; /* death */ else l = inside; /* birth; includes conserved */ for (i = 0; i < lst_size(l); i++) { n = lst_get_ptr(l, i); alpha[n->id] = alpha_c; beta[n->id] = beta_c; tau[n->id] = tau_c; } bdphmm->indel_mods[state] = im_new(alpha, beta, tau, models[state]->tree); } } else bdphmm->indel_mods = NULL; lst_free(inside); lst_free(outside); sfree(alpha); sfree(beta); sfree(tau); return bdphmm; }