int ExportMerlinMap (void) { char mkrname[NAMESIZE], tempstr[NAMESIZE]; int i; double currentpos; printf("Which chromosome is this: "); InputLine(buf, BUFFERSIZE); currentpos = 0; // Makes the marker file cfopen ("merlin.map", "w"); fprintf(F, "CHROMOSOME MARKER LOCATION\n"); for (i = 1; i<=numberofmarkers(); i++) { // Remove white spaces in marker name RemoveWhiteSpace(tempstr, GetName(markernames, order[i])); strncpy(mkrname, tempstr, NAMESIZE); fprintf(F, "%-5s %-18s %f\n", buf, mkrname, MarkerDistance(0,i)); } fclose(F); puts("Made Merlin map file"); return 0; }
SQInteger Sq_AskForInput(HSQUIRRELVM v) { char Buffer[4096]; *Buffer = 0; const SQChar *Prompt; sq_getstring(v, 2, &Prompt); Redraw = 1; if(InputLine(Prompt, Buffer, sizeof(Buffer))) sq_pushstring(v, Buffer, -1); else sq_pushnull(v); return 1; }
void ReadLinkageParameterFile(void) { int i; int linenr, locinumber; int numloci, risk, xlink, program; int locus_type, num_alleles, nmarkers; char *traitname; char tmpbuf[256]; FreqList *fl; namelist *nl; printf("Name of parameter file: "); InputLine(buf, BUFFERSIZE); // Deletes old info FreeDataInfo(); DeletePedigreeData(); DeleteParameterData(); cfopen (buf,"r"); linenr = 0; locinumber = 1; nmarkers = 0; // Read line 1 ReadNextNonEmptyLine(); numloci = atoip (igetstr (buf)); risk = geti(); xlink = geti(); program = geti(); if (numloci==0) { printf("WARNING: No loci in parameter file\n"); return; } InitializeFrequencies(numloci); freelist(markernames); markernames = 0; // Read line 2 and 3. Not used yet ReadNextNonEmptyLine(); ReadNextNonEmptyLine(); // Saves the order for later strncpy(tmpbuf, buf, sizeof(tmpbuf)); // Read all locus/traits while (locinumber <= numloci) { ReadNextNonEmptyLine(); locus_type = atoip (igetstr (buf)); num_alleles = geti(); traitname = GetRestOfLine(); switch (locus_type) { case 1 : break; case 3 : // Read a marker locus fl = FrequencyNumber(locinumber); fl->num_alleles = num_alleles; // Read in the allele frequencies ReadNextNonEmptyLine(); fl->frequency[1] = atof(igetstr(buf)); for (i=2; i<= num_alleles; i++) { fl->frequency[i] = getf(); } // Increase the number of markers in the dataset nmarkers++; // Saves the marker name nl = cmalloc(sizeof(namelist)); memset(nl, 0, sizeof(namelist)); if (strlen(traitname)==0) sprintf(nl->name, "Marker %d",locinumber); else { // remove initial # if any traitname +=strspn(traitname, "# ") ; strncpy(nl->name, traitname, sizeof(nl->name)); } addlist(&markernames, nl); break; case 4 : // Read a quantitative trait break; default: printf("Unknown locus type (%d)\nExiting\n", locus_type); } locinumber++; #ifdef debug printf("Found locus (%s) type %d with %d alleles\n", nl->name, locus_type, num_alleles); #endif } ReadNextNonEmptyLine(); // Now reads the recombination fractions for markers ReadNextNonEmptyLine(); if (nmarkers>1) { distance = vector(1,nmarkers-1); distance[1] = atof(igetstr(buf)); for (i = 2; i<nmarkers; i++) distance[i] = atof(getstr()); } ReadNextNonEmptyLine(); ReadNextNonEmptyLine(); fclose(F); // Fixes order order = ivector(1,nmarkers); invorder = ivector(1,nmarkers); OrderMarkers(tmpbuf); }
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); }