#include <pedigree.h>
Definition at line 53 of file pedigree.h.
Public Types | |
| enum | ped_type { raw, standard } |
Public Methods | |
| Pedigree (char pedtype[]="") | |
| Pedigree (Pedigree &P) | |
| ~Pedigree (void) | |
| const Pedigree & | operator= (Pedigree &P) |
| int | inbcoef_done (void) const |
| int | in_memory (void) const |
| void | copyfrom (Pedigree &P) |
| void | save_pedsheet (const int relse=1) |
| void | input_pedsheet (void) |
| void | release_pedsheet (void) |
| void | resize (const unsigned na) |
| unsigned | input (const std::string &pfname, const std::string &fmt="individual mother father", const std::string &pedtype="raw") |
| unsigned | input_standard (std::istream &pedfile, unsigned ind, unsigned mother, unsigned father) |
| unsigned | ngroup (void) const |
| unsigned | size (void) const |
| unsigned | nbase (void) const |
| Vector< double > * | inbcoef_quaas (int keepinmem=0) |
| Vector< double > * | inbcoef_meuwissen (int keepinmem=0) |
| Vector< double > * | inbcoef (int keepinmem=0) |
| doubleMatrix | mat (void) |
| double | logdet (int keepinmem=0) |
| doubleMatrix | rela (int keepinmem=0) |
| doubleMatrix | ainv (int keepinmem=0) |
| doubleMatrix | reld (int keepinmem=0) |
| Pedigree & | sample (const unsigned maxsize, const unsigned maxg, const unsigned sire0=1, const unsigned dam0=1, const double imrate=0.1, const unsigned parent=1, const int no_po=1, const int no_fsib=1, const double sexratio=0.5) |
| void | out_to_stream (std::ostream &stream, const int style=0, const int ic=0) |
| void | save (const std::string &fname, const int style=0, const int io_mode=std::ios::out) |
| void | display (const std::string msg="", const int style=0, const int ic=0) |
| void | release (void) |
| const std::string | diskfname (void) const |
Public Attributes | |
| PedNode ** | pedmember |
| unsigned | maxnamelen |
| unsigned | sex_confirmed |
Static Public Attributes | |
| Pedigree::ped_type | type |
Protected Methods | |
| void | renum (void) |
Protected Attributes | |
| std::string | binfname |
| unsigned | totalna |
| unsigned | basesize |
| unsigned | numgroup |
| unsigned | nang |
| Vector< double > | fvec |
| int | fdone |
| int | ped_on_disk |
| int | ped_in_memory |
| int | groupingped |
| PedNode * | ped_storage |
Friends | |
| std::ostream & | operator<< (std::ostream &stream, Pedigree &A) |
|
|
Definition at line 63 of file pedigree.h.
|
|
|
Definition at line 68 of file pedigree.cpp. References basesize, binfname, fdone, groupingped, maxnamelen, matvec::Session::mktemp(), numgroup, ped_in_memory, ped_on_disk, ped_storage, pedmember, matvec::SESSION, sex_confirmed, totalna, and type.
00069 {
00070 /////////////////////////////////////////////////
00071 // type = "group" -> group
00072 // = "standard"
00073 // = anything else -> nongrouop
00074 //
00075 /////////////////////////////////////////////////
00076 nang = 0;
00077 fdone = 0;
00078 totalna = 0;
00079 numgroup = 0;
00080 basesize = 0;
00081 maxnamelen = 0;
00082 pedmember = 0;
00083 ped_storage = 0;
00084 sex_confirmed = 0;
00085 groupingped = 0;
00086 type = Pedigree::raw;
00087 if (strcmp(pedtype,"group") == 0) groupingped = 1;
00088 if (strcmp(pedtype,"standard") == 0) type = Pedigree::standard;
00089
00090 ped_on_disk = 0;
00091 ped_in_memory = 1;
00092 binfname = SESSION.mktemp();
00093 }
|
|
|
Definition at line 95 of file pedigree.cpp. References copyfrom(), groupingped, ped_storage, pedmember, and totalna.
00096 {
00097 totalna = 0;
00098 pedmember = 0;
00099 ped_storage = 0;
00100 groupingped = 0;
00101 copyfrom(P);
00102 }
|
|
|
Definition at line 72 of file pedigree.h. References release().
00072 {release();}
|
|
|
Definition at line 1155 of file pedigree.cpp. References matvec::Matrix< T >::begin(), matvec::PedNode::father_id, fdone, fvec, matvec::getlambda(), inbcoef(), input_pedsheet(), matvec::PedNode::mother_id, matvec::PedNode::myid, ped_in_memory, pedmember, release_pedsheet(), and totalna.
01156 {
01157 doubleMatrix ainvmat(totalna,totalna);
01158 if (totalna == 0) return ainvmat;
01159 if (!fdone) inbcoef(1);
01160 if (!ped_in_memory) input_pedsheet();
01161
01162 Matrix<double> lambda(3,3);
01163 getlambda(lambda.begin(),3);
01164 double f,x;
01165 Vector<unsigned> ids(3);
01166 unsigned i,j,k,ii,jj;
01167 PedNode *I;
01168
01169 for (k=0; k<totalna; k++) memset(ainvmat[k],'\0',sizeof(double)*totalna);
01170 for (k=0; k<totalna; k++) {
01171 I = pedmember[k];
01172 ids[0] = I->myid;
01173 ids[1] = I->mother_id;
01174 ids[2] = I->father_id;
01175 for (i=1; i<3; i++) if (ids[i]>totalna) ids[i] = 0;
01176 f = 2.0;
01177 if (ids[1] == 0) {f -= -1.0; }
01178 else {f -= fvec[ids[1]-1]; }
01179
01180 if (ids[2] == 0) {f -= -1.0; }
01181 else {f -= fvec[ids[2]-1]; }
01182
01183 f = 4.0/f;
01184 for (i=0; i<3; i++) {
01185 ii = ids[i];
01186 if (ii) {
01187 ii--;
01188 for (j=0; j<3; j++) {
01189 jj = ids[j];
01190 if (jj) {
01191 jj--;
01192 x = lambda[i][j]*f;
01193 ainvmat[ii][jj] += x;
01194 }
01195 }
01196 }
01197 }
01198 }
01199 if (!keepinmem) release_pedsheet();
01200 return ainvmat;
01201 }
|
|
|
Definition at line 104 of file pedigree.cpp. References basesize, binfname, fdone, fvec, groupingped, input_pedsheet(), maxnamelen, matvec::Session::mktemp(), nang, numgroup, ped_in_memory, ped_on_disk, release_pedsheet(), resize(), save_pedsheet(), matvec::SESSION, sex_confirmed, totalna, and type. Referenced by operator=(), and Pedigree().
00105 {
00106 if (this == &P) return;
00107 if (P.ped_in_memory) P.release_pedsheet();
00108 resize(P.nang);
00109 fvec = P.fvec;
00110 fdone = P.fdone;
00111 numgroup = P.numgroup;
00112 basesize = P.basesize;
00113 totalna = P.totalna; // totalna is necessary for save_pedsheet()
00114 maxnamelen = P.maxnamelen;
00115 groupingped = P.groupingped;
00116 type = P.type;
00117 sex_confirmed = P.sex_confirmed;
00118
00119 if (P.ped_on_disk) {
00120 binfname = P.binfname;
00121 if (P.ped_in_memory) P.release_pedsheet();
00122 ped_in_memory = 0;
00123 ped_on_disk = 1;
00124 input_pedsheet();
00125 }
00126 else {
00127 if (totalna != 0) throw exception("Pedigree::copyfrom(): you have probably found a bug!");
00128 ped_on_disk = 0;
00129 }
00130 binfname = SESSION.mktemp(); // each ped object must have its own binfname
00131 if (totalna != 0) save_pedsheet(0); // save changes without memory-release
00132 ped_in_memory = 1;
00133 }
|
|
|
Definition at line 111 of file pedigree.h. References binfname.
00111 {return binfname; }
|
|
||||||||||||||||
|
Definition at line 1404 of file pedigree.cpp. References out_to_stream().
01405 {
01406 if (msg != "") std::cout << "\n" << msg << "\n" << std::endl;
01407 out_to_stream(std::cout,style,ic);
01408 }
|
|
|
Definition at line 78 of file pedigree.h. References ped_in_memory.
00078 {return ped_in_memory;}
|
|
|
Definition at line 94 of file pedigree.h. References inbcoef_meuwissen(). Referenced by ainv().
00094 {return inbcoef_meuwissen(keepinmem);}
|
|
|
Definition at line 77 of file pedigree.h. References fdone.
00077 {return fdone;}
|
|
|
Definition at line 1009 of file pedigree.cpp. References matvec::Vector< double >::begin(), matvec::PedNode::father_id, fdone, fvec, input_pedsheet(), matvec::PedNode::mother_id, ped_in_memory, pedmember, release_pedsheet(), and totalna. Referenced by inbcoef(), and logdet().
01010 {
01011 if (totalna == 0) return &fvec;
01012 if (fdone) return &fvec;
01013 if (!ped_in_memory) input_pedsheet();
01014 double *L;
01015 if(totalna>0){
01016 L = new double [totalna];
01017 }
01018 else {
01019 L = 0;
01020 }
01021 double *D;
01022 if(totalna>0){
01023 D = new double [totalna];
01024 }
01025 else {
01026 D = 0;
01027 }
01028 unsigned *point;
01029 if(totalna>0){
01030 point = new unsigned [totalna];
01031 }
01032 else {
01033 point = 0;
01034 }
01035
01036 memset(L,'\0',sizeof(double)*totalna);
01037 memset(D,'\0',sizeof(double)*totalna);
01038 memset(point,'\0',sizeof(unsigned)*totalna);
01039
01040 L--; D--; point--;
01041 double *F = fvec.begin()-1; // now F starting from 1, no F[0] at all
01042
01043 unsigned i,j,k,d,s,kd,ks,kk,previous_d,previous_s;
01044 double r,fi;
01045 PedNode *I;
01046
01047 previous_s = 0; previous_d = 0;
01048 for (i=1; i<=totalna; i++) {
01049 I = pedmember[i-1];
01050 d = I->mother_id; if (d > totalna) d = 0;
01051 s = I->father_id; if (s > totalna) s = 0;
01052
01053 if (s == 0 || d == 0) {
01054 if (d+s == 0) {
01055 D[i] = 1.0;
01056 }
01057 else {
01058 D[i] = 0.75;
01059 }
01060 F[i] = 0.0;
01061 }
01062 else if ((d == previous_d) && (s == previous_s)) {
01063 F[i] = F[i-1];
01064 D[i] = D[i-1];
01065 }
01066 else {
01067 D[i] = 0.5 - 0.25*(F[d] + F[s]);
01068 fi = -1.0;
01069 L[i] = 1.0;
01070 j = i;
01071 while (j != 0) {
01072 k = j;
01073 r = 0.5*L[k];
01074 I = pedmember[k-1];
01075 kd = I->mother_id;
01076 ks = I->father_id;
01077 if (kd > ks) {kk = ks; ks = kd; kd = kk;}
01078 if (ks > 0 && ks <= totalna) {
01079 while (point[k] > ks) k = point[k];
01080 L[ks] += r;
01081 if (ks != point[k]) {
01082 point[ks] = point[k];
01083 point[k] = ks;
01084 }
01085 if (kd > 0 && kd <=totalna) {
01086 while (point[k] > kd) k = point[k];
01087 L[kd] += r;
01088 if (kd != point[k]) {
01089 point[kd] = point[k];
01090 point[k] = kd;
01091 }
01092 }
01093 }
01094 fi += L[j]*L[j]*D[j];
01095 L[j] = 0.0;
01096 k = j;
01097 j = point[j];
01098 point[k] = 0;
01099 }
01100 F[i] = fi;
01101 }
01102 previous_d = d; previous_s = s;
01103 }
01104 L++;
01105 if(L){
01106 delete [] L;
01107 L=0;
01108 }
01109 D++;
01110 if(D){
01111 delete [] D;
01112 D=0;
01113 }
01114 point++;
01115 if(point){
01116 delete [] point;
01117 point=0;
01118 }
01119
01120 fdone = 1;
01121 if (!keepinmem) release_pedsheet();
01122 return &fvec;
01123 }
|
|
|
Definition at line 973 of file pedigree.cpp. References matvec::Vector< double >::begin(), matvec::PedNode::father_id, fdone, fvec, input_pedsheet(), matvec::PedNode::mother_id, ped_in_memory, pedmember, release_pedsheet(), and totalna.
00974 {
00975 if (totalna == 0) return &fvec;
00976 if (fdone) return &fvec;
00977 if (!ped_in_memory) input_pedsheet();
00978
00979 unsigned i,j,s,d;
00980 PedNode *I,*J;
00981 double t;
00982 Vector<double> work(totalna); // working space
00983 double *inbc = fvec.begin();
00984 for (j=0; j<totalna; j++) {
00985 t = 0.0;
00986 J = pedmember[j];
00987 d = J->mother_id; s = J->father_id;
00988 if (d> 0 && d <= totalna) t += inbc[d-1];
00989 if (s> 0 && s <= totalna) t += inbc[s-1];
00990 t = 1.0 - 0.25*t;
00991 inbc[j] += t;
00992 work[j] = std::sqrt(t);
00993 for (i=j+1; i<totalna; i++) {
00994 t = 0.0;
00995 I = pedmember[i];
00996 d = I->mother_id; s = I->father_id;
00997 if (d > j && j<=totalna) t += .5*work[d-1];
00998 if (s > j && j<=totalna) t += .5*work[s-1];
00999 work[i] = t;
01000 inbc[i] += t*t;
01001 }
01002 }
01003 for (i=0; i<totalna; i++) *inbc++ -= 1.0;
01004 fdone = 1;
01005 if (!keepinmem) release_pedsheet();
01006 return &fvec;
01007 }
|
|
||||||||||||||||
|
Definition at line 239 of file pedigree.cpp. References basesize, matvec::Vector< T >::begin(), binfname, matvec::check_ptr(), matvec::PedNode::father_id, fdone, fvec, matvec::HashTable::get_id(), groupingped, INPUT_LINE_WIDTH, input_standard(), matvec::HashTable::insert(), maxnamelen, matvec::Session::mktemp(), matvec::PedNode::mother_id, matvec::PedNode::myid, matvec::PedNode::myname, matvec::PedNode::mysex, matvec::PedNode::namelen, nang, numgroup, ped_storage, matvec::pedcp1(), pedmember, release(), matvec::HashTable::release(), renum(), matvec::Vector< double >::resize(), resize(), save_pedsheet(), matvec::SESSION, sex_confirmed, totalna, type, matvec::validline(), and matvec::warning().
00241 {
00242 std::string fmt(recfmt);
00243 // fmt.replace_all('$',' ');
00244 std::string::size_type begidx,endidx;
00245 begidx = fmt.find("$");
00246 while (begidx != std::string::npos) {
00247 fmt[begidx] = ' ';
00248 begidx = fmt.find("$",begidx+1);
00249 }
00250
00251 std::string tempstr,sep(" ,");
00252 unsigned i,j,numrec,k;
00253 PedNode *I;
00254 int ncol,ind=-1,mother=-1,father=-1,sex=-1;
00255 ncol = 0;
00256 begidx = fmt.find_first_not_of(sep);
00257 while(begidx != std::string::npos) {
00258 endidx = fmt.find_first_of(sep,begidx);
00259 if (endidx == std::string::npos) endidx = fmt.length();
00260 tempstr = fmt.substr(begidx,endidx - begidx);
00261 if (tempstr == "individual") {
00262 ind = ncol;
00263 } else if (tempstr == "father") {
00264 father = ncol;
00265 } else if (tempstr == "mother") {
00266 mother = ncol;
00267 } else if (tempstr == "sex") {
00268 sex = ncol;
00269 }
00270 ncol++;
00271 begidx = fmt.find_first_not_of(sep,endidx);
00272 }
00273 if (ncol < 3) throw exception("Pedigree::input(fmt): fmt must contain at least three columns");
00274 if (ind < 0) throw exception("Pedigree::input(fmt): no individual column in fmt");
00275 if (mother < 0) throw exception("Pedigree::input(fmt): no mother column in fmt");
00276 if (father < 0) throw exception("Pedigree::input(fmt): no father column in fmt");
00277 if (sex >= 0) sex_confirmed = 1;
00278
00279 // std::string tmpfname;
00280 // tmpfname = SESSION.mktemp();
00281
00282 std::ifstream pedfile(pfname.c_str(),std::ios::in);
00283 if (!pedfile) throw exception("Pedigree::input(): can't open pedigree file");
00284 if (pedtype != "") {
00285 if (pedtype == "raw") {
00286 type = Pedigree::raw;
00287 }
00288 else if (pedtype == "standard") {
00289 type = Pedigree::standard;
00290 numrec = input_standard(pedfile,ind,mother,father);
00291 pedfile.close();
00292 return numrec;
00293 }
00294 else if (pedtype == "group") {
00295 groupingped = 1;
00296 }
00297 else {
00298 warning("Pedigree::input(): unknown pedigree type: arg3 is ignored");
00299 }
00300 }
00301
00302 size_t linewidth = INPUT_LINE_WIDTH;
00303 char *line;
00304 if(linewidth>0){
00305 line = new char [linewidth];
00306 }
00307 else {
00308 line = 0;
00309 }
00310
00311 numrec = 0;
00312 while (pedfile.getline(line,linewidth)) if (validline(line)) numrec++;
00313 if (numrec == 0) {
00314 if(line){
00315 delete [] line;
00316 line=0;
00317 }
00318 pedfile.close();
00319 nang = totalna = numrec;
00320 throw exception("Pedigree::input(): pedigree is empty");
00321 }
00322 pedfile.clear();
00323 pedfile.seekg(0L,std::ios::beg);
00324
00325 size_t isdwidth = sizeof(unsigned)*3;
00326 char *wd;
00327 if(linewidth>0){
00328 wd = new char [linewidth];
00329 }
00330 else {
00331 wd = 0;
00332 }
00333 char *sireid;
00334 if(linewidth>0){
00335 sireid= new char [linewidth];
00336 }
00337 else {
00338 sireid = 0;
00339 }
00340 char *damid;
00341 if(linewidth>0){
00342 damid = new char [linewidth];
00343 }
00344 else {
00345 damid = 0;
00346 }
00347 char sexid;
00348 sexid = '.';
00349 Vector<unsigned> stdrec(3);
00350
00351 std::string tmpfname;
00352 tmpfname = SESSION.mktemp();
00353
00354 std::fstream tpedfile(tmpfname.c_str(),std::ios::out);
00355 if (!tpedfile) throw exception("can't open internal pedigree file " + tmpfname);
00356
00357 resize(numrec);
00358 HashTable pedigreeTable(numrec,"str");
00359 char *temp;
00360 maxnamelen = 0;
00361 numrec = 0;
00362 unsigned lineNum = 0;
00363 while (pedfile.getline(line,linewidth)) {
00364 lineNum++;
00365 if (!validline(line)) continue;
00366 temp = strtok(line,", ");
00367 i = 0;
00368 while (temp) {
00369 if (i == ind) {
00370 strcpy(wd, temp);
00371 }
00372 else if (i == mother) {
00373 strcpy(damid,temp);
00374 }
00375 else if (i == father) {
00376 strcpy(sireid,temp);
00377 }
00378 else if (i == sex) {
00379 sexid = temp[0];
00380 }
00381 i++;
00382 temp = strtok('\0',", ");
00383 }
00384 if (i < ncol) {
00385 std::cerr << "pedigree " << pfname << ", line " << lineNum << ": invalid\n";
00386 throw exception("invalid line");
00387 }
00388 if (!groupingped && strcmp(damid,sireid) == 0) {
00389 if (strcmp(sireid,".") && strcmp(sireid,"0")) {
00390 warning("pedigree %s, line %d, identical parents: %s. It's ignored",
00391 pfname.c_str(),lineNum,sireid);
00392 continue;
00393 }
00394 }
00395 if (pedigreeTable.get_id(wd)) {
00396 warning("pedigree %s, line %d, duplicated id: %s. It's ignored",
00397 pfname.c_str(),lineNum,wd);
00398 continue;
00399 }
00400 else {
00401 pedigreeTable.insert(wd);
00402 }
00403 stdrec[0] = strlen(wd)+1;
00404 stdrec[1] = strlen(damid)+1;
00405 stdrec[2] = strlen(sireid)+1;
00406 I = pedmember[numrec];
00407 I->myname = new char [stdrec[0]];
00408 strcpy(I->myname,wd);
00409 I->namelen = stdrec[0];
00410 if (stdrec[0] > maxnamelen) maxnamelen = stdrec[0];
00411 numrec++;
00412 tpedfile.write((char*)stdrec.begin(),isdwidth);
00413 tpedfile.write(wd,(size_t)stdrec[0]);
00414 tpedfile.write(damid,(size_t)stdrec[1]);
00415 tpedfile.write(sireid,(size_t)stdrec[2]);
00416 tpedfile.write((char*)&sexid,1);
00417 }
00418 if (maxnamelen > 0) maxnamelen--;
00419 pedigreeTable.release();
00420 if(line){
00421 delete [] line;
00422 line=0;
00423 }
00424 pedfile.close();
00425 tpedfile.close();
00426 qsort((char *)pedmember,numrec,sizeof(PedNode*),pedcp1);
00427 /*
00428 for (i=1; i<numrec; i++) {
00429 if (strcmp(pedmember[i]->myname,pedmember[i-1]->myname) == 0) {
00430 cout << " in pedigree " << pfname <<"\n";
00431 cout << " duplicated id: " << pedmember[i]->myname << "\n";
00432 delete [] wd;
00433 delete [] damid;
00434 delete [] sireid;
00435 delete [] stdrec;
00436 release();
00437 return 0;
00438 }
00439 }
00440 */
00441 tpedfile.open(tmpfname.c_str(),std::ios::in);
00442
00443 std::set<std::string> table; // binary tree
00444 PedNode **d,**s;
00445 d = new PedNode*[1];
00446 s = new PedNode*[1];
00447 d[0] = new PedNode[1];
00448 s[0] = new PedNode[1];
00449 d[0]->myname = damid;
00450 s[0]->myname = sireid;
00451
00452 char *c;
00453 for (i=0; i<numrec; i++) {
00454 tpedfile.read((char*)stdrec.begin(),isdwidth);
00455 tpedfile.read(wd,(size_t)stdrec[0]);
00456 tpedfile.read(damid,(size_t)stdrec[1]);
00457 tpedfile.read(sireid,(size_t)stdrec[2]);
00458 tpedfile.read((char*)&sexid,1);
00459 if (groupingped) {
00460 c =(char *)bsearch((char *)d,(char *)pedmember,numrec,sizeof(PedNode*),
00461 pedcp1);
00462 if (!c) table.insert(damid);
00463 c =(char *)bsearch((char *)s,(char *)pedmember,numrec,sizeof(PedNode*),
00464 pedcp1);
00465 if (!c) table.insert(sireid);
00466 }
00467 else {
00468 if (strcmp(damid,"0") && strcmp(damid,".")) {
00469 c = (char *)bsearch((char *)d,(char *)pedmember,numrec,
00470 sizeof(PedNode*),pedcp1);
00471 if (!c) table.insert(damid);
00472 }
00473 if (strcmp(sireid,"0") && strcmp(sireid,".")) {
00474 c =(char *)bsearch((char *)s,(char *)pedmember,numrec,
00475 sizeof(PedNode*),pedcp1);
00476 if (!c) table.insert(sireid);
00477 }
00478 }
00479 }
00480
00481 basesize = table.size();
00482 ///////////////////////////////////////////////////////////////////
00483 // it is not really # of base animals, it is # of animals which
00484 // are not listed in the individual column. However, it is # of
00485 // unknown parents groups for genetic group model.
00486 // Real basesize will be calculated in renum().
00487 ///////////////////////////////////////////////////////////////////
00488
00489 if (groupingped) {
00490 totalna = numrec;
00491 numgroup = basesize;
00492 }
00493 else {
00494 totalna = basesize + numrec;
00495 numgroup = 0;
00496 }
00497 fvec.resize(totalna,0.0);
00498 fdone = 0;
00499
00500 if (basesize ) { // now hash sire and dam which are not in the id list
00501 std::fstream bpedfile(binfname.c_str(),std::ios::out);
00502 if (!bpedfile) {
00503 release();
00504 throw exception("Pedigree.input(): can't open internal file");
00505 }
00506 for (i=0; i<numrec; i++) {
00507 I = pedmember[i];
00508 j = I->namelen;
00509 bpedfile.write((char*)&j,sizeof(unsigned));
00510 bpedfile.write(I->myname,j);
00511 }
00512 bpedfile.close();
00513 bpedfile.open(binfname.c_str(),std::ios::in);
00514
00515 for (i=0; i<numrec; i++) {
00516 if(ped_storage[i].myname){
00517 delete [] ped_storage[i].myname;
00518 ped_storage[i].myname=0;
00519 }
00520 }
00521 if(ped_storage){
00522 delete [] ped_storage;
00523 ped_storage=0;
00524 }
00525 if(pedmember){
00526 delete [] pedmember;
00527 pedmember=0;
00528 }
00529 nang = basesize + numrec;
00530 if(nang>0){
00531 ped_storage = new PedNode[nang];
00532 }
00533 else {
00534 ped_storage = 0;
00535 }
00536 check_ptr(ped_storage);
00537 pedmember = new PedNode*[nang];
00538 check_ptr(pedmember);
00539 for (i=0; i<nang; i++) {
00540 I = &(ped_storage[i]);
00541 I->mysex = '.';
00542 I->myname = 0;
00543 I->namelen = 0;
00544 pedmember[i] = I;
00545 }
00546
00547 for (i=0; i<numrec; i++) {
00548 I = pedmember[i];
00549 bpedfile.read((char*)&j,sizeof(unsigned));
00550 I->namelen = j;
00551 if(j>0){
00552 I->myname = new char [j];
00553 }
00554 else {
00555 I->myname = 0;
00556 }
00557 check_ptr(I->myname);
00558 bpedfile.read(I->myname,(size_t)j);
00559 }
00560 bpedfile.close();
00561
00562 qsort((char *)pedmember,numrec,sizeof(PedNode*),pedcp1);
00563 std::set<std::string>::iterator pos;
00564 for (i=0,pos=table.begin(); pos != table.end(); ++pos,++i) {
00565 j = numrec+i;
00566 I = pedmember[j];
00567 k = I->namelen = pos->length()+1;
00568 if(k>0){
00569 I->myname = new char [k];
00570 }
00571 else {
00572 I->myname = 0;
00573 }
00574 strcpy(I->myname, pos->c_str());
00575 }
00576 }
00577
00578 for (i=0; i<nang; i++) {
00579 I = pedmember[i];
00580 I->myid = i+1; I->father_id = 0; I->mother_id = 0;
00581 }
00582 tpedfile.close();
00583 tpedfile.open(tmpfname.c_str(),std::ios::in);
00584
00585 PedNode **w,**pm;
00586 w = new PedNode*[1];
00587 w[0] = new PedNode[1];
00588 w[0]->myname = wd;
00589 for (i=0; i<numrec; i++) {
00590 tpedfile.read((char*)stdrec.begin(),isdwidth);
00591 tpedfile.read(wd,(size_t)stdrec[0]);
00592 tpedfile.read(damid,(size_t)stdrec[1]);
00593 tpedfile.read(sireid,(size_t)stdrec[2]);
00594 tpedfile.read((char*)&sexid,1);
00595 pm = (PedNode **)bsearch((char *)w,(char *)pedmember,numrec,
00596 sizeof(PedNode*),pedcp1);
00597 I = pedmember[pm[0]->myid - 1];
00598 if (groupingped) {
00599 pm = (PedNode **)bsearch((char *)d,(char *)pedmember,numrec,
00600 sizeof(PedNode*),pedcp1);
00601 if (!pm) {
00602 pm = (PedNode **)bsearch((char *)d,(char *)&(pedmember[numrec]),
00603 basesize, sizeof(PedNode*),pedcp1);
00604 if (!pm) throw exception("Pedigree::input(): you have probably found a bug!");
00605 }
00606 I->mother_id = pm[0]->myid;
00607
00608 pm = (PedNode **)bsearch((char *)s,(char *)pedmember,numrec,
00609 sizeof(PedNode*),pedcp1);
00610 if (!pm) {
00611 pm = (PedNode **)bsearch((char *)s,(char *)&(pedmember[numrec]),
00612 basesize, sizeof(PedNode*),pedcp1);
00613 if (!pm) throw exception("Pedigree::input(): you have probably found a bug!");
00614 }
00615 I->father_id = pm[0]->myid;
00616 }
00617 else {
00618 if (strcmp(damid,"0") && strcmp(damid,".")) {
00619 pm = (PedNode **)bsearch((char *)d,(char *)pedmember,numrec,
00620 sizeof(PedNode*),pedcp1);
00621 if (!pm) {
00622 pm =(PedNode **)bsearch((char *)d,(char *)&(pedmember[numrec]),
00623 basesize, sizeof(PedNode*),pedcp1);
00624 if (!pm) throw exception("Pedigree::input(): you have probably found a bug!");
00625 }
00626 I->mother_id = pm[0]->myid;
00627 }
00628 if (strcmp(sireid,"0") && strcmp(sireid,".") ) {
00629 pm = (PedNode **)bsearch((char *)s,(char *)pedmember,numrec,
00630 sizeof(PedNode*),pedcp1);
00631 if (!pm) {
00632 pm =(PedNode **)bsearch((char *)s,(char *)&(pedmember[numrec]),
00633 basesize, sizeof(PedNode*),pedcp1);
00634 if (!pm) throw exception("Pedigree::input(): you have probably found a bug!");
00635 }
00636 I->father_id = pm[0]->myid;
00637 }
00638 }
00639 I->mysex = sexid;
00640 }
00641 tpedfile.close();
00642 if(wd){
00643 delete [] wd;
00644 wd=0;
00645 }
00646 if(damid){
00647 delete [] damid;
00648 damid=0;
00649 }
00650 if(sireid){
00651 delete [] sireid;
00652 sireid=0;
00653 }
00654 if(w[0]){
00655 delete [] w[0];
00656 w[0]=0;
00657 }
00658 if(w){
00659 delete [] w;
00660 w=0;
00661 }
00662 if(d[0]){
00663 delete [] d[0];
00664 d[0]=0;
00665 }
00666 if(d){
00667 delete [] d;
00668 d=0;
00669 }
00670 if(s[0]){
00671 delete [] s[0];
00672 s[0]=0;
00673 }
00674 if(s){
00675 delete [] s;
00676 s=0;
00677 }
00678 renum();
00679 save_pedsheet();
00680 remove(tmpfname.c_str());
00681 return numrec;
00682 }
|
|
|
Definition at line 834 of file pedigree.cpp. References binfname, matvec::check_ptr(), matvec::PedNode::father_id, maxnamelen, matvec::PedNode::mother_id, matvec::PedNode::myid, matvec::PedNode::myname, matvec::PedNode::mysex, matvec::PedNode::namelen, nang, ped_in_memory, ped_on_disk, ped_storage, pedmember, and totalna. Referenced by ainv(), copyfrom(), inbcoef_meuwissen(), inbcoef_quaas(), mat(), out_to_stream(), and rela().
00835 {
00836 if (ped_in_memory) return;
00837 if (!ped_on_disk) throw exception("Pedigree::input_pedsheet(): Pedigre is not on disk");
00838 std::ifstream pedfile(binfname.c_str(),std::ios::in);
00839 if (!pedfile) throw exception("(1) most likely, pedigree has not been inputed\n"
00840 " (2) or probably, it can't open internal file");
00841 unsigned i,len;
00842 PedNode *I;
00843 if(nang>0){
00844 ped_storage = new PedNode[nang];
00845 }
00846 else {
00847 ped_storage = 0;
00848 }
00849 check_ptr(ped_storage);
00850 pedmember = new PedNode*[nang];
00851 check_ptr(pedmember);
00852
00853 for (i=0; i<nang; i++) {
00854 I = &(ped_storage[i]);
00855 I->mysex = '.';
00856 I->myname = 0;
00857 I->namelen = 0;
00858 pedmember[i] = I;
00859 }
00860 unsigned idssex[4];
00861 size_t idswidth = 4*sizeof(unsigned);
00862 for (i=0; i<totalna; i++) {
00863 pedfile.read((char *)idssex,idswidth);
00864 I = pedmember[i];
00865 I->myid = idssex[0]; I->mother_id = idssex[1]; I->father_id = idssex[2];
00866 I->mysex = (char)idssex[3];
00867 //cout << "input_pedsheet "<< I << I->myid << " " << I->father_id << " " << I->mother_id <<"\n";
00868 }
00869 if (maxnamelen > 0) {
00870 for (i=0; i<nang; i++) {
00871 I = pedmember[i];
00872 pedfile.read((char *)&len,sizeof(unsigned));
00873 if(len>0){
00874 I->myname = new char [len];
00875 }
00876 else {
00877 I->myname = 0;
00878 }
00879 pedfile.read(I->myname,(size_t)len);
00880 }
00881 }
00882 pedfile.close();
00883 ped_in_memory = 1; // pedigree data now is in memorry
00884 }
|
|
||||||||||||||||||||
|
Definition at line 152 of file pedigree.cpp. References basesize, matvec::PedNode::father_id, fdone, fvec, INPUT_LINE_WIDTH, matvec::PedNode::mother_id, matvec::PedNode::myid, nang, pedmember, matvec::Vector< double >::resize(), resize(), save_pedsheet(), totalna, and matvec::validline(). Referenced by input().
00154 {
00155 size_t linewidth = INPUT_LINE_WIDTH;
00156 char *line;
00157 if(linewidth>0){
00158 line = new char [linewidth];
00159 }
00160 else {
00161 line = 0;
00162 }
00163 size_t isdwidth = sizeof(unsigned)*4;
00164
00165 pedfile.clear();
00166 pedfile.seekg(0L,std::ios::beg);
00167 unsigned i,numrec = 0;
00168 while (pedfile.getline(line,linewidth)) if (validline(line)) numrec++;
00169 if (numrec == 0) {
00170 if(line){
00171 delete [] line;
00172 line=0;
00173 }
00174 nang = totalna = numrec;
00175 throw exception("Pedigree::input_standard(): pedigree is empty");
00176 }
00177 pedfile.clear();
00178 pedfile.seekg(0L,std::ios::beg);
00179
00180 resize(numrec);
00181 PedNode *I;
00182 char *temp;
00183 numrec = 0;
00184 basesize = 0;
00185 unsigned numsameid = 0;
00186 while (pedfile.getline(line,linewidth)) {
00187 if (!validline(line)) continue;
00188 I = pedmember[numrec++];
00189 temp = strtok(line,", ");
00190 i = 0;
00191 while (temp) {
00192 if (i==individual) {
00193 if (!sscanf(temp,"%d",&(I->myid))) {
00194 numrec--;
00195 throw exception("Pedigree::input_standard(): non-numerical character"
00196 " in your standard pedigree");
00197 }
00198 }
00199 else if (i==father) {
00200 if (strcmp(temp,".") == 0) {
00201 I->father_id = 0;
00202 }
00203 else {
00204 if (!sscanf(temp,"%d",&(I->father_id))) {
00205 numrec--;
00206 throw exception("Pedigree::input_standard(): non-numerical character"
00207 " in your standard pedigree");
00208 }
00209 }
00210 }
00211 else if (i==mother) {
00212 if (strcmp(temp,".") == 0) {
00213 I->mother_id = 0;
00214 }
00215 else {
00216 if (!sscanf(temp,"%d",&(I->mother_id))) {
00217 numrec--;
00218 throw exception("Pedigree::input_standard(): non-numerical character"
00219 " in your standard pedigree");
00220 }
00221 }
00222 }
00223 i++;
00224 temp = strtok('\0',", ");
00225 }
00226 if (I->father_id==0 && I->mother_id==0) basesize++;
00227 }
00228 nang = totalna = numrec;
00229 if(line){
00230 delete [] line;
00231 line=0;
00232 }
00233 fvec.resize(totalna,0.0);
00234 fdone = 0;
00235 save_pedsheet(0);
00236 return totalna;
00237 }
|
|
|
Definition at line 1125 of file pedigree.cpp. References matvec::Vector< double >::begin(), matvec::PedNode::father_id, fdone, fvec, inbcoef_meuwissen(), matvec::PedNode::mother_id, pedmember, release_pedsheet(), and totalna.
01126 {
01127 ////////////////////////////////////////////////////////
01128 // ln of determinant of additive relationship matrix A
01129 ////////////////////////////////////////////////////////
01130 double retval = 0.0;
01131 if (totalna==0) throw exception("Pedigree::logdet(): empty pedigree");
01132 if (!fdone) inbcoef_meuwissen(1);
01133 double *F = fvec.begin()-1; // now F starting from 1, no F[0] at all
01134 PedNode *I;
01135 unsigned father,mother;
01136
01137 for (unsigned i=0; i<totalna; i++) {
01138 I = pedmember[i];
01139 mother = I->mother_id;
01140 father = I->father_id;
01141 if (mother && father) {
01142 retval += std::log((2.0-F[mother]-F[father])/4.0);
01143 }
01144 else if (mother && !father) {
01145 retval += std::log((3.0-F[mother])/4.0);
01146 }
01147 else if (!mother && father) {
01148 retval += std::log((3.0-F[father])/4.0);
01149 }
01150 }
01151 if (!keepinmem) release_pedsheet();
01152 return retval;
01153 }
|
|
|
Definition at line 1277 of file pedigree.cpp. References matvec::PedNode::father_id, input_pedsheet(), matvec::PedNode::mother_id, matvec::PedNode::myid, ped_in_memory, pedmember, release_pedsheet(), and totalna.
01278 {
01279 doubleMatrix retval(totalna,3);
01280 if (totalna == 0) throw exception("Pedigree::mat(): empty pedigree objec");
01281
01282 if (!ped_in_memory) input_pedsheet();
01283 double *dpt;
01284 PedNode *I;
01285 for (unsigned i=0; i<totalna; i++) {
01286 I = pedmember[i];
01287 dpt = retval[i];
01288 *dpt++ = static_cast<double>(I->myid);
01289 *dpt++ = static_cast<double>(I->mother_id);
01290 *dpt++ = static_cast<double>(I->father_id);
01291 }
01292 release_pedsheet();
01293 return retval;
01294 }
|
|
|
Definition at line 91 of file pedigree.h. References basesize.
00091 {return basesize;}
|
|
|
Definition at line 89 of file pedigree.h. References numgroup. Referenced by matvec::Model::RSamplerPrior_dist().
00089 {return numgroup;}
|
|
|
Definition at line 74 of file pedigree.h. References copyfrom().
00074 {copyfrom(P); return *this;}
|
|
||||||||||||||||
|
Definition at line 1296 of file pedigree.cpp. References matvec::PedNode::father_id, fvec, input_pedsheet(), maxnamelen, matvec::PedNode::mother_id, matvec::PedNode::myid, matvec::PedNode::myname, matvec::PedNode::mysex, matvec::Session::output_precision, ped_in_memory, pedmember, release_pedsheet(), matvec::SESSION, totalna, and matvec::warning(). Referenced by display(), matvec::operator<<(), and save().
01297 {
01298 if (totalna == 0) {
01299 os << "\t empty pedigree object\n" << std::flush;
01300 return;
01301 }
01302 char line[10];
01303 unsigned i,k;
01304 int W = SESSION.output_precision+6; // 6 = +.e+00
01305 char S = ' '; // one blank space
01306 PedNode *I;
01307
01308 if (!ped_in_memory) input_pedsheet();
01309 if (maxnamelen > 0) {
01310 if (style==0) {
01311 os << " string_ID renumed_ID mother_ID father_ID"
01312 << " sex";
01313 if (fdone) os << " inbcoef";
01314 os << "\n";
01315 for (k=23,i=0; i<totalna; i++) {
01316 if (ic && i>=k) {
01317 k += 23;
01318 os << " more ... [q for quit] ";
01319 std::cin.getline(line,sizeof(line));
01320 if (line[0]=='q') break;
01321 }
01322 I = pedmember[i];
01323 os << std::setw(maxnamelen) << I->myname
01324 << S << std::setw(W)<< I->myid
01325 << S << std::setw(W) << I->mother_id
01326 << S << std::setw(W) << I->father_id
01327 << S << std::setw(1) << I->mysex;
01328 if (fdone) os << S << std::setw(W) << fvec[i];
01329 os << "\n";
01330 }
01331 }
01332 else if (style==1) {
01333 for (k=23,i=0; i<totalna; i++) {
01334 if (ic && i>=k) {
01335 k += 23;
01336 os << " more ... [q for quit] ";
01337 std::cin.getline(line,sizeof(line));
01338 if (line[0]=='q') break;
01339 }
01340 I = pedmember[i];
01341 os << std::setw(maxnamelen) << I->myname;
01342 if (I->mother_id) {
01343 os << S << std::setw(maxnamelen) << pedmember[I->mother_id-1]->myname;
01344 }
01345 else {
01346 os << S << std::setw(maxnamelen) << "0";
01347 }
01348 if (I->father_id) {
01349 os << S << std::setw(maxnamelen) << pedmember[I->father_id-1]->myname;
01350 }
01351 else {
01352 os << S << std::setw(maxnamelen) << "0";
01353 }
01354 os << S << std::setw(1) << I->mysex;
01355 if (fdone) os << S << std::setw(W) << fvec[i];
01356 os << "\n";
01357 }
01358 }
01359 else {
01360 warning("Pedigree::out_to_stream(,style): invalid style");
01361 return;
01362 }
01363 }
01364 else {
01365 if (style==0) {
01366 os << " renumed_ID mother_ID father_ID sex";
01367 if (fdone) os << " inbcoef";
01368 os << "\n";
01369 }
01370 for (k=23,i=0; i<totalna; i++) {
01371 if (ic && i>=k) {
01372 k += 23;
01373 os << " more ... [q for quit] ";
01374 std::cin.getline(line,sizeof(line));
01375 if (line[0]=='q') break;
01376 }
01377 I = pedmember[i];
01378 os << std::setw(W)<< I->myid
01379 << S << std::setw(W) << I->mother_id << S << std::setw(W) << I->father_id
01380 << S << std::setw(1) << I->mysex;
01381 if (fdone) os << S << std::setw(W) << fvec[i];
01382 os << "\n";
01383 }
01384 }
01385 os << std::flush;
01386 release_pedsheet();
01387 }
|
|
|
Definition at line 1203 of file pedigree.cpp. References matvec::PedNode::father_id, input_pedsheet(), matvec::PedNode::mother_id, matvec::PedNode::myid, ped_in_memory, pedmember, release_pedsheet(), and totalna. Referenced by reld().
01204 {
01205 doubleMatrix amat(totalna,totalna);
01206 if (totalna == 0) return amat;
01207 if (!ped_in_memory) input_pedsheet();
01208
01209 PedNode *I;
01210 unsigned i,j,a,d,s;
01211 for (i=0; i<totalna; i++) {
01212 memset(amat[i],'\0',sizeof(double)*totalna);
01213 I = pedmember[i];
01214 a = I->myid-1;
01215 d = I->mother_id;
01216 s = I->father_id;
01217 amat[a][a] = 1.0;
01218 if ( d>totalna ) d = 0;
01219 if ( s>totalna ) s = 0;
01220 if (d && s) {
01221 d--; s--;
01222 for (j=0; j<a; j++) {
01223 amat[j][a] = amat[a][j] = (amat[d][j]+amat[s][j])/2.0;
01224 }
01225 amat[a][a] += amat[d][s]/2.0;
01226 }
01227 else if (s && !d) {
01228 s--;
01229 for (j=0; j<a; j++) amat[j][a] = amat[a][j] = amat[s][j]/2.0;
01230 }
01231 else if (!s && d) {
01232 d--;
01233 for (j=0; j<a; j++) amat[j][a] = amat[a][j] = amat[d][j]/2.0;
01234 }
01235 }
01236 if (!keepinmem) release_pedsheet();
01237 return amat;
01238 }
|
|
|
Definition at line 1240 of file pedigree.cpp. References matvec::Matrix< double >::begin(), matvec::PedNode::father_id, matvec::PedNode::mother_id, pedmember, rela(), release_pedsheet(), totalna, and matvec::warning().
01241 {
01242 doubleMatrix temp(totalna,totalna);
01243
01244 if (totalna == 0) return temp;
01245 warning("P.reld() is appropriate only if pedigree is non-inbred");
01246 doubleMatrix A(totalna,totalna);
01247 A = rela(1);
01248 double **me = A.begin();
01249 PedNode *I,*J;
01250 unsigned i,j,di,si,dj,sj;
01251
01252 for (i=0; i<totalna; i++) memset(temp[i],'\0',sizeof(double)*totalna);
01253 for (i=0; i<totalna-1; i++) {
01254 temp[i][i] = 1.0;
01255 I = pedmember[i];
01256 di = I->mother_id;
01257 si = I->father_id;
01258 if (di>0 && di<=totalna && si>0 && si<=totalna) {
01259 di--; si--;
01260 for (j=i+1; j<totalna; j++) {
01261 J = pedmember[j];
01262 dj = J->mother_id;
01263 sj = J->father_id;
01264 if ( dj>0 && dj<=totalna && sj>0 && sj<=totalna) {
01265 dj--; sj--;
01266 temp[j][i] = temp[i][j] = .25*(me[di][dj]*me[si][sj]+
01267 me[di][sj]*me[si][dj]);
01268 }
01269 }
01270 }
01271 }
01272 temp[totalna-1][totalna-1] = 1.0;
01273 if (!keepinmem) release_pedsheet();
01274 return temp;
01275 }
|
|
|
Definition at line 960 of file pedigree.cpp. References basesize, binfname, fdone, maxnamelen, nang, ped_in_memory, ped_on_disk, release_pedsheet(), and totalna. Referenced by input(), resize(), and ~Pedigree().
00961 {
00962 release_pedsheet();
00963 nang = 0;
00964 fdone = 0;
00965 totalna = 0;
00966 basesize = 0;
00967 maxnamelen = 0;
00968 ped_on_disk = 0;
00969 ped_in_memory = 0;
00970 remove(binfname.c_str());
00971 }
|
|
|
Definition at line 886 of file pedigree.cpp. References matvec::PedNode::myname, nang, ped_in_memory, ped_storage, and pedmember. Referenced by ainv(), copyfrom(), inbcoef_meuwissen(), inbcoef_quaas(), logdet(), mat(), out_to_stream(), rela(), reld(), release(), and save_pedsheet().
00887 {
00888 if (ped_storage) {
00889 for (unsigned i=0; i<nang; i++) {
00890 if (ped_storage[i].myname) {
00891 if(ped_storage[i].myname){
00892 delete [] ped_storage[i].myname;
00893 ped_storage[i].myname=0;
00894 }
00895 }
00896 }
00897 if(ped_storage){
00898 delete [] ped_storage;
00899 ped_storage=0;
00900 }
00901 ped_storage = 0;
00902 }
00903 if (pedmember) {delete [] pedmember; pedmember = 0;}
00904 ped_in_memory = 0; // pedigree is not in memory, but should on disk;
00905 }
|
|
|
Definition at line 907 of file pedigree.cpp. References basesize, matvec::PedNode::father_id, groupingped, matvec::Vector< T >::max(), matvec::PedNode::mother_id, matvec::PedNode::myid, matvec::PedNode::myname, nang, matvec::pedcp2(), pedmember, matvec::Vector< T >::reserve(), and totalna. Referenced by input().
00908 {
00909 if (totalna == 0) return;
00910 unsigned i,j,k,d,s;
00911 PedNode *I;
00912 Vector<unsigned> agen; agen.reserve(nang+1);
00913 agen[0] = 0;
00914 for (i=1; i<=totalna; i++) agen[i] = 1;
00915 for (i=(totalna+1); i<=nang; i++) agen[i] = 0; // group is assigned 0
00916
00917 int okk = 1;
00918 int g = 0;
00919 while (okk) {
00920 okk = 0;
00921 for (i=0; i<totalna; i++) {
00922 I = pedmember[i];
00923 d = agen[I->mother_id];
00924 s = agen[I->father_id];
00925 k = std::max(d,s);
00926 if (agen[i+1] <= k) {
00927 agen[i+1]= k+1;
00928 okk = I->myid;
00929 }
00930 }
00931 if (g++ >100) {
00932 std::cout << " A B C" << std::endl;
00933 std::cout << " B A D" << std::endl;
00934 std::cout << "Is it strange ? but it's in your pedigree\n";
00935 std::cout << "check the families with " << pedmember[okk-1]->myname << std::endl;
00936 exit(1);
00937 }
00938 }
00939 unsigned mg = agen.max();
00940 k = 0;
00941 for (i=1; i<=mg; i++) {
00942 for (j=0; j<totalna; j++) {
00943 if (agen[j+1] == i) pedmember[j]->myid = ++k;
00944 }
00945 }
00946 basesize = 0;
00947 if (!groupingped) {
00948 for (i=1; i<=totalna; i++) if (agen[i]==1) basesize++;
00949 }
00950 for (i=0; i<totalna; i++) {
00951 I = pedmember[i];
00952 d = I->mother_id; s = I->father_id;
00953 if (d>0 && d<=totalna) I->mother_id = pedmember[d-1]->myid;
00954 if (s>0 && s<=totalna) I->father_id = pedmember[s-1]->myid;
00955 // std::cout << "renum " << i << " " <<I->father_id <<" " <<I->mother_id<< "\n";
00956 }
00957 qsort((char *)pedmember,totalna,sizeof(PedNode*),pedcp2);
00958 }
|
|
|
Definition at line 135 of file pedigree.cpp. References matvec::PedNode::myname, matvec::PedNode::mysex, matvec::PedNode::namelen, nang, ped_storage, pedmember, and release(). Referenced by copyfrom(), input(), and input_standard().
00136 {
00137 if (nang == na) return;
00138 release();
00139 nang = na;
00140 if(!(ped_storage = new PedNode[nang])) throw exception("Pedigree.resize(): out of memory");
00141 if (!(pedmember = new PedNode*[nang])) throw exception("Pedigree.resize(): out of memory");
00142 PedNode* I;
00143 for (unsigned i=0; i<nang; i++) {
00144 I = &(ped_storage[i]);
00145 I->mysex = '.';
00146 I->myname = 0;
00147 I->namelen = 0;
00148 pedmember[i] = I;
00149 }
00150 }
|
|
||||||||||||||||||||||||||||||||||||||||
|
Definition at line 684 of file pedigree.cpp. References basesize, matvec::Vector< T >::begin(), binfname, fdone, fvec, matvec::ignbin(), maxnamelen, nang, numgroup, ped_in_memory, ped_on_disk, matvec::ran1(), matvec::Vector< double >::resize(), sex_confirmed, and totalna.
00689 {
00690 if (maxg < 1) throw exception("Pedigree::sample(maxsize,maxg,...): maxg must >= 1");
00691 size_t isdsexwidth = 4*sizeof(unsigned);
00692 unsigned tgsire, tsire = sire0;
00693 unsigned tgdam, tdam = dam0;
00694 if ((tdam+tsire) > maxsize) throw exception("Pedigree::sample(): out of memory");
00695 unsigned s,d,i,j,max_male,max_female;
00696 d = maxsize-tsire-tdam;
00697 s = static_cast<unsigned>(d*sexratio);
00698 max_female = tdam+d-s+200;
00699 max_male = tsire+s+200; // 200 is the buffer for randomness
00700 Vector<unsigned> female(max_female--);
00701 Vector<unsigned> male(max_male--);
00702
00703 for (i=0; i<=tdam; i++) female[i]=i;
00704 for (male[0]=0,i=1; i<=tsire; i++) male[i] = tdam + i;
00705 totalna = tdam + tsire;
00706 unsigned npg = (maxsize-tdam-tsire)/maxg +1;
00707 Matrix<unsigned> pedholder(3,maxsize+1);
00708
00709 // sexcode: female = 1, male = 2
00710 for (i=1; i<=tdam; i++) pedholder[2][i] = 1;
00711 for (i=tdam+1; i<=totalna; i++) pedholder[2][i] = 2;
00712
00713 long selecteddam,selectedsire;
00714 unsigned ds,dd,ss,sd;
00715 int tryagain,ntry;
00716 for (tgdam=tdam, tgsire=tsire, i=0; i<maxg; i++) {
00717 if (totalna >= maxsize) break;
00718 for (j=0; j<npg; j++) {
00719 if (totalna >= maxsize) break;
00720 if (ran1() > imrate) {
00721 ntry = 0;
00722 do {
00723 selecteddam = ignbin(long(tdam),0.6);
00724 selectedsire = ignbin(long(tsire),0.6);
00725 if (selecteddam == 0) selecteddam = parent;
00726 if (selectedsire == 0) selectedsire = parent;
00727 tryagain = 0;
00728 d = female[selecteddam];
00729 s = male[selectedsire];
00730 dd = pedholder[0][d];
00731 ds = pedholder[1][d];
00732 sd = pedholder[0][s];
00733 ss = pedholder[1][s];
00734 if (no_po) {
00735 if ( d>0 && sd == d) {
00736 tryagain = 1;
00737 }
00738 else if (s > 0 && ds == s) {
00739 tryagain = 1;
00740 }
00741 }
00742 if (no_fsib) {
00743 if (ss > 0 && sd >0) if (ss == ds && sd == dd) tryagain = 1;
00744 }
00745 if (tryagain) ntry++;
00746 if (ntry >100) {
00747 tryagain = 0;
00748 selecteddam = 0;
00749 selectedsire = 0;
00750 }
00751 } while (tryagain);
00752 }
00753 else {
00754 selecteddam = 0;
00755 selectedsire = 0;
00756 }
00757 totalna++;
00758 pedholder[0][totalna] = female[selecteddam];
00759 pedholder[1][totalna] = male[selectedsire];
00760
00761 if (ran1()<sexratio && tgdam < max_female) {
00762 tgdam++;
00763 female[tgdam] = totalna;
00764 pedholder[2][totalna] = 1;
00765 }
00766 else {
00767 if (tgsire < max_male) {
00768 tgsire++;
00769 male[tgdam] = totalna;
00770 pedholder[2][totalna] = 2;
00771 }
00772 else {
00773 tgdam++;
00774 female[tgdam] = totalna;
00775 pedholder[2][totalna] = 1;
00776 }
00777 }
00778 }
00779 tdam = tgdam;
00780 tsire = tgsire;
00781 }
00782
00783 std::ofstream outfile(binfname.c_str(),std::ios::out);
00784 if (!outfile) throw exception("can't open internal file");
00785 Vector<unsigned> stdrec(3);
00786 basesize = 0;
00787 for (j=1; j<=totalna; j++) {
00788 stdrec[0] = j;
00789 stdrec[1] = pedholder[0][j];
00790 stdrec[2] = pedholder[1][j];
00791 stdrec[3] = pedholder[2][j];
00792 if (stdrec[1] == 0 && stdrec[2] == 0) basesize++;
00793 outfile.write((char *)stdrec.begin(),isdsexwidth);
00794 }
00795 outfile.close();
00796 ped_in_memory = 0;
00797 ped_on_disk = 1;
00798 nang = totalna;
00799 numgroup = 0;
00800 fdone = 0;
00801 fvec.resize(totalna,0.0);
00802 maxnamelen = 0;
00803 sex_confirmed = 1;
00804 return *this;
00805 }
|
|
||||||||||||||||
|
Definition at line 1389 of file pedigree.cpp. References out_to_stream().
01390 {
01391 std::ofstream opedf;
01392 opedf.open(fname.c_str(),(OpenModeType)io_mode);
01393 if (!opedf) throw exception("Pedigree::save(): cannot open file");
01394 out_to_stream(opedf,style);
01395 opedf.close();
01396 }
|
|
|
Definition at line 807 of file pedigree.cpp. References binfname, matvec::PedNode::father_id, maxnamelen, matvec::PedNode::mother_id, matvec::PedNode::myid, matvec::PedNode::myname, matvec::PedNode::mysex, matvec::PedNode::namelen, nang, ped_on_disk, pedmember, release_pedsheet(), and totalna. Referenced by copyfrom(), input(), and input_standard().
00808 {
00809 //cout << "Save pedsheet\n";
00810 std::ofstream pedfile(binfname.c_str(),std::ios::out);
00811 if (!pedfile) throw exception("can't open internal file");
00812 PedNode *I;
00813 unsigned idssex[4];
00814 size_t idssexwidth = 4*sizeof(unsigned);
00815 unsigned i;
00816 for (i=0; i<totalna; i++) {
00817 I = pedmember[i];
00818 idssex[0] = I->myid; idssex[1] = I->mother_id; idssex[2] = I->father_id;
00819 idssex[3] = I->mysex;
00820 pedfile.write((char *)idssex,idssexwidth);
00821 }
00822 if (maxnamelen > 0) {
00823 for (i=0; i<nang; i++) {
00824 I = pedmember[i];
00825 pedfile.write((char *)&(I->namelen),sizeof(unsigned));
00826 pedfile.write(I->myname,I->namelen);
00827 }
00828 }
00829 pedfile.close();
00830 ped_on_disk = 1;
00831 if (relse) release_pedsheet();
00832 }
|
|
|
Definition at line 90 of file pedigree.h. References totalna.
00090 {return totalna;}
|
|
||||||||||||
|
Definition at line 1398 of file pedigree.cpp.
01399 {
01400 A.out_to_stream(stream);
01401 return stream;
01402 }
|
|
|
Definition at line 56 of file pedigree.h. Referenced by copyfrom(), input(), input_standard(), nbase(), Pedigree(), release(), renum(), and sample(). |
|
|
Definition at line 55 of file pedigree.h. Referenced by copyfrom(), diskfname(), input(), input_pedsheet(), Pedigree(), release(), sample(), and save_pedsheet(). |
|
|
Definition at line 58 of file pedigree.h. Referenced by ainv(), copyfrom(), inbcoef_done(), inbcoef_meuwissen(), inbcoef_quaas(), input(), input_standard(), logdet(), Pedigree(), release(), and sample(). |
|
|
Definition at line 57 of file pedigree.h. Referenced by ainv(), copyfrom(), inbcoef_meuwissen(), inbcoef_quaas(), input(), input_standard(), logdet(), out_to_stream(), and sample(). |
|
|
Definition at line 58 of file pedigree.h. |
|
|
Definition at line 68 of file pedigree.h. Referenced by copyfrom(), input(), input_pedsheet(), out_to_stream(), Pedigree(), release(), sample(), and save_pedsheet(). |
|
|
Definition at line 56 of file pedigree.h. Referenced by copyfrom(), input(), input_pedsheet(), input_standard(), release(), release_pedsheet(), renum(), resize(), sample(), and save_pedsheet(). |
|
|
Definition at line 56 of file pedigree.h. Referenced by copyfrom(), input(), ngroup(), Pedigree(), and sample(). |
|
|
Definition at line 58 of file pedigree.h. Referenced by ainv(), copyfrom(), in_memory(), inbcoef_meuwissen(), inbcoef_quaas(), input_pedsheet(), mat(), out_to_stream(), Pedigree(), rela(), release(), release_pedsheet(), and sample(). |
|
|
Definition at line 58 of file pedigree.h. Referenced by copyfrom(), input_pedsheet(), Pedigree(), release(), sample(), and save_pedsheet(). |
|
|
Definition at line 59 of file pedigree.h. Referenced by input(), input_pedsheet(), Pedigree(), release_pedsheet(), and resize(). |
|
|
Definition at line 67 of file pedigree.h. Referenced by ainv(), inbcoef_meuwissen(), inbcoef_quaas(), input(), input_pedsheet(), input_standard(), logdet(), mat(), out_to_stream(), Pedigree(), rela(), reld(), release_pedsheet(), renum(), resize(), and save_pedsheet(). |
|
|
Definition at line 68 of file pedigree.h. Referenced by copyfrom(), input(), matvec::Population::input_ped(), Pedigree(), and sample(). |
|
|
Definition at line 56 of file pedigree.h. Referenced by ainv(), copyfrom(), inbcoef_meuwissen(), inbcoef_quaas(), input(), input_pedsheet(), input_standard(), logdet(), mat(), out_to_stream(), Pedigree(), rela(), reld(), release(), renum(), sample(), save_pedsheet(), and size(). |
|
|
Definition at line 35 of file pedigree.cpp. |
1.2.16