/** * mark all places that are reachable */ void pullAndMark(vector<string> &mark, Position b, Position p) { if (outOfBoundary(mark, p) || outOfBoundary(mark, b)) { return; } if (mark[b.x][b.y] == 'V') return; if (isWall(mark[b.x][b.y]) || isWall(mark[p.x][p.y])) return; mark[b.x][b.y] = 'V'; for (int i = 0; i < 4; ++i) { Position newbox(b.x + direction[i][0], b.y + direction[i][1]); Position newperson(newbox.x + direction[i][0], newbox.y + direction[i][1]); pullAndMark(mark, newbox, newperson); } }
void importlinkagepedigree (void) { char minibuf[NAMESIZE]; individual *ind, *ind2; // IDlist *idlist; markerlist *marker; namelist *nl; quanttrait *qt; int i, families, persons, nmarkers, ntraits, code; printf("Number of markers in file: "); InputLine(buf, BUFFERSIZE); nmarkers = atoip(buf); printf("Number of traits in file : "); InputLine(buf, BUFFERSIZE); ntraits = atoip(buf); printf ("Name of linkage pedigree file to input: "); InputLine(buf, BUFFERSIZE); cfopen (buf,"r"); getbuf (); persons = 0; families = 0; if (options->Index[O_CONVERTLINKAGEID]) printf("WARNING: ID's are converted from number to fam-number\n"); while (buf[0] != EOF) { // If empty line then read next line if (!buf[0] || !strpbrk(buf, "0123456789")) { getbuf (); continue; } ind = newperson (); persons++; ind->globalid = persons; ind->localid = persons; strcpy(ind->pedigree, igetstr (buf)); strcpy(ind->id, getstr ()); strcpy(ind->tmpstr1, getstr ()); // Father ID strcpy(ind->tmpstr2, getstr ()); // Mother ID // If conversion of IDs if (options->Index[O_CONVERTLINKAGEID]) { sprintf(minibuf,"%s-%s", ind->pedigree,ind->id); strcpy(ind->id,minibuf); sprintf(minibuf, "%s-%s", ind->pedigree,ind->tmpstr1); strcpy(ind->tmpstr1,minibuf); sprintf(minibuf, "%s-%s", ind->pedigree,ind->tmpstr2); strcpy(ind->tmpstr2,minibuf); } switch (geti ()) { case 1 : ind->sex = S_MALE; break; case 2 : ind->sex = S_FEMALE; break; default : ind->sex = S_UNKNOWN; } // atof(getstr()); for (i = 0 ; i<nmarkers; i++) { marker = cmalloc (sizeof (markerlist)); memset (marker,0,sizeof (markerlist)); marker->allele1 = geti(); marker->allele2 = geti (); addlist(&ind->marker, marker); } // Reading traits for (i = 0 ; i<ntraits; i++) { qt = cmalloc (sizeof (quanttrait)); memset (qt,0,sizeof (quanttrait)); ReadATrait(qt); addlist(&ind->qttrait,qt); } // printf("\n"); getbuf (); } fclose (F); printf ("%d persons from %d pedigree(s) read\n", persons, numberofpedigrees()); code = 0; // Should now fix fathers and mothers forind { ind->father = findperson(ind->tmpstr1); ind->mother = findperson(ind->tmpstr2); // if a person has a father and a mother, then add the // person to the parents lists if (ind->father && ind->mother) { adduniqueidlist (&ind->father->offspring, ind); adduniqueidlist (&ind->father->mate, ind->mother); adduniqueidlist (&ind->mother->offspring, ind); adduniqueidlist (&ind->mother->mate,ind->father); } else if (ind->father || ind->mother) // The person has only one parent { code = 1; sprintf(buf2, "%s has only one parent in pedigree file\n", ind->id); WriteErrorMsg(buf2); } } if (code) printf("ERROR: A least one parent not found in pedigree file\n"); // Fixing sibs forind { for (ind2 = ind->next; ind2; ind2 = ind2->next) { // If same father or mother then add to list of both if (((ind->father == ind2->father) && (ind->father)) || ((ind->mother == ind2->mother) && (ind->mother))) { adduniqueidlist(&ind->sib, ind2); adduniqueidlist(&ind2->sib, ind); } } } // Have now read the file and made the dataset // Should fix the missing parts // This part definately needs some error checking // First set the marker names: for (i=1; i<=nmarkers; i++) { nl = cmalloc (sizeof (namelist)); memset (nl,0,sizeof (namelist)); sprintf(nl->name, "Marker %d",i); addlist(&markernames, nl); } // Then add trait names for (i=1; i<=ntraits; i++) { nl = cmalloc (sizeof (namelist)); memset (nl,0,sizeof (namelist)); sprintf(nl->name, "Trait %d",i); addlist(&traitnames, nl); } InitializeFrequencies(nmarkers); // Initialize order and distances order = ivector(1,nmarkers); invorder = ivector(1,nmarkers); distance = vector(1, nmarkers-1); for (i=1; i<=nmarkers; i++) { order[i] = i; invorder[i] = i; } for (i=1; i<nmarkers; i++) distance[i] = InverseMapFunction(0.1); }