void 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 re_estimate, RqtlCrossType rqtlcrosstype,int domi,int verbose){ int cof_cnt=0; MQMMarkerMatrix markers = newMQMMarkerMatrix(Nmark+1,Nind); cvector cofactor = newcvector(Nmark); vector mapdistance = newvector(Nmark); MQMCrossType crosstype = determine_MQMCross(Nmark,Nind,(const int **)Geno,rqtlcrosstype); change_coding(&Nmark, &Nind, Geno, markers, crosstype); // Change all the markers from R/qtl format to MQM internal for (int i=0; i< Nmark; i++) { mapdistance[i] = POSITIONUNKNOWN; // Mapdistances mapdistance[i] = Dist[0][i]; cofactor[i] = MNOCOF; // Cofactors if (Cofactors[0][i] == 1) { cofactor[i] = MCOF; // Set cofactor cof_cnt++; } if (Cofactors[0][i] == 2) { cofactor[i] = MSEX; cof_cnt++; } if (cof_cnt+10 > Nind){ fatal("Setting %d cofactors would leave less than 10 degrees of freedom.\n", cof_cnt); } } char reestimate = 'y'; if(re_estimate == 0) reestimate = 'n'; if (crosstype != CF2) { // Determine what kind of cross we have if (verbose==1) Rprintf("INFO: Dominance setting ignored (setting dominance to 0)\n"); // Update dominance accordingly domi = 0; } bool dominance=false; if(domi != 0){ dominance=true; } //WE HAVE EVERYTHING START WITH MAIN SCANNING FUNCTION analyseF2(Nind, &Nmark, &cofactor, (MQMMarkerMatrix)markers, Pheno[(Npheno-1)], Backwards, QTL, &mapdistance, Chromo, NRUN, RMLorML, Windowsize, Steps, Stepmi, Stepma, Alfa, Emiter, out_Naug, INDlist, reestimate, crosstype, dominance, verbose); if (re_estimate) { if (verbose==1) Rprintf("INFO: Sending back the re-estimated map used during the MQM analysis\n"); for (int i=0; i< Nmark; i++) { Dist[0][i] = mapdistance[i]; } } if (Backwards) { if (verbose==1) Rprintf("INFO: Sending back the model\n"); for (int i=0; i< Nmark; i++) { Cofactors[0][i] = cofactor[i]; } } if(verbose) Rprintf("INFO: All done in C returning to R\n"); #ifndef STANDALONE R_CheckUserInterrupt(); /* check for ^C */ R_FlushConsole(); #endif return; } /* end of function mqmscan */
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; }