int compare_sulstons(const void* a, const void* b)
{
if((*(struct MatrixListItem**)a)->score < (*(struct MatrixListItem**)b)->score) return -1;
if((*(struct MatrixListItem**)a)->score > (*(struct MatrixListItem**)b)->score) return 1;
return 0;
}
int build_bestlist(struct Clone **clones, struct Contig **contigs, int ctgnum, int tolerance)
{
int i, j, k;
int num, tot;
// 1) Allocate memory for list and clear list
num = contigs[ctgnum]->num_show;
tot = num * (num - 1) / 2;
bestlist = (struct MatrixListItem **) malloc (sizeof (struct MatrixListItem*) * tot);
for (i = 0; i < tot; i++) {
bestlist[i] = (struct MatrixListItem *) malloc (sizeof (struct MatrixListItem));
bestlist[i]->indx1 = -1;
bestlist[i]->indx2 = -1;
bestlist[i]->score = 0.0;
}
// 2) Build the list (half the matrix)
k = 0;
for (i = 0; i < num; i++)
for (j = i+1; j < num; j++) {
bestlist[k]->indx1 = contigs[ctgnum]->show_indx[i];
bestlist[k]->indx2 = contigs[ctgnum]->show_indx[j];
bestlist[k]->score = sulston(clones[contigs[ctgnum]->show_indx[i]],clones[contigs[ctgnum]->show_indx[j]]);
if (DEBUG >= 2)
printf("Adding %3i %3i %3i\t\t1=%3i\t2=%3i\t%.1e\n",i,j,k,bestlist[k]->indx1,bestlist[k]->indx2,bestlist[k]->score);
k++;
}
// 3) Sort this list by sulston score
qsort(bestlist, tot, sizeof(struct MatrixListItem*), compare_sulstons);
// 4) Print the list out
if (DEBUG)
for (i = 0; i < tot; i++) {
printf("Score = %.1e\ti = %i\tClone A %3i (%s)\tClone B %3i (%s)\n",bestlist[i]->score,i,
bestlist[i]->indx1, clones[bestlist[i]->indx1]->clonename,
bestlist[i]->indx2, clones[bestlist[i]->indx2]->clonename);
}
return tot;
}
Isn't that cute? :)