void MessageOut::writeString(const string &string, Sint16 length){ Uint16 stringLength = string.length(); if (length < 0) { // Write the length at the start if not fixed. write2(stringLength); length = stringLength; } else if (length < stringLength) { stringLength = length; // Make sure the length of the string is no longer than specified } expandData((this->pos) + length); memcpy((this->myData) + (this->pos), string.c_str(), stringLength); // Write the actual string. if (length > stringLength) // Pad remaining space with zeros. { memset((this->myData) + (this->pos) + stringLength, '\0', length - stringLength); } this->pos += length; }
void MessageOut::write4(Uint32 value){ expandData((this->pos) + 4); Uint32 tmp = SDL_SwapBE32(value); memcpy((this->myData)+(this->pos), &tmp, 4); this->pos += 4; }
void MessageOut::write1(char value){ expandData((this->pos) + 1); myData[this->pos] = value; this->pos += 1; }
void MessageOut::write2(Uint16 value){ expandData((this->pos) + 2); Uint16 tmp = SDL_SwapBE16(value); memcpy((this->myData)+(this->pos), &tmp, 2); this->pos += 2; }
void scanFile(Args *args, FILE *fp){ char *line, *name, *token, *chr; size_t n; int status, len, l, start, end; int pos[2], p, i, tp, tn; Data *data; double ll, ul, cf; line = NULL; while((status = getline(&line,&n,fp)) != -1){ if(line[0] != '#') break; } if(!args->p) printf("# Int\tChr\tStart\tEnd\tLen\t[%%\t%%\t%%]\t[cM/Mb\tcM/Mb\tcM/Mb]\n"); data = newData(1,args->o); while(status != -1){ data->n = 0; name = estrdup(strtok(line,"\t")); /* read name of region */ chr = estrdup(strtok(NULL,"\t")); /* read chromosome */ start = intVal(strtok(NULL,"\t")); /* start position */ end = intVal(strtok(NULL,"\t")); /* end position */ len = end - start + 1; /* length of region in bp */ tp = 0; /* total positives */ tn = 0; /* total negatives */ while((token = strtok(NULL,"\t")) != NULL){ /* iterating across experiments */ if(data->n + 1 == data->maxN) expandData(data); l = strlen(token); p = 0; for(i=0;i<l;i++){ /* determine positions of commata */ if(token[i] == '|'){ token[i] = '\0'; pos[p++] = i+1; } } data->numMol[data->n] = atoi(token); /* number of molecules */ token += pos[0]; data->numPos[data->n] = atoi(token); token -= pos[0]; token += pos[1]; data->numNeg[data->n] = atoi(token); token -= pos[1]; tp += data->numPos[data->n]; tn += data->numNeg[data->n]; data->n++; } if(args->d){ printData(name,len,data); exit(0); } if(args->p && tp){ printLikFun(data, args); return; } cf = crossoverFreq(data); data->mlXover = cf; data->ci = args->c; ul = upperCL(data,cf); ll = lowerCL(data,cf); /* convert to centi-Morgans */ ll *= 100; cf *= 100; ul *= 100; if(cf < 100){ printf("%s\t%s\t%d\t%d\t%*d\t%.3f\t%.3f\t%.3f",name,chr,start,end,4,len,ll,cf,ul); /* convert to cM per Mb */ ll = ll / len * 1000000; cf = cf / len * 1000000; ul = ul / len * 1000000; printf("\t%.3f\t%.3f\t%.3f\n",ll,cf,ul); }else printf("%s\t%d\t%d\t%*d\tNA\tNA\tNA\tNA\tNA\tNA\n",name,start,end,4,len); status = getline(&line,&n,fp); free(name); } free(line); freeData(data); }