void CNPLCM_CR_Basic_Freq::permute_latent_classes_by_nu(){ //reorder latent classes increasingly according to nuK. std::vector<int> new2old(par->K), old2new(par->K); std::vector<_CNPLCM_CR_Basic_Freq_mypair> s_index(par->K); for (int k = 0; k < par->K; k++){ s_index[k].first = 1.0 - par->nuK[k]; s_index[k].second = k; } std::sort(s_index.begin(), s_index.end(), _CNPLCM_CR_Basic_Freq_comparator); std::vector<int> perm(K); for (int k = 0; k < par->K; k++){ new2old[k] = s_index[k].second; } // new2old[a] == b <=> former b-th element is now a-th element. for (int k = 0; k < par->K; k++){ old2new[ new2old[k] ] = k; } CParams_NPLCM_CR_Basic_Freq *tmp = new CParams_NPLCM_CR_Basic_Freq(*par); //for (int i = 0; i < par->n; i++){ // tmp->zI[i] = old2new[ par->zI[i] ]; //} for (int m = 0; m < par->M; m++){ for (int k = 0; k < par->K; k++){ tmp->count_zIK[m][k] = par->count_zIK[m][ new2old[k] ]; } } for (int j = 0; j < par->J; j++){ for (int k = 0; k < par->K; k++){ tmp->lambdaJK[j][k] = par->lambdaJK[j][ new2old[k] ]; tmp->aux_JK2[j][k][0] = par->aux_JK2[j][ new2old[k] ][0]; tmp->aux_JK2[j][k][1] = par->aux_JK2[j][ new2old[k] ][1]; } } for (int k = 0; k < par->K; k++){ tmp->nuK[k] = par->nuK[new2old[k]]; tmp->log_nuK[k] = par->log_nuK[new2old[k]]; tmp->countK[k] = par->countK[new2old[k]]; tmp->count0K[k] = par->count0K[new2old[k]]; } //std::copy(tmp->zI, tmp->zI + par->n, par->zI); std::copy(tmp->count_zIK[0], tmp->count_zIK[0] + par->M * par->J, par->count_zIK[0]); std::copy(tmp->lambdaJK[0], tmp->lambdaJK[0] + par->J * par->K, par->lambdaJK[0]); std::copy(tmp->aux_JK2[0][0], tmp->aux_JK2[0][0] + par->J * par->K * 2, par->aux_JK2[0][0]); std::copy(tmp->nuK, tmp->nuK + par->K, par->nuK); std::copy(tmp->log_nuK, tmp->log_nuK + par->K, par->log_nuK); std::copy(tmp->countK, tmp->countK + par->K, par->countK); std::copy(tmp->count0K, tmp->count0K + par->K, par->count0K); delete tmp; }
void Tree::reorderSeqs (vguard<FastSeq>& seq) const { Assert (seq.size() == nodes(), "Number of sequences doesn't match number of nodes in tree"); map<string,size_t> name2seq; for (size_t n = 0; n < seq.size(); ++n) { Assert (name2seq.find (seq[n].name) == name2seq.end(), "Duplicate sequence name: %s", seq[n].name.c_str()); name2seq[seq[n].name] = n; } vguard<size_t> new2old (seq.size()), old2new (seq.size()); for (TreeNodeIndex n = 0; n < nodes(); ++n) { Assert (name2seq.find (seqName(n)) != name2seq.end(), "Tree node %s is absent from sequence dataset", seqName(n).c_str()); const size_t old_n = name2seq[seqName(n)]; new2old[n] = old_n; old2new[old_n] = n; } for (size_t n = 0; n < new2old.size(); ++n) { const size_t o = new2old[n], m = old2new[n]; swap (seq[n], seq[o]); swap (old2new[n], old2new[o]); swap (new2old[n], new2old[m]); } }
struct utmpx * pututxline(const struct utmpx *utx) { struct utmpx temp, *u = NULL; int gotlock = 0; _DIAGASSERT(utx != NULL); if (utx == NULL) return NULL; if (strcmp(_PATH_UTMPX, utfile) == 0) { if (geteuid() == 0) { if (fp != NULL && readonly) endutxent(); } else { if (fp == NULL || readonly) return utmp_update(utx); } } (void)memcpy(&temp, utx, sizeof(temp)); if (fp == NULL) { (void)getutxent(); if (fp == NULL || readonly) return NULL; } if (getutxid(&temp) == NULL) { setutxent(); if (getutxid(&temp) == NULL) { if (lockf(fileno(fp), F_LOCK, (off_t)0) == -1) return NULL; gotlock++; if (fseeko(fp, (off_t)0, SEEK_END) == -1) goto fail; } } if (!gotlock) { /* we are not appending */ if (fseeko(fp, -(off_t)sizeof(ut), SEEK_CUR) == -1) return NULL; } if (version == 1) new2old(&temp); if (fwrite(&temp, sizeof (temp), 1, fp) != 1) goto fail; if (fflush(fp) == -1) goto fail; u = memcpy(&ut, &temp, sizeof(ut)); fail: if (gotlock) { if (lockf(fileno(fp), F_ULOCK, (off_t)0) == -1) return NULL; } return u; }