void findBestDupes(duplicate_t *head, char *consensus) { // For each duplicate list, go through its mafline list and find the best line and move it // to the head of the list. duplicate_t *d = head; scoredMafLine_t *sml = NULL; while (d != NULL) { if (d->numSequences < 2) { // if there's only one sequence, who cares d = d->next; continue; } // score all the maf lines sml = d->headScoredMaf; while (sml != NULL) { sml->score = scoreSequence(consensus, maf_mafLine_getSequence(sml->mafLine)); sml = sml->next; } // sort on scores scoredMafLine_t **mafLineArray = (scoredMafLine_t**) de_malloc(sizeof(*mafLineArray) * d->numSequences); populateMafLineArray(d->headScoredMaf, mafLineArray); qsort(mafLineArray, d->numSequences, sizeof(scoredMafLine_t *), cmp_by_score); // move the top score to the head of the list d->headScoredMaf = mafLineArray[0]; sml = d->headScoredMaf; for (unsigned i = 1; i < d->numSequences; ++i) { // rebuild the linked list sml->next = mafLineArray[i]; sml = sml->next; } sml->next = NULL; d = d->next; free(mafLineArray); } }
void findBestDupes(duplicate_t *head, char *consensus) { // For each duplicate, go through its mafline list and find the best line and move it // to the head of the list. duplicate_t *d = head; scoredMafLine_t *m = NULL; debug("findBestDupes()\n"); while (d != NULL) { debug(" d is not NULL\n"); debug(" species: %s", d->headScoredMaf->mafLine->species); m = d->headScoredMaf; unsigned n = numberOfSequencesScoredMafLineList(m); if (n < 2) { d = d->next; debug(" ... not dup.\n"); continue; } debug(" ... DUP.\n"); // score all the dupes while (m != NULL) { m->score = scoreSequence(consensus, m->mafLine->sequence); m = m->next; } // sort on scores scoredMafLine_t *mafLineArray[n]; populateMafLineArray(d->headScoredMaf, mafLineArray); qsort(mafLineArray, n, sizeof(scoredMafLine_t *), cmp_by_score); // move the top score to the head of the list d->headScoredMaf = mafLineArray[0]; m = d->headScoredMaf; for (unsigned i = 1; i < n; ++i) { m->next = mafLineArray[i]; m = m->next; } m->next = NULL; d = d->next; } }