int ResourceManager::initResource() { unsigned int targetServer; string logStr = "initialize the FileInfo::serverList and SubServer::fileList"; serverLog.writeResourceLog(logStr); for (unsigned int i = 0; i < resourceNum; i++) { targetServer = i % subServerNum; fileList[i]->addNewServer(targetServer); lb->addNewFile(i, targetServer); logStr = "put file " + numToString(i) + " to server " + numToString(targetServer); serverLog.writeResourceLog(logStr); } return 0; }
int LFRUManager::readFile(unsigned int fileId, unsigned int serverId) { string logStr; for (unsigned int i = 0; i < LFRUFileList.size(); i++) { if (LFRUFileList[i]->fileId == fileId && LFRUFileList[i]->serverId == serverId) { LFRUFileList[i]->count++; gettimeofday(&(LFRUFileList[i]->vtime), NULL); logStr = " the count of file " + numToString(fileId) + " in server[" + numToString(serverId) + "] is " + numToString(LFRUFileList[i]->count); break; } } serverLog.writeResourceLog(logStr); return 0; }
void ofxUINumberDialer::update() { if(useReference) { setTextString(numToString(abs(*value), precision, numOfPrecisionZones, '0')); } }
BOOL MBVersion::needUpdate() { phoneHome(); unsigned int tVer,pVer; tVer = thisVersion(); logger.log("tVer:"+numToString(tVer)); pVer = publicVersion(); logger.log("pVer:"+numToString(pVer)); if (tVer < pVer) { return TRUE; } else { return FALSE; } }
std::string GraphData::makeGraphPacket() { std::string data; std::string datastream; graphMapMutex_.lock( ); std::cerr << "mutex locked" << std::endl; std::map< uint32_t, std::map< uint32_t, GraphInfo*> >::iterator ritr; std::map< uint32_t, GraphInfo* >::iterator citr; std::map< uint32_t, GraphInfo* >::iterator tmp; uint32_t edges = 0; edgeLifeMutex_.lock( ); for( ritr = graphMap_.begin(); ritr != graphMap_.end(); ++ritr ) { for( citr = ritr->second.begin(); citr != ritr->second.end(); ) { tmp = citr; //Needed to be able to delete the current element in all cases. ++citr; //edge exist //recalculate weight time_t currentTime = time( NULL ); if( (currentTime - tmp->second->lastAccess) >= edgeLife_ ) { //edge past life expectancy - time to die Edge edge; edge.ipA = ritr->first; edge.ipB = tmp->first; deadNodesMutex_.lock( ); deadNodes_.push_back( edge ); deadNodesMutex_.unlock(); delete tmp->second; (ritr->second).erase( tmp->first ); continue; } ++edges; data += numToString( ritr->first ); data += numToString( tmp->first ); data += numToString( htonl(calculateWeight((tmp->second)->weights, tmp->second->lastAccess)) ); } } edgeLifeMutex_.unlock( ); graphMapMutex_.unlock( ); std::cout << "Number of Edges: " << edges << std::endl; datastream += numToString( htonl(edges) ); datastream += data; return datastream; }
GenRet BlockStmt::codegen() { GenInfo* info = gGenInfo; FILE* outfile = info->cfile; GenRet ret; codegenStmt(this); if( outfile ) { if (blockInfo) { if (blockInfo->isPrimitive(PRIM_BLOCK_WHILEDO_LOOP)) { std::string hdr = "while (" + codegenValue(blockInfo->get(1)).c + ") "; info->cStatements.push_back(hdr); } else if (blockInfo->isPrimitive(PRIM_BLOCK_DOWHILE_LOOP)) { info->cStatements.push_back("do "); } else if (blockInfo->isPrimitive(PRIM_BLOCK_FOR_LOOP)) { std::string hdr = "for (;" + codegenValue(blockInfo->get(1)).c + ";) "; info->cStatements.push_back(hdr); } else if (blockInfo->isPrimitive(PRIM_BLOCK_XMT_PRAGMA_FORALL_I_IN_N)) { std::string hdr = "_Pragma(\"mta for all streams "; hdr += codegenValue(blockInfo->get(1)).c; hdr += " of "; hdr += codegenValue(blockInfo->get(2)).c; hdr += "\")\n"; info->cStatements.push_back(hdr); } } if (this != getFunction()->body) info->cStatements.push_back("{\n"); if (!(fNoRepositionDefExpr)) { Vec<BaseAST*> asts; collect_top_asts(this, asts); forv_Vec(BaseAST, ast, asts) { if (DefExpr* def = toDefExpr(ast)) { if (def->parentExpr == this) { if (!toTypeSymbol(def->sym)) { if (fGenIDS && isVarSymbol(def->sym)) info->cStatements.push_back("/* " + numToString(def->sym->id) + " */ "); def->sym->codegenDef(); } } } } } body.codegen(""); if (blockInfo && blockInfo->isPrimitive(PRIM_BLOCK_DOWHILE_LOOP)) { std::string ftr = "} while (" + codegenValue(blockInfo->get(1)).c + ");\n"; info->cStatements.push_back(ftr); } else if (this != getFunction()->body) { std::string end = "}"; CondStmt* cond = toCondStmt(parentExpr); if (!cond || !(cond->thenStmt == this && cond->elseStmt)) end += "\n"; info->cStatements.push_back(end); } } else {
void codegenStmt(Expr* stmt) { GenInfo* info = gGenInfo; FILE* outfile = info->cfile; info->lineno = stmt->linenum(); info->filename = stmt->fname(); if( outfile ) { if (stmt->linenum() > 0) { if (printCppLineno) { info->cStatements.push_back( "/* ZLINE: " + numToString(stmt->linenum()) + " " + stmt->fname() + " */\n"); } } if (fGenIDS) info->cStatements.push_back("/* " + numToString(stmt->id) + "*/ "); } }
std::string CodeGenerator::workelement(int n) { casadi_assert(n>=0); if (n==0) { return "*w"; } else { return "w[+" + numToString(n) + "]"; } }
int ResourceManager::resourceRequest(unsigned int clientId, unsigned int fileId, unsigned int &filePlayLen) { string logStr = "client [" + numToString(clientId) + "] request file " + numToString(fileId); serverLog.writeResourceLog(logStr); //get the sub servers that contain the fileId vector<unsigned int >containList; filePlayLen = fileList[fileId]->filePlayLen; logStr = "file " + numToString(fileId) + " can play " + numToString(filePlayLen) + " secs"; serverLog.writeResourceLog(logStr); containList.clear(); containList.push_back(fileId % subServerNum); //choose one by random int targetServer; logStr = "find the best server to server client[" + numToString(clientId) + "]"; serverLog.writeResourceLog(logStr); targetServer = lb->getMinLoadServer(containList); if (targetServer < 0) { logStr = "no server to server client[" + numToString(clientId) + "]"; serverLog.writeResourceLog(logStr); return targetServer; } logStr = "the ResourceManager chose server[" + numToString(targetServer) + "] to server it"; serverLog.writeResourceLog(logStr); //change the load of the chose sub server lb->increaseLoad(targetServer); //return the id of the chose sub server return targetServer; }
std::string CodeGenerator::work(int n) { if (n<0) { return "0"; } else if (n==0) { return "w"; } else { return "w+" + numToString(n); } }
std::string GraphData::makeDeadNodePacket() { std::string data; std::string datastream; int edges = 0; std::deque< Edge >::iterator itr; deadNodesMutex_.lock( ); for( itr = deadNodes_.begin(); itr != deadNodes_.end(); ++itr ) { edges++; data += numToString( itr->ipA ); data += numToString( itr->ipB ); } deadNodes_.clear(); deadNodesMutex_.unlock( ); datastream = numToString( htonl( edges ) ); datastream += data; return datastream; }
///////////////////////////////////////////////////////////////////////////// // CConfigDisplay message handlers BOOL CConfigDisplay::OnInitDialog() { AutoLog alog("CCD::OnInitDialog"); CPropertyPage::OnInitDialog(); m_FontPanel.Initialize(); m_FontTitles.Initialize(); m_FontColHdr.Initialize(); AutoBuf buf(5); int i; m_SizeTitles.ResetContent(); m_SizePanel.ResetContent(); m_SizeColHdr.ResetContent(); m_BorderWidth.ResetContent(); for (i = 5 ; i < 40; ++i) { sprintf(buf.p, "%d", i); m_SizeTitles.AddString(buf.p); m_SizePanel.AddString(buf.p); m_SizeColHdr.AddString(buf.p); } for (i = 0 ; i < 40; ++i) { sprintf(buf.p, "%d", i); m_BorderWidth.AddString(buf.p); } readSkins(); initFontSels(); int sel = m_SkinList.SelectString(-1, m_sSkinName); m_SkinList.SetCurSel(sel); OnSkinChoose(); sel = m_BorderWidth.SelectString(-1, numToString(m_vBorderWidth)); m_BorderWidth.SetCurSel(sel); showSample(); m_Modified = FALSE; #ifndef _DEBUG m_MakeDefault.ShowWindow(SW_HIDE); #endif EnableDisable(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
int LFRUManager::resourceRequest(unsigned int clientId, unsigned int fileId, unsigned int &filePlayLen) { //first get the information of fileId string logStr = "client [" + numToString(clientId) + "] request file " + numToString(fileId); serverLog.writeResourceLog(logStr); //get the sub servers that contain the fileId vector<unsigned int >containList; filePlayLen = fileList[fileId]->filePlayLen; logStr = "file " + numToString(fileId) + " can play " + numToString(filePlayLen) + " secs"; serverLog.writeResourceLog(logStr); containList.clear(); getServerList(fileId, containList); //output the containList ostringstream oslogStr; oslogStr << "the containList of file " << fileId << ":"; for (unsigned int i = 0; i < containList.size(); i++) { oslogStr << containList[i] << " "; } logStr = oslogStr.str(); serverLog.writeResourceLog(logStr); //then find the best sub server to serve it int targetServer; targetServer = lb->getMinLoadServer(containList); if (targetServer < 0) { logStr = "can't find a sub server to serve client " + numToString(clientId); serverLog.writeResourceLog(logStr); return targetServer; } logStr = "the LFRUManager chose server[" + numToString(targetServer) + "] to server it"; serverLog.writeResourceLog(logStr); //and then change the attribute of fileId and target server readFile(fileId, targetServer); lb->increaseLoad(targetServer); return targetServer; }
void ofxUINumberDialer::setValue(float _value) { if(_value > max) { _value = max; } else if(_value < min) { _value = min; } *value = _value; setTextString(numToString(abs(*value), precision, numOfPrecisionZones, '0')); }
void ofxUINumberDialer::setParent(ofxUIWidget *_parent) { parent = _parent; rect->height = label->getPaddingRect()->height+padding*2.0; rect->width = label->getPaddingRect()->width+padding*3.0; ofxUIRectangle *labelrect = label->getRect(); labelrect->setX(padding*2.0); float h = labelrect->getHeight(); float ph = rect->getHeight(); labelrect->y = ph/2.0 - h/2.0; paddedRect->height = rect->height+padding*2.0; paddedRect->width = rect->width+padding*2.0; setTextString(numToString(abs(*value), precision, numOfPrecisionZones, '0')); }
/* Function to write the data*/ void *write_data(void *fd) { struct Parameters *args = (struct Parameters *)fd; char buffer[1024]; char number[10]; bzero(buffer, 1024); char letter[1024]; int i = 0; int j = 0; while(1) { while(1) { letter[i] = getchar(); if(letter[i] == '\n') { buffer[j] = '\0'; letter[i] = '\0'; j = 0; i = 0; break; } else { bzero(number, 10); strcpy(number, numToString(encrypt((int)letter[i], args->serverE, args->serverN))); if(strlen(buffer) == 0) { strcpy(buffer, number); } else { strcat(buffer, number); } j += strlen(number); buffer[j] = ' '; j++; } i++; } write(args->connfd, buffer, strlen(buffer)); if(strcmp(letter, "quit") == 0) { break; } bzero(letter, 1024); bzero(buffer, 1024); } close(args->connfd); exit(0); }
int main(int argc, char const *argv[]) { char num[100]; scanf("%s", num); int sum = 0; int i; for (i = 0; i < strlen(num); ++i) { sum += getNum(num[i]); } // printf("%d\n", sum); numToString(sum); return 0; }
int numToString(int num) { int result; int numToChar(int num); if ( (num / 10) != 0) { numToString( num / 10); printf(" "); numToChar(num % 10); } else { result = num %10; numToChar(result); } return 0; }
bool I2SAudioCapDevice::OnReadEvent() { int ret=-1; struct timeval ts; //state is not ok return if (_isStart == false) { return true; } ret = ioctl (_deviceFD, PCM_READ_PCM, &_pcm_record); #ifdef PCMDEBUG int readsize=0; if (pcmfile != NULL) { readsize = fread (_pcm_record.pcmbuf, 1, _pcm_record.size, pcmfile); if (readsize != _pcm_record.size) { DEBUG ("end of read file"); fclose (pcmfile); exit(1); } } #endif if (_dropFrame > 0) { _dropFrame --; return true; } //TODO(recardo): detect audio event here if ((_pcm_record.size>0) && (ret!=-1)) { SendDataToCarriers((uint8_t*)_pcm_record.pcmbuf, (uint32_t)_pcm_record.size, 0, HW_DATA_AUDIO); string rmsValue= numToString(DetectSoundEvent((uint8_t*)_pcm_record.pcmbuf, (uint32_t)_pcm_record.size), 2); if (IsRMSEnabled()) { NotifyObservers(ACM_RMSVALUE, rmsValue); } } else DEBUG ("_pcm_record.size == 0"); _pcm_record.size = 0; return true; }
bufManager::bufManager(Client *client,unsigned int blockSize,unsigned int totalBufSize){ owner = client; _blockSize = blockSize; _totalBufSize = totalBufSize; _blockNum = (totalBufSize%blockSize ==0)?(totalBufSize/blockSize):(totalBufSize/blockSize + 1); _clientId = client->getClientId(); bufRecordFile = client->getBufRecordFile(); int j= bufRecordFile.find('.'); string bufRecord=(bufRecordFile).substr(0,j) + numToString(_clientId) + bufRecordFile.substr(j); _needRecord = client->needRecord(); if(_needRecord == true){ bufOfs.open(bufRecord.c_str(),ifstream::in | ifstream::trunc); if(bufOfs.is_open() == false){ cout<<"open the file error"<<endl; exit(1); } pthread_mutex_init(&_osmutex,NULL); } }
void ofxUINumberDialer::mouseDragged(int x, int y, int button) { if(hit) { *value += zoneMultiplier*(hitPoint.y-y); if(*value > max) { *value = max; } else if(*value < min) { *value = min; } hitPoint = ofPoint(x,y); setTextString(numToString(abs(*value), precision, numOfPrecisionZones, '0')); triggerEvent(this); state = OFX_UI_STATE_DOWN; } else { state = OFX_UI_STATE_NORMAL; } stateChange(); }
int LFRUManager::duplicateMethod(unsigned int serverId) { unsigned int needSpreadFile; double minWeight, curWeight; minWeight = 1000000.0; string logStr = "server[" + numToString(serverId) + "] is overload"; serverLog.writeSystemLog(logStr); //get the file need to spread struct timeval callTime; gettimeofday(&callTime, NULL); ostringstream logStream; for (unsigned int i = 0; i < LFRUFileList.size(); i++) { if (LFRUFileList[i]->serverId != serverId) continue; logStream<<"for server "<<serverId<<",file "<<LFRUFileList[i]->fileId<<endl; logStream<<"\tcallTime:"<<callTime.tv_sec<<":"<<callTime.tv_usec<<" "; logStream<<"t0:"<<t0.tv_sec<<":"<<t0.tv_usec<<" "; logStream<<"vtime:"<<LFRUFileList[i]->vtime.tv_sec<<":"<< LFRUFileList[i]->vtime.tv_usec<<" "; logStream<<"count:"<<LFRUFileList[i]->count<<" "; double fk = getTimeSlips(&callTime, &t0) / (double(LFRUFileList[i]->count * 1000000.0)); double rk = getTimeSlips(&callTime, &(LFRUFileList[i]->vtime)) / 1000000.0; curWeight = period - getTimeSlips(&callTime, &t0) / 1000000.0; curWeight = curWeight * rk / (double) period; curWeight += getTimeSlips(&callTime, &t0) * fk / (1000000.0 * period); logStream<<"Fk:"<<fk<<",rk:"<<rk<<",weight : "<<curWeight<<" "; //logStr = "in server[" + numToString(serverId) + "],the count of file " + //numToString(DWFileList[i]->fileId) + " is " + numToString(curCount); //serverLog.writeResourceLog(logStr); if (minWeight > curWeight) { minWeight = curWeight; needSpreadFile = LFRUFileList[i]->fileId; } logStream<<" minWeight = "<<minWeight<<",need spread file ="<<needSpreadFile<<endl; } serverLog.writeResourceLog(logStream.str()); logStr = "server[" + numToString(serverId) + "] chose file[" + numToString(needSpreadFile) + "] to spread"; serverLog.writeResourceLog(logStr); //choose the machine that have the minLoad and don't have the file vector<unsigned int > containList; getServerList(needSpreadFile, containList); vector<unsigned int> noList; noList.clear(); for (unsigned int i = 0; i < subServerNum; i++) { bool isContain = false; for (unsigned int j = 0; j < containList.size(); j++) { if (containList[j] == i) { isContain = true; break; } } if (isContain == false) { noList.push_back(i); } } int targetServer = lb->getMinLoadServer(noList); if (targetServer < 0) { logStr = "no server to duplicate"; serverLog.writeResourceLog(logStr); return -1; } logStr = "the spread target server is server[" + numToString(targetServer) + "]"; serverLog.writeResourceLog(logStr); //should have some transport time lb->addFileToSubServer(needSpreadFile, targetServer); addNewServer(needSpreadFile, targetServer); LFRUFileInfo *fileInfo = new LFRUFileInfo(needSpreadFile, targetServer); if (fileInfo != NULL) LFRUFileList.push_back(fileInfo); lb->printFileList(); return 0; }
internal int32 lettersInNumber(int32 num) { char* string = numToString(num); return numCharsInString(string); }
void ServerMessageProcessor::process_crack_request(LSP_Packet& packet) { fprintf(stderr, "ServerMessageProcessor:: Processing crack Request from %s : %d\n", packet.getHostname(), packet.getPort()); /*crack request to server comes from request and is of the format c sha len */ /* Send ack to request */ LSP_Packet ack_packet = create_ack_packet(packet); ConnInfo* connInfo = get_conn_info(packet.getConnId()); connInfo->add_to_outMsgs(ack_packet); fprintf(stderr, "ServerMessageProcessor:: Pushing ACK packet to Outbox for conn_id: %u\n", packet.getConnId()); if(testing) return; /* Parse and get appropriate entries about the request */ uint8_t* bytes = packet.getBytes(); string s((char*)bytes); stringstream iss(s); string ignore; iss >> ignore; string hash; iss >> hash; string startS; iss >> startS; string endS; iss >> endS; int length = strlen(startS.c_str()); /* Get the least busy worker */ vector<int> workers = get_least_busy_workers(1); /* Check some conditions before assigning to the worker */ if(workers.empty() || hash.length() != 40) { LSP_Packet c_pkt(create_not_found_packet(connInfo)); connInfo->add_to_outMsgs(c_pkt); return; } if(length == 0) { LSP_Packet c_pkt(create_not_found_packet(connInfo)); connInfo->add_to_outMsgs(c_pkt); return; } if(length > MAX_PWD_LTH) { LSP_Packet c_pkt(create_not_found_packet(connInfo)); connInfo->add_to_outMsgs(c_pkt); return; } if(length<4) { /*Assign only 1 worker. Sending message to more workers will take more time than processing by a single worker for 17576 entries.*/ /* Get least busy worker and create an empty packet with that connId*/ int worker = workers[0]; ConnInfo *cInfo = get_conn_info(worker); int end = pow(26,length)-1; string startString = numToString(0,length); string endString = numToString(end,length); string data = "c " + hash + " "+startString + " " +endString; WorkerInfo w(cInfo->getConnectionId(), 0, hash, startString, endString); /* Send crack request to worker. */ send_crack_worker_request(packet, cInfo,w, data.c_str()); } else if(length >= 4) { int start = 0; int numPoss = pow(26,length)-1; vector<int> workers = get_least_busy_workers(5); int workersCount = workers.size(); int each = ceil(numPoss/workersCount); /* Split the work among the workers, update the request and worker information and send crack request to worker */ for(int i=0; i<workersCount; ++i) { ConnInfo* cInfo = get_conn_info(workers[i]); int last; if(start+each>numPoss) last = numPoss; else last = start+each; string startString = numToString(start,length); string endString = numToString(last,length); string data = "c " + hash + " " + startString + " " +endString; WorkerInfo w(cInfo->getConnectionId(), 0, hash, startString, endString); send_crack_worker_request(packet, cInfo, w, data.c_str()); start = start + each + 1; } } }
int linkGNMain(int argc, char** argv) { linkGNOptions(argc, argv); string gpFileRoot = stripExtension(opt::gpFile); std::ofstream* gpOutFile; std::ofstream* refLinkFile; std::ofstream* goBedFile; std::ofstream* fullBedFile; if (opt::NtoN) { goBedFile = new std::ofstream(gpFileRoot + opt::out + "_NtoN_GOBed.txt"); fullBedFile = new std::ofstream(gpFileRoot + opt::out + "_NtoN_FullBed.txt"); gpOutFile = new std::ofstream(gpFileRoot + opt::out + "_NtoN_RefGene.gp"); refLinkFile = new std::ofstream(gpFileRoot + opt::out + "_NtoN_RefLink.gp"); } else { goBedFile = new std::ofstream(gpFileRoot + opt::out + "_GOBed.txt"); fullBedFile = new std::ofstream(gpFileRoot + opt::out + "_FullBed.txt"); gpOutFile = new std::ofstream(gpFileRoot + opt::out + "_RefGene.gp"); refLinkFile = new std::ofstream(gpFileRoot + opt::out + "_RefLink.gp"); } string line; int geneNum = 1; // Load David Brawand's assignment of orthologs // Mapping from cichlid IDs to a zebrafish homolog (or medaka // stickleback, tetraodon, if zebrafish not available) std::map<string,string> cichlidHomolog; std::map<string,string> cichlidDanRerCopyNum; if (opt::v2orthologsFile != "") { std::cerr << "Reading the v2 full orthologs file:" << std::endl; std::ifstream* ocFile = new std::ifstream(opt::v2orthologsFile); while (getline(*ocFile, line)) { std::vector<string> orthVec = split(line, '\t'); int c = getSpeciesColumn(opt::species); if (orthVec[c] != "NA") { if (orthVec[8] != "NA") { cichlidHomolog[orthVec[c]] = orthVec[8]; cichlidDanRerCopyNum[orthVec[c]] = "1-1"; } // Zebrafish else if (orthVec[5] != "NA") { cichlidHomolog[orthVec[c]] = orthVec[5]; } // Medaka else if (orthVec[7] != "NA") { cichlidHomolog[orthVec[c]] = orthVec[7]; } // Stickleback else if (orthVec[6] != "NA") { cichlidHomolog[orthVec[c]] = orthVec[6]; } // Tetraodon else { cichlidHomolog[orthVec[c]] = "novelCichlidGene"; } } else { continue; } } ocFile->close(); } if (opt::v1orthologousClustersFile != "") { int copiesInCichlid = 0; int copiesInDanRer = 0; string cichlidGene = ""; string homologGene = ""; std::cerr << "Reading the v1 orthologous cluster file: " << std::endl; std::ifstream* ocFile = new std::ifstream(opt::v1orthologousClustersFile); while (getline(*ocFile, line)) { std::vector<string> idAndNum = split(line, '\t'); string thisLineGeneID = idAndNum[0]; int thisLineGeneClusterNumber = atoi(idAndNum[1].c_str()); // Another line for the same cluster if (thisLineGeneClusterNumber == geneNum) { if (thisLineGeneID.substr(0,2) == opt::species) { if (cichlidGene == "") { // First copy in the cichlid species (e.g. mz) cichlidGene = thisLineGeneID; } else { // There is more than one copy in the cichlid if (homologGene != "") { if (copiesInDanRer <= 1 || opt::NtoN) { attemptMappingUpdate(cichlidHomolog, cichlidGene, homologGene + "/" + numToString(copiesInCichlid)); if (copiesInDanRer == 1) cichlidDanRerCopyNum[cichlidGene] = "N-1"; else if (copiesInDanRer > 1) cichlidDanRerCopyNum[cichlidGene] = "N-N"; } cichlidGene = thisLineGeneID; } } copiesInCichlid++; } else if (thisLineGeneID.substr(0,6) == "ENSDAR") { copiesInDanRer++; if (homologGene == "") { homologGene = thisLineGeneID; } else { if (rand() < 0.5) homologGene = thisLineGeneID; // 50% chance of using this zfish copy (hacky!!!) } } else if (thisLineGeneID.substr(0,6) == "ENSGAC") { if (homologGene == "") { homologGene = thisLineGeneID; } } else if (thisLineGeneID.substr(0,6) == "ENSORL") { if (homologGene == "" || homologGene.substr(0,6) == "ENSGAC") { homologGene = thisLineGeneID; } } else if (thisLineGeneID.substr(0,6) == "ENSTNI") { if (homologGene == "") { homologGene = thisLineGeneID; } } // std::cerr << atoi(idAndNum[1].c_str()) << "\t" << geneNum << std::endl; } else { // First line for a new cluster read // so first add the mapping for the previous cluster if (cichlidGene != "" && homologGene != "") { assert(copiesInCichlid > 0); if (copiesInDanRer == 1) { if (copiesInCichlid == 1) { cichlidDanRerCopyNum[cichlidGene] = "1-1"; attemptMappingUpdate(cichlidHomolog, cichlidGene,homologGene); } else if (copiesInCichlid > 1) { cichlidDanRerCopyNum[cichlidGene] = "N-1"; attemptMappingUpdate(cichlidHomolog, cichlidGene,homologGene + "/" + numToString(copiesInCichlid)); } } else if (copiesInDanRer > 1) { if (copiesInCichlid == 1) { cichlidDanRerCopyNum[cichlidGene] = "1-N"; if (opt::NtoN) attemptMappingUpdate(cichlidHomolog, cichlidGene,homologGene); } else if (copiesInCichlid > 1) { cichlidDanRerCopyNum[cichlidGene] = "N-N"; if (opt::NtoN) attemptMappingUpdate(cichlidHomolog, cichlidGene,homologGene + "/" + numToString(copiesInCichlid)); } } else { if (copiesInCichlid == 1) { attemptMappingUpdate(cichlidHomolog, cichlidGene,homologGene); } else if (copiesInCichlid > 1) { attemptMappingUpdate(cichlidHomolog, cichlidGene,homologGene + "/" + numToString(copiesInCichlid)); } } } // then start looking through the next cluster cichlidGene = ""; homologGene = ""; copiesInDanRer = 0; copiesInCichlid = 0; geneNum = thisLineGeneClusterNumber; if (thisLineGeneID.substr(0,2) == opt::species) { cichlidGene = thisLineGeneID; } else if (thisLineGeneID.substr(0,6) == "ENSDAR") { copiesInDanRer++; homologGene = thisLineGeneID; } else if (thisLineGeneID.substr(0,6) == "ENSGAC") { homologGene = thisLineGeneID; } else if (thisLineGeneID.substr(0,6) == "ENSORL") { homologGene = thisLineGeneID; } else if (thisLineGeneID.substr(0,6) == "ENSTNI") { homologGene = thisLineGeneID; } } } ocFile->close(); } if (opt::sepByCopyNumberPrefix != "") { std::ofstream* OneOneFile = new std::ofstream(opt::sepByCopyNumberPrefix + "_1-1.txt"); std::ofstream* NOneFile = new std::ofstream(opt::sepByCopyNumberPrefix + "_N-1.txt"); std::ofstream* OneNFile = new std::ofstream(opt::sepByCopyNumberPrefix + "_1-N.txt"); std::ofstream* NNFile = new std::ofstream(opt::sepByCopyNumberPrefix + "_N-N.txt"); for (std::map<string, string>::iterator it = cichlidDanRerCopyNum.begin(); it != cichlidDanRerCopyNum.end(); it++) { if (it->second == "1-1") { *OneOneFile << it->first << std::endl; } else if (it->second == "N-1") { *NOneFile << it->first << std::endl; } else if (it->second == "1-N") { *OneNFile << it->first << std::endl; } else if (it->second == "N-N") { *NNFile << it->first << std::endl; } } } // Load gene names and descriptions from ENSEMBL std::map<string,string> ensGeneMap; std::map<string,string> ensGeneDescriptionMap; std::map<string,string> ensEntrezMap; if (!opt::ensGeneFile.empty()) { std::ifstream* egFile = new std::ifstream(opt::ensGeneFile); while (getline(*egFile, line)) { std::vector<string> ensGene = split(line, '\t'); if (ensGene.size() == 4) { ensGeneMap[ensGene[0]] = ensGene[3]; ensGeneDescriptionMap[ensGene[0]] = ensGene[2]; // Sometimes there are two Entrez records for one Ensembl gene, the first Entrez record tends to be the more informative one if ( ensEntrezMap.find(ensGene[0]) == ensEntrezMap.end() ) { if (ensGene[1] != "") {ensEntrezMap[ensGene[0]] = ensGene[1]; } else { ensEntrezMap[ensGene[0]] = "0"; } } } else if (ensGene.size() == 3) { ensGeneMap[ensGene[0]] = "NA"; if (ensGene[2] != "") { ensGeneDescriptionMap[ensGene[0]] = ensGene[2]; } else { ensGeneDescriptionMap[ensGene[0]] = "no description: " + ensGene[0]; } // Sometimes there are two Entrez records for one Ensembl gene, the first Entrez record tends to be the more informative one if ( ensEntrezMap.find(ensGene[0]) == ensEntrezMap.end() ) { if (ensGene[1] != "") {ensEntrezMap[ensGene[0]] = ensGene[1]; } else { ensEntrezMap[ensGene[0]] = "0"; } } } else { //std::cerr << ensGene.size() << std::endl; print_vector_stream(ensGene, std::cerr); } // std::cout << ensGene[0] << "\t" << ensGene[2] << std::endl; } } // Go through the gene prediction file and generate the final outputs std::ifstream* gpFile = new std::ifstream(opt::gpFile); int countNovel = 1; int countUnknown = 1; int countNotInEnsembl = 1; while (getline(*gpFile, line)) { std::vector<string> gpVec = split(line, '\t'); if ( cichlidHomolog.count(gpVec[0]) == 1) { std::vector<string> ensembl = split(cichlidHomolog[gpVec[0]], '/'); std::vector<string> myNameVec = split(gpVec[0], '.'); std::string nameWdots = gpVec[0]; gpVec[0] = myNameVec[0] + "_" + myNameVec[1] + "_" + myNameVec[2] + "_" + myNameVec[3]; if ( ensGeneMap.find(ensembl[0]) != ensGeneMap.end() ) { if (ensembl.size() == 1) { std::cout << nameWdots << "\t" << ensembl[0] << "\t" << ensEntrezMap[ensembl[0]] << "\t" << ensGeneMap[ensembl[0]] << std::endl; gpVec[11] = ensGeneMap[ensembl[0]]; print_vector(gpVec, *gpOutFile); *refLinkFile << ensGeneMap[ensembl[0]] << "\t" << ensGeneDescriptionMap[ensembl[0]] << "\t" << gpVec[0] << "\tNP_X\t77\t88\t" << ensEntrezMap[ensembl[0]] << "\t0" << std::endl; *fullBedFile << gpVec[1] << "\t" << gpVec[3] << "\t" << gpVec[4] << "\t" << ensEntrezMap[ensembl[0]] << "\t0\t" << gpVec[2] << std::endl; if (ensEntrezMap[ensembl[0]] != "0") { *goBedFile << gpVec[1] << "\t" << gpVec[3] << "\t" << gpVec[4] << "\t" << ensEntrezMap[ensembl[0]] << "\t0\t" << gpVec[2] << std::endl; } } else { std::cout << nameWdots << "\t" << ensembl[0] << "\t" << ensEntrezMap[ensembl[0]] << "\t" << ensGeneMap[ensembl[0]] << "/" << ensembl[1] << std::endl; gpVec[11] = ensGeneMap[ensembl[0]]+"/"+ensembl[1]; print_vector(gpVec, *gpOutFile); *refLinkFile << ensGeneMap[ensembl[0]] << "/" << ensembl[1] << "\t" << ensGeneDescriptionMap[ensembl[0]] << "\t" << gpVec[0] << "\tNP_X\t77\t88\t" << ensEntrezMap[ensembl[0]] << "\t0" << std::endl; *fullBedFile << gpVec[1] << "\t" << gpVec[3] << "\t" << gpVec[4] << "\t" << ensEntrezMap[ensembl[0]] << "\t0\t" << gpVec[2] << std::endl; if (ensEntrezMap[ensembl[0]] != "0") { *goBedFile << gpVec[1] << "\t" << gpVec[3] << "\t" << gpVec[4] << "\t" << ensEntrezMap[ensembl[0]] << "\t0\t" << gpVec[2] << std::endl; } } } else if (ensembl[0] == "novelCichlidGene") { std::cout << nameWdots << "\t" << ensembl[0] << "\t0" << "\t" << opt::species + ".novel." + numToString(countNovel) << std::endl; gpVec[11] = opt::species + ".novel." + numToString(countNovel); countNovel++; print_vector(gpVec, *gpOutFile); *refLinkFile << opt::species + ".novel." + numToString(countNovel) << "\t" << "novel gene found only in cichlids" << "\t" << gpVec[0] << "\tNP_X\t77\t88\t" << "0" << "\t0" << std::endl; } else { std::cout << nameWdots << "\t" << "noOrthologAssigned" << "\t" << "0" << "\t" << opt::species + ".orthologNotInEnsembl." + numToString(countNotInEnsembl) << std::endl; *refLinkFile << opt::species + ".orthologNotInEnsembl." + numToString(countUnknown) << "\t" << "ortholog from Brawand data not foud in Ensembl v75" << "\t" << gpVec[0] << "\tNP_X\t77\t88\t" << "0" << "\t0" << std::endl; gpVec[11] = opt::species + ".orthologNotInEnsembl." + numToString(countNotInEnsembl); print_vector(gpVec, *gpOutFile); //std::cerr << ensembl[0] << std::endl; } //std::cout << "hello" << std::endl; } else { std::vector<string> myNameVec = split(gpVec[0], '.'); std::string nameWdots = gpVec[0] + ".1"; gpVec[0] = myNameVec[0] + "_" + myNameVec[1] + "_" + myNameVec[2] + "_" + myNameVec[3]; std::cout << nameWdots << "\t" << "noOrthologAssigned" << "\t" << "0" << "\t" << opt::species + ".unknown." + numToString(countUnknown) << std::endl; *refLinkFile << opt::species + ".unknown." + numToString(countUnknown) << "\t" << "unknown - no ortholog from Brawand data" << "\t" << gpVec[0] << "\tNP_X\t77\t88\t" << "0" << "\t0" << std::endl; gpVec[11] = opt::species + ".unknown." + numToString(countUnknown); print_vector(gpVec, *gpOutFile); countUnknown++; } } return 0; }
void ofxUINumberDialer::keyPressed(int key) { if(state == OFX_UI_STATE_OVER) { switch (key) { case OF_KEY_RIGHT: *value += zoneMultiplier; if(*value > max) { *value = max; } else if(*value < min) { *value = min; } setTextString(numToString(abs(*value), precision, numOfPrecisionZones, '0')); triggerEvent(this); break; case OF_KEY_UP: *value += zoneMultiplier; if(*value > max) { *value = max; } else if(*value < min) { *value = min; } setTextString(numToString(abs(*value), precision, numOfPrecisionZones, '0')); triggerEvent(this); break; case OF_KEY_LEFT: *value -= zoneMultiplier; if(*value > max) { *value = max; } else if(*value < min) { *value = min; } setTextString(numToString(abs(*value), precision, numOfPrecisionZones, '0')); triggerEvent(this); break; case OF_KEY_DOWN: *value -= zoneMultiplier; if(*value > max) { *value = max; } else if(*value < min) { *value = min; } setTextString(numToString(abs(*value), precision, numOfPrecisionZones, '0')); triggerEvent(this); break; default: break; } } }
void CConfigDisplay::ReadReg(RegistryKey & reg) { AutoLog alog("CCD::ReadReg"); m_vBkPanel = reg.Read(RegWindowsColorBkPanel, m_vBkPanel); m_vBkNormal = reg.Read(RegWindowsColorBkNormal, m_vBkNormal); m_vBkHigh = reg.Read(RegWindowsColorBkHigh, m_vBkHigh); m_vBkSel = reg.Read(RegWindowsColorBkSel, m_vBkSel); m_vTxPanel = reg.Read(RegWindowsColorTxPanel, m_vTxPanel); m_vTxNormal = reg.Read(RegWindowsColorTxNormal, m_vTxNormal); m_vTxHigh = reg.Read(RegWindowsColorTxHigh, m_vTxHigh); m_vTxSel = reg.Read(RegWindowsColorTxSel, m_vTxSel); m_vBkColHdr = reg.Read(RegWindowsColorBkColHdr, m_vBkColHdr); m_vTxColHdr = reg.Read(RegWindowsColorTxColHdr, m_vTxColHdr); MBCONFIG_READ_COLOR_3D(reg,MB3DCOLHDRCOLOR, m_vcrColHdrInUL,m_vcrColHdrInLR,m_vcrColHdrOutUL,m_vcrColHdrOutLR); MBCONFIG_READ_COLOR_3D(reg,MB3DDATACOLOR, m_vcrDataInUL,m_vcrDataInLR,m_vcrDataOutUL,m_vcrDataOutLR); MBCONFIG_READ_COLOR_3D(reg,MB3DSTATUSCOLOR, m_vcrStatusInUL,m_vcrStatusInLR,m_vcrStatusOutUL,m_vcrStatusOutLR); m_3dData = reg.Read(MB3DDATA,0); m_3dColHdr = reg.Read(MB3DCOLHDRS,0); m_3dStatus = reg.Read(MB3DSTATUS,0); if (IsWindow(m_3dDataCheck.m_hWnd)) { m_3dColHdrsCheck.SetCheck(m_3dColHdr); m_3dDataCheck.SetCheck(m_3dData); m_3dStatusCheck.SetCheck(m_3dStatus); } v2m(); m_vBorderWidth = reg.Read(RegWindowsBorderWidth, m_vBorderWidth); m_vBorderHorz = reg.Read(RegWindowsBorderHorz, m_vBorderHorz); m_vBorderVert = reg.Read(RegWindowsBorderVert, m_vBorderVert); int sel; if (IsWindow(m_BorderWidth.m_hWnd)) { sel = m_BorderWidth.SelectString(-1, numToString(m_vBorderWidth)); m_BorderWidth.SetCurSel(sel); } AutoBuf buf(1000); reg.Read(RegWindowsFontTitles, buf.p, 999, ""); if (MBUtil::ConfigFontValidate(buf.p) && strlen(buf.p) > MBCCFONTFACEPOS) { MBUtil::FontStr2LogFont(buf.p, &m_lfTitles); } reg.Read(RegWindowsFontPanel, buf.p, 999, ""); if (MBUtil::ConfigFontValidate(buf.p) && strlen(buf.p) > MBCCFONTFACEPOS) { MBUtil::FontStr2LogFont(buf.p, &m_lfPanel); } reg.Read(RegWindowsFontColHdr, buf.p, 999, ""); if (MBUtil::ConfigFontValidate(buf.p) && strlen(buf.p) > MBCCFONTFACEPOS) { MBUtil::FontStr2LogFont(buf.p, &m_lfColHdr); } EnableDisable(); }
void summariseEigensoft() { std::ifstream* eigenFile = new std::ifstream(opt::eigensoftFile.c_str()); string fileRoot = stripExtension(opt::eigensoftFile); string FstResultsFileName = fileRoot + "_" + opt::runName + "_fst_matrix.forR"; std::ofstream* pFst = new std::ofstream(FstResultsFileName.c_str()); std::vector<std::vector<std::string> > fst_matrix; string line; getline(*eigenFile, line); // Get the first description line short type; if (line == "##") { type = 1; } else { type = 2; } std::cerr << "It is type: " << type << std::endl; if (type == 1) { getline(*eigenFile, line); std::vector<std::string> fields = split(line, '\t'); std::vector<std::string> this_indiv_fst; std::vector<std::string> all_indiv; string this_indiv = fields[0]; this_indiv_fst.push_back(fields[2]); while (getline(*eigenFile, line)) { fields = split(line, '\t'); std::cerr << "Indiv: " << fields[0] << std::endl; if (this_indiv == fields[0]) { this_indiv_fst.push_back(fields[2]); } else { fst_matrix.push_back(this_indiv_fst); all_indiv.push_back(this_indiv); this_indiv = fields[0]; this_indiv_fst.clear(); this_indiv_fst.push_back(fields[2]); } } all_indiv.push_back(this_indiv); fst_matrix.push_back(this_indiv_fst); this_indiv_fst.clear(); this_indiv_fst.push_back("0"); all_indiv.push_back(fields[1]); fst_matrix.push_back(this_indiv_fst); for (std::vector<std::vector<std::string> >::size_type i = 0; i != fst_matrix.size(); i++) { std::reverse(fst_matrix[i].begin(), fst_matrix[i].end()); fst_matrix[i].insert(fst_matrix[i].end(), "0"); while (fst_matrix[i].size() != fst_matrix[0].size()) { fst_matrix[i].insert(fst_matrix[i].end(), "0"); } } std::reverse(fst_matrix.begin(), fst_matrix.end()); std::reverse(all_indiv.begin(), all_indiv.end()); print_vector(all_indiv, *pFst); print_matrix(fst_matrix, *pFst); } else if (type == 2) { std::cerr << "type2" << std::endl; std::vector<std::string> fields = split(line, '\t'); std::vector<std::string> all_indiv(fields.begin()+1,fields.end()); getline(*eigenFile, line); getline(*eigenFile, line); std::vector<std::string> this_indiv_fst; while (getline(*eigenFile, line)) { fields = split(line, '\t'); std::copy(fields.begin()+1,fields.end(),std::back_inserter(this_indiv_fst)); for (std::vector<std::string>::size_type i = 0; i != this_indiv_fst.size(); i++) { double fst = convertToDouble(this_indiv_fst[i]) / 1000; this_indiv_fst[i] = numToString(fst); } fst_matrix.push_back(this_indiv_fst); this_indiv_fst.clear(); } print_vector(all_indiv, *pFst); print_matrix(fst_matrix, *pFst); } }
void getFstFromVCF() { std::cerr << "Calculating Fst using variants from: " << opt::vcfFile << std::endl; std::cerr << "Between the two 'populations' defined in: " << opt::sampleSets << std::endl; if (opt::windowSize > 0) { std::cerr << "also using a sliding window of size: " << opt::windowSize << " variants and sliding in steps of: " << opt::windowStep << std::endl; } string fileRoot = stripExtension(opt::sampleSets); //std::cerr << "Still alive: " << std::endl; // Open connection to read from the vcf file std::istream* vcfFile = createReader(opt::vcfFile.c_str()); //std::cerr << "Hello: " << std::endl; std::ifstream* setsFile = new std::ifstream(opt::sampleSets.c_str()); std::ifstream* annotFile; std::ofstream* snpCategoryFstFile; std::ofstream* regionsAboveFstFile; bool inRegAbove = false; std::ofstream* fstDxyFixedWindowFile; std::ifstream* ancSetsFile; std::ofstream* ancSetsOutFile; std::vector<string> ancSet1; std::vector<string> ancSet2; Annotation wgAnnotation; if (!opt::annotFile.empty()) { annotFile = new std::ifstream(opt::annotFile.c_str()); Annotation Annot(annotFile, false); // Does not use transcripts annotated as 5' or 3' partial wgAnnotation = Annot; string snpCategoryFstFileName = fileRoot + "_" + opt::runName + "SNPcategory_fst.txt"; snpCategoryFstFile = new std::ofstream(snpCategoryFstFileName.c_str()); *snpCategoryFstFile << "SNPcategory" << "\t" << "thisSNPFst" << "\t" << "thisSNPDxy" << "\t" << "scaffold" << "\t" << "position" << std::endl; } if (!opt::ancSets.empty()) { ancSetsFile = new std::ifstream(opt::ancSets); string ancOutFileName = fileRoot + "_" + opt::runName + "ancestralSNPs_fst.txt"; ancSetsOutFile = new std::ofstream(ancOutFileName); *ancSetsOutFile << "scaffold" << "\t" << "position" << "\t" << "AncAllelePopulation" << "\t" << "Fst" << "\t" << "ancSet1_segregating" << "\t" << "ancSet2_segregating" << std::endl; string ancSet1String; string ancSet2String; getline(*ancSetsFile, ancSet1String); getline(*ancSetsFile, ancSet2String); ancSet1 = split(ancSet1String, ','); ancSet2 = split(ancSet2String, ','); std::sort(ancSet1.begin(),ancSet1.end()); std::sort(ancSet2.begin(),ancSet2.end()); } if (opt::regAbove > 0) { string regionsAboveFstFileName = fileRoot + "_w_" + numToString(opt::windowSize) + opt::runName + "_fst_above" + numToString(opt::regAbove) + ".txt"; regionsAboveFstFile = new std::ofstream(regionsAboveFstFileName.c_str()); } string FstResultsFileName = fileRoot + "_w_" + numToString(opt::windowSize) + opt::runName + "_fst.txt"; std::ofstream* pFst = new std::ofstream(FstResultsFileName.c_str()); string fstDxyFixedWindowFileName = fileRoot + "dXY_fixedWindow.txt"; fstDxyFixedWindowFile = new std::ofstream(fstDxyFixedWindowFileName.c_str()); string heterozygositySetsFileName = fileRoot + "_w_" + numToString(opt::windowSize) + opt::runName + "_heterozygosity.txt"; *fstDxyFixedWindowFile << "scaffold" << "\t" << "Start" << "\t" << "End" << "\t" << "Fst" << "\t" << "Dxy" << "\t" << "Set1_pi" << "\t" << "Set2_pi" << std::endl; std::ofstream* pHetSets = new std::ofstream(heterozygositySetsFileName.c_str()); //std::cerr << "Still alive: " << std::endl; string set1String; string set2String; getline(*setsFile, set1String); getline(*setsFile, set2String); std::vector<string> set1 = split(set1String, ','); std::vector<string> set2 = split(set2String, ','); std::sort(set1.begin(),set1.end()); std::sort(set2.begin(),set2.end()); int numChromosomes; int totalVariantNumber = 0; int countedVariantNumber = 0; string windowMiddleVariant = "first\tWindow"; string windowStartEnd = "scaffold_0\t0"; int windowStart = 0; int windowEnd; int fixedWindowStart = 0; std::vector<double> fixedWindowDxyVector; std::vector<double> fixedWindowFstNumVector; std::vector<double> fixedWindowFstDenomVector; std::vector<double> fixedWindowHet1Vector; std::vector<double> fixedWindowHet2Vector; std::vector<double> fixedWindowPi1Vector; std::vector<double> fixedWindowPi2Vector; std::vector<string> sampleNames; std::vector<string> fields; std::vector<size_t> set1Loci; std::vector<size_t> set2Loci; std::vector<size_t> ancSet1Loci; std::vector<size_t> ancSet2Loci; short n1; short n2; short n1anc; short n2anc; string line; std::map<std::string, double> loc_pval; std::vector<double> fstNumerators; fstNumerators.reserve(30000000); std::vector<double> fstDenominators; fstDenominators.reserve(30000000); std::vector<double> DxyVector; DxyVector.reserve(30000000); std::vector<std::vector<double> > heterozygositiesVector; heterozygositiesVector.reserve(30000000); std::vector<double> set1heterozygositiesSimple; set1heterozygositiesSimple.reserve(30000000); std::vector<double> set2heterozygositiesSimple; set2heterozygositiesSimple.reserve(30000000); std::vector<double> set1heterozygositiesNei; set1heterozygositiesNei.reserve(30000000); std::vector<double> set2heterozygositiesNei; set2heterozygositiesNei.reserve(30000000); std::vector<double> set1heterozygositiesPi; set1heterozygositiesPi.reserve(30000000); std::vector<double> set2heterozygositiesPi; set2heterozygositiesPi.reserve(30000000); while (getline(*vcfFile, line)) { if (line[0] == '#' && line[1] == '#') { } else if (line[0] == '#' && line[1] == 'C') { std::vector<std::string> fields = split(line, '\t'); const std::vector<std::string>::size_type numSamples = fields.size() - NUM_NON_GENOTYPE_COLUMNS; numChromosomes = (int)numSamples * 2; // std::cerr << "Number of chromosomes: " << numChromosomes << std::endl; if (opt::sampleNameFile.empty()) { for (std::vector<std::string>::size_type i = NUM_NON_GENOTYPE_COLUMNS; i != fields.size(); i++) { sampleNames.push_back(fields[i]); } } else { sampleNames = readSampleNamesFromTextFile(opt::sampleNameFile); } set1Loci = locateSet(sampleNames, set1); set2Loci = locateSet(sampleNames, set2); n1 = set1Loci.size()*2; n2 = set2Loci.size()*2; std::cerr << "Set1 loci: " << std::endl; print_vector_stream(set1Loci, std::cerr); std::cerr << "Set2 loci: " << std::endl; print_vector_stream(set2Loci, std::cerr); if (!opt::ancSets.empty()) { ancSet1Loci = locateSet(sampleNames, ancSet1); ancSet2Loci = locateSet(sampleNames, ancSet2); std::cerr << "Ancestral Set1 loci: " << std::endl; print_vector_stream(ancSet1Loci, std::cerr); std::cerr << "Ancestral Set2 loci: " << std::endl; print_vector_stream(ancSet2Loci, std::cerr); n1anc = ancSet1Loci.size() * 2; n2anc = ancSet2Loci.size() * 2; } if (opt::windowSize > 0) { if (opt::windowSize == opt::windowStep) { *pHetSets << "scaffold" << "\t" << "Start" << "\t" << "End" << "Set1_heterozygosity" << "\t" << "Set2_heterozygosity" << "\t" << "Set1_heterozygosity_Nei" << "\t" << "Set2_heterozygosity_Nei" << "\t" << "Set1_nucleotideDiversity_pi" << "\t" << "Set2_nucleotideDiversity_pi" << std::endl; *pFst << "var_num" << "\t" << "scaffold" << "\t" << "Start" << "\t" << "End" << "\t" << "Fst" << "\t" << "Dxy_onlyVaiants" << "\t" << "Dxy_AllSites" << "\t" << "windowSize" << std::endl; if (opt::regAbove > 0) *regionsAboveFstFile << "scaffold" << "\t" << "Start" << "\t" << "End" << std::endl; } else { *pHetSets << "Middle_SNP_position" << "\t" << "Set1_heterozygosity" << "\t" << "Set2_heterozygosity" << "\t" << "Set1_heterozygosity_Nei" << "\t" << "Set2_heterozygosity_Nei" << "\t" << "Set1_nucleotideDiversity_pi" << "\t" << "Set2_nucleotideDiversity_pi" << std::endl; } } } else { totalVariantNumber++; std::vector<std::string> fields = split(line, '\t'); std::vector<std::string> info = split(fields[7], ';'); if (info[0] != "INDEL") { // Without indels SetCounts counts = getVariantCountsForFst(fields,set1Loci,set2Loci); //std::cerr << "Still here: " << counts.set1HaplotypeVariant.size() << "\t" << counts.set1individualsWithVariant.size() << "\t" << n1 << std::endl; //std::cerr << "Still here: " << counts.set2HaplotypeVariant.size() << "\t" << counts.set2individualsWithVariant.size() << "\t" << n2 << std::endl; //print_vector_stream(counts.set1HaplotypeVariant, std::cerr); //print_vector_stream(counts.set1individualsWithVariant, std::cerr); //print_vector_stream(counts.set2HaplotypeVariant, std::cerr); if ((counts.set1Count > 0 || counts.set2Count > 0) && (counts.set1Count < n1 || counts.set2Count < n2)) { countedVariantNumber++; double FstNumerator = calculateFstNumerator(counts, n1, n2); fstNumerators.push_back(FstNumerator); fixedWindowFstNumVector.push_back(FstNumerator); double FstDenominator = calculateFstDenominator(counts, n1, n2); fstDenominators.push_back(FstDenominator); fixedWindowFstDenomVector.push_back(FstDenominator); assert(FstDenominator != 0); double thisSNPDxy = calculateDxy(counts, n1, n2); DxyVector.push_back(thisSNPDxy); fixedWindowDxyVector.push_back(thisSNPDxy); std::vector<double> thisSNPhet = getSetHeterozygozities(counts, n1, n2); heterozygositiesVector.push_back(thisSNPhet); std::vector<double> thisSNPpis = calculatePiTwoSets(counts, n1, n2); fixedWindowPi1Vector.push_back(thisSNPpis[0]); fixedWindowPi2Vector.push_back(thisSNPpis[1]); set1heterozygositiesPi.push_back(thisSNPpis[0]); set2heterozygositiesPi.push_back(thisSNPpis[1]); // std::cerr << "Still here: " << thisSNPpis[0] << std::endl; set1heterozygositiesSimple.push_back(thisSNPhet[0]); set2heterozygositiesSimple.push_back(thisSNPhet[1]); fixedWindowHet1Vector.push_back(thisSNPhet[0]); set1heterozygositiesNei.push_back(thisSNPhet[2]); set2heterozygositiesNei.push_back(thisSNPhet[3]); fixedWindowHet2Vector.push_back(thisSNPhet[1]); if (!opt::annotFile.empty()) { string scaffold = fields[0]; string loc = fields[1]; // Scaffold string SNPcategory = wgAnnotation.getCategoryOfSNP(scaffold, loc); double thisSNPFst = FstNumerator/FstDenominator; *snpCategoryFstFile << SNPcategory << "\t" << thisSNPFst << "\t" << thisSNPDxy << "\t" << scaffold << "\t" << loc << std::endl; } if (!opt::ancSets.empty()) { double thisSNPFst = FstNumerator/FstDenominator; if (thisSNPFst < 0) { thisSNPFst = 0; } string AA = split(info[info.size()-1],'=')[1]; //std::cerr << "AA=" << " " << AA << std::endl; FourSetCounts c; if (AA == fields[3]) { c = getFourSetVariantCounts(fields,set1Loci,set2Loci,ancSet1Loci,ancSet2Loci,"ref"); *ancSetsOutFile << fields[0] << "\t" << fields[1] << "\t" << c.set1daAF-c.set2daAF << "\t" << thisSNPFst << "\t"; if (c.set3daAF > 0 & c.set3daAF < 1) { *ancSetsOutFile << "1" << "\t"; } else { *ancSetsOutFile << "0" << "\t"; } if (c.set4daAF > 0 & c.set4daAF < 1) { *ancSetsOutFile << "1" << std::endl; } else { *ancSetsOutFile << "0" << std::endl; } } else if (AA == fields[4]) { c = getFourSetVariantCounts(fields,set1Loci,set2Loci,ancSet1Loci,ancSet2Loci,"alt"); *ancSetsOutFile << fields[0] << "\t" << fields[1] << "\t" << c.set1daAF-c.set2daAF << "\t" << thisSNPFst << "\t"; if (c.set3daAF > 0 & c.set3daAF < 1) { *ancSetsOutFile << "1" << "\t"; } else { *ancSetsOutFile << "0" << "\t"; } if (c.set4daAF > 0 & c.set4daAF < 1) { *ancSetsOutFile << "1" << std::endl; } else { *ancSetsOutFile << "0" << std::endl; } // std::cerr << "AA=alt" << " " << c.set1daAF << " " << c.set2daAF << std::endl; } else { c = getFourSetVariantCounts(fields,set1Loci,set2Loci,ancSet1Loci,ancSet2Loci,"N"); *ancSetsOutFile << fields[0] << "\t" << fields[1] << "\t" << "-888" << "\t" << thisSNPFst << "\t"; if (c.set3AltAF > 0 & c.set3AltAF < 1) { *ancSetsOutFile << "1" << "\t"; } else { *ancSetsOutFile << "0" << "\t"; } if (c.set4AltAF > 0 & c.set4AltAF < 1) { *ancSetsOutFile << "1" << std::endl; } else { *ancSetsOutFile << "0" << std::endl; } } } std::vector<string> s = split(windowStartEnd, '\t'); if (s[0] == fields[0]) { if (atoi(fields[1].c_str()) > (fixedWindowStart+10000)) { double thisFixedWindowDxy = vector_average_withRegion(fixedWindowDxyVector, 10000); double thisFixedWindowFst = calculateFst(fixedWindowFstNumVector, fixedWindowFstDenomVector); //double thisFixedWindowHet1 = vector_average_withRegion(fixedWindowHet1Vector, 10000); //double thisFixedWindowHet2 = vector_average_withRegion(fixedWindowHet2Vector, 10000); double thisFixedWindowPi1 = vector_average_withRegion(fixedWindowPi1Vector, 10000); double thisFixedWindowPi2 = vector_average_withRegion(fixedWindowPi2Vector, 10000); *fstDxyFixedWindowFile << fields[0] << "\t" << fixedWindowStart << "\t" << fixedWindowStart+10000 << "\t" << thisFixedWindowFst << "\t" << thisFixedWindowDxy << "\t" << thisFixedWindowPi1 << "\t" << thisFixedWindowPi2 << std::endl; fixedWindowDxyVector.clear(); fixedWindowFstNumVector.clear(); fixedWindowFstDenomVector.clear(); fixedWindowHet1Vector.clear(); fixedWindowHet2Vector.clear(); fixedWindowPi1Vector.clear(); fixedWindowPi2Vector.clear(); fixedWindowStart= fixedWindowStart+10000; } } else { fixedWindowStart = 0; } if (opt::windowSize == 1) { double Fst = FstNumerator/FstDenominator; if (Fst < 0) Fst = 0; *pFst << countedVariantNumber << "\t" << fields[0] + "\t" + fields[1] << "\t" << Fst << "\t" << thisSNPDxy << std::endl; } else if ((opt::windowSize > 0) && (countedVariantNumber % opt::windowStep == 0) && countedVariantNumber >= opt::windowSize) { std::vector<double> windowFstNumerators(fstNumerators.end()-opt::windowSize, fstNumerators.end()); std::vector<double> windowFstDenominators(fstDenominators.end()-opt::windowSize, fstDenominators.end()); double windowFst = calculateFst(windowFstNumerators, windowFstDenominators); if (windowFst < 0) windowFst = 0; std::vector<double> windowDxyVec(DxyVector.end()-opt::windowSize, DxyVector.end()); double windowDxy = vector_average(windowDxyVec); if (opt::windowSize == opt::windowStep) { std::vector<string> s = split(windowStartEnd, '\t'); if (s[0] == fields[0]) { windowStartEnd = windowStartEnd + "\t" + fields[1]; windowEnd = atoi(fields[1].c_str()); double windowDxyIncNonSeg = vector_average_withRegion(windowDxyVec, windowEnd-windowStart); *pFst << countedVariantNumber-opt::windowSize+1 << "\t" << windowStartEnd << "\t" << windowFst << "\t" << windowDxy << "\t" << windowDxyIncNonSeg << "\t" << windowFstDenominators.size() << std::endl; if (opt::regAbove > 0) { if (windowFst >= opt::regAbove && !inRegAbove) { inRegAbove = true; *regionsAboveFstFile << s[0] << "\t" << s[1] << "\t"; } else if (windowFst < opt::regAbove && inRegAbove) { inRegAbove = false; *regionsAboveFstFile << s[1] << std::endl; } } } } else { *pFst << countedVariantNumber-opt::windowSize+1 << "\t" << windowMiddleVariant << "\t" << windowFst << "\t" << windowDxy << "\t" << windowFstDenominators.size() << std::endl; } // Now calculate and output expected heterozygosities for this window std::vector<double> windowHetS1Vec(set1heterozygositiesSimple.end()-opt::windowSize, set1heterozygositiesSimple.end()); double windowHetS1 = vector_average(windowHetS1Vec); std::vector<double> windowHetS2Vec(set2heterozygositiesSimple.end()-opt::windowSize, set2heterozygositiesSimple.end()); double windowHetS2 = vector_average(windowHetS2Vec); std::vector<double> windowHetNei1Vec(set1heterozygositiesNei.end()-opt::windowSize, set1heterozygositiesNei.end()); double windowHetNei1 = vector_average(windowHetNei1Vec); std::vector<double> windowHetNei2Vec(set2heterozygositiesNei.end()-opt::windowSize, set2heterozygositiesNei.end()); double windowHetNei2 = vector_average(windowHetNei2Vec); std::vector<double> windowHetPi1Vec(set1heterozygositiesPi.end()-opt::windowSize, set1heterozygositiesPi.end()); double windowHetPi1 = vector_average_withRegion(windowHetPi1Vec, windowEnd-windowStart); std::vector<double> windowHetPi2Vec(set2heterozygositiesPi.end()-opt::windowSize, set2heterozygositiesPi.end()); double windowHetPi2 = vector_average_withRegion(windowHetPi2Vec, windowEnd-windowStart); if (opt::windowSize == opt::windowStep) { std::vector<string> s = split(windowStartEnd, '\t'); if (s[0] == fields[0]) { *pHetSets << windowStartEnd << "\t" << windowHetS1 << "\t" << windowHetS2 << "\t" << windowHetNei1 << "\t" << windowHetNei2 << "\t" << windowHetPi1 << "\t" << windowHetPi2 << std::endl; windowStartEnd = fields[0] + "\t" + fields[1]; windowStart = atoi(fields[1].c_str()); } else { windowStartEnd = fields[0] + "\t0"; windowStart = 0; } } else { *pHetSets << windowMiddleVariant << "\t" << windowHetS1 << "\t" << windowHetS2 << "\t" << windowHetNei1 << "\t" << windowHetNei2 << std::endl; windowMiddleVariant = fields[0] + "\t" + fields[1]; // works only if STEP is half SIZE for the window } } } } if (totalVariantNumber % 100000 == 0) { double Fst = calculateFst(fstNumerators, fstDenominators); std::cerr << totalVariantNumber << " variants processed... Fst: " << Fst << std::endl; } } } double Fst = calculateFst(fstNumerators, fstDenominators); double overallHetS1 = vector_average(set1heterozygositiesSimple); double overallHetS2 = vector_average(set2heterozygositiesSimple); double overallHetNei1 = vector_average(set1heterozygositiesNei); double overallHetNei2 = vector_average(set2heterozygositiesNei); std::cerr << "Fst: " << Fst << std::endl; std::cerr << "Heterozygosities: " << "\tS1:" << overallHetS1 << "\tS2:" << overallHetS2 << "\tNei1:" << overallHetNei1 << "\tNei2" << overallHetNei2 << std::endl; *pHetSets << "#Heterozygosities: " << "\tS1:" << overallHetS1 << "\tS2:" << overallHetS2 << "\tNei1:" << overallHetNei1 << "\tNei2" << overallHetNei2 << std::endl; }