void R_mqmscan(int *Nind,int *Nmark,int *Npheno, int *geno,int *chromo, double *dist, double *pheno, int *cofactors, int *backwards, int *RMLorML,double *alfa,int *emiter, double *windowsize,double *steps,double *stepmi,double *stepma, int *nRun, int *out_Naug, int *indlist, double *qtl, int *reestimate, int *crosstype, int *domi, int *verbose) { int **Geno; int **Chromo; double **Dist; double **Pheno; double **QTL; int **Cofactors; int **INDlist; // Reorganise the pointers into arrays, singletons are just cast into the function reorg_geno(*Nind,*Nmark,geno,&Geno); reorg_int(*Nmark,1,chromo,&Chromo); reorg_pheno(*Nmark,1,dist,&Dist); // Here we have the assumption that step.min is negative this needs to be split in 2 reorg_pheno((int)(2*(*chromo) * (((*stepma)-(*stepmi))/ (*steps))),1,qtl,&QTL); reorg_pheno(*Nind,*Npheno,pheno,&Pheno); reorg_int(*Nmark,1,cofactors,&Cofactors); reorg_int(*out_Naug,1,indlist,&INDlist); mqmscan(*Nind,*Nmark,*Npheno,Geno,Chromo,Dist,Pheno,Cofactors,*backwards,*RMLorML,*alfa,*emiter,*windowsize,*steps,*stepmi,*stepma,*nRun,*out_Naug,INDlist,QTL, *reestimate,(RqtlCrossType)*crosstype,*domi,*verbose); }
void R_mqmaugment(int *geno, double *dist, double *pheno, int *auggeno, double *augPheno, int *augIND, int *Nind, int *Naug, int *Nmark, int *Npheno, int *maxind, int *maxiaug, double *minprob, int *chromo, int *rqtlcrosstypep, int *augment_strategy, int *verbosep) { int **Geno; double **Pheno; double **Dist; int **NEW; //Holds the output for the augmentdata function int **Chromo; double **NEWPheno; //New phenotype vector int **NEWIND; //New list of individuals const int nind0 = *Nind; //Individuals we start with const int verbose = *verbosep; const RqtlCrossType rqtlcrosstype = (RqtlCrossType) *rqtlcrosstypep; if(verbose) Rprintf("INFO: Starting C-part of the data augmentation routine\n"); ivector new_ind; MQMMarkerMatrix markers = newMQMMarkerMatrix(*Nmark, nind0); vector mapdistance = newvector(*Nmark); ivector chr = newivector(*Nmark); //Reorganise the pointers into arrays, Singletons are just cast into the function reorg_geno(nind0, *Nmark, geno, &Geno); reorg_int(*Nmark, 1, chromo, &Chromo); reorg_pheno(nind0, *Npheno, pheno, &Pheno); reorg_pheno(*Nmark, 1, dist, &Dist); reorg_int(*maxind, *Nmark, auggeno, &NEW); reorg_int((*maxiaug)*nind0, 1, augIND, &NEWIND); reorg_pheno((*maxiaug)*nind0, 1, augPheno, &NEWPheno); MQMCrossType crosstype = determine_MQMCross(*Nmark, *Nind, (const int **)Geno, rqtlcrosstype); // Determine cross change_coding(Nmark, Nind, Geno, markers, crosstype); // Change all the markers from R/qtl format to MQM internal if(verbose) Rprintf("INFO: Filling the chromosome matrix\n"); for (int i=0; i<(*Nmark); i++) { //Set some general information structures per marker mapdistance[i] = POSITIONUNKNOWN; mapdistance[i] = Dist[0][i]; chr[i] = Chromo[0][i]; } if(mqmaugmentfull(&markers,Nind,Naug,&new_ind,*minprob, *maxind, *maxiaug,&Pheno,*Nmark,chr,mapdistance,*augment_strategy,crosstype,verbose)){ //Data augmentation finished succesfully, encode it back into RQTL format for (int i = 0; i<(*Nmark); i++) { for (int j = 0; j<(*Naug); j++) { //Rprintf("INFO: Phenotype after return: %f",NEWPheno[0][j]); NEWPheno[0][j] = Pheno[0][j]; NEWIND[0][j] = new_ind[j]; NEW[i][j] = 9; if (markers[i][j] == MAA) { NEW[i][j] = 1; } if (markers[i][j] == MH) { NEW[i][j] = 2; } if (markers[i][j] == MBB) { // [karl:] this might need to be changed for RIL crosstype==CRIL ? NEW[i][j]=2 : NEW[i][j] = 3; //[Danny:] This should solve it } if (markers[i][j] == MNOTAA) { NEW[i][j] = 5; } if (markers[i][j] == MNOTBB) { NEW[i][j] = 4; } } } if (verbose) { Rprintf("# Unique individuals before augmentation:%d\n", nind0); Rprintf("# Unique selected individuals:%d\n", *Nind); Rprintf("# Marker p individual:%d\n", *Nmark); Rprintf("# Individuals after augmentation:%d\n", *Naug); Rprintf("INFO: Data augmentation succesfull\n"); } } else { //Unsuccessfull data augmentation exit Rprintf("INFO: This code should not be reached, data corruption could have occured. Please re-run this analysis.\n"); *Naug = nind0; for (int i=0; i<(*Nmark); i++) { for (int j=0; j<(*Naug); j++) { NEWPheno[0][j] = Pheno[0][j]; NEW[i][j] = 9; if (markers[i][j] == MAA) { NEW[i][j] = 1; } if (markers[i][j] == MH) { NEW[i][j] = 2; } if (markers[i][j] == MBB) { // [Karl:] this might need to be changed for RIL crosstype==CRIL ? NEW[i][j]=2 : NEW[i][j] = 3; // [Danny:] This should solve it } if (markers[i][j] == MNOTAA) { NEW[i][j] = 5; } if (markers[i][j] == MNOTBB) { NEW[i][j] = 4; } } } fatal("Data augmentation failed", ""); } delMQMMarkerMatrix(markers,*Nmark); // [Danny:] This looked suspicious, we were leaking memory here because we didn't clean it Free(mapdistance); Free(chr); return; }