void remapind(SNP **snpmarkers, int numsnps, Indiv **indivmarkers, Indiv **indm2, int numindivs, int numind2) { int *g1, *g2, *w1 ; int *tind, t, i, j, k ; Indiv *indx ; SNP *cupt ; if (numindivs != numind2) fatalx("different remapind sizes %d %d\n", numindivs, numind2) ; ZALLOC(tind, numind2, int) ; ZALLOC(g2, numind2, int) ; ZALLOC(g1, numind2, int) ; ZALLOC(w1, numind2, int) ; for (k=0; k<numind2; ++k) { indx = indm2[k] ; t = tind[k] = indindex(indivmarkers, numindivs, indx -> ID) ; if (t<0) fatalx("bad newindiv: %s\n", indx -> ID) ; } for (i=0; i<numsnps; i++) { cupt = snpmarkers[i] ; for (j=0; j<numind2; ++j) { g1[j] = getgtypes(cupt, j) ; } copyiarr(g1, w1, numind2) ; for (k=0; k< numind2; ++k) { g2[k] = g1[tind[k]] ; } ivclear(g1, -1, numind2) ; copyiarr(g2, g1, numind2) ; for (k=0; k<numind2; ++k) { putgtypes(cupt, k, g1[k]) ; } /** if (i<100) { printf("zzz %s\n", cupt -> ID) ; for (j=0; j<numind2; ++j) { g1[j] = getgtypes(cupt, j) ; } printimat(w1, 1, numind2) ; printimat(g1, 1, numind2) ; } */ } free(w1) ; free(g1) ; free(g2) ; free(tind) ; }
void iclear2D(int ***xx, int numrows, int numcols, int val) { int **array ; int i ; array = *xx ; for (i=numrows-1; i>=0; i--) { ivclear(array[i], val, numcols) ; } }
void countcat(int *tags, int n,int *ncat,int nclass) /* simple frequency count of integer array */ { int i, k; ivclear(ncat, 0, nclass) ; for (i=0 ; i<n ; i++) { k = tags[i] ; if ( (k<0) || (k >= nclass)) fatalx("(countcat) bounds error\n") ; ++ncat[k] ; } }
void invperm(int *a, int *b, int n) { /** a, b can be same */ int i, j ; int *x ; if (n==0) return ; ZALLOC(x, n, int) ; ivclear(x,-1,n) ; for (i=0; i<n; i++) { j=b[i] ; x[j]=i ; } copyiarr(x, a, n) ; free(x) ; }
void ivzero(int *a, int n) { ivclear(a, 0, n) ; }