//Get all Name in order bool PWM::_getOrderedPositionNames(stringList& pos, stringList& names){ for(size_t i=0;i<pos.size();i++){ size_t nameHeader=pos[i].find("NAME:"); if (nameHeader == std::string::npos){ continue; } size_t nameLineEnding=pos[i].find_first_of("\n",nameHeader); std::string name = pos[i].substr(nameHeader+5,nameLineEnding-(nameHeader+5)); clear_whitespace(name, " \t\n"); if (names.contains(name)){ std::cerr << "Position with name of: " << name << " is defined twice in the model\n"; return false; } else{ names.push_back(name); } } return true; }
//!Parse the stringList from model import bool transitionFuncParam::parse(stringList& lst, tracks& trcks, weights* wts, StateFuncs* funcs) { size_t idx; //FUNCTION NAME (REQUIRED) if (lst.contains("FUNCTION")) { idx=lst.indexOf("FUNCTION"); idx++; transFuncName = lst[idx]; if (funcs!=NULL) { transFunc = funcs->getTransitionFunction(transFuncName); } } else { std::cerr << "Tag was parsed but contains no FUNCTION: . Please check the formatting of the tags\n" << std::endl; return false; //errorInfo(sCantParseLine, "Tag was parsed but contains no FUNCTION: . Please check the formatting of the tags\n"); } //Implement Which track to pass to function if (lst.contains("TRACK")) { idx=lst.indexOf("TRACK"); idx++; trackName=lst[idx]; transFuncTrack = trcks.getTrack(trackName); } else { std::cerr << "Tag was parsed but contains no TRACK: . Please check the formatting of the tags\n" << std::endl; return false; //errorInfo(sCantParseLine, "Tag was parsed but contains no TRACK: . Please check the formatting of the tags\n"); } if (lst.contains("SCALE")) { idx=lst.indexOf("SCALE"); idx++; if (isNumeric(lst[idx])) { transFuncScaling = new(std::nothrow) weight; if (transFuncScaling==NULL) { std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl; exit(1); } double tempValue; if (!stringToDouble(lst[idx], tempValue)) { std::cerr << "Ambiguous Value couldn't be parsed: "<< lst[idx] << std::endl; return false; } transFuncScaling->setAbsolute(tempValue); } else { std::string weightName=lst[idx]; if (wts->count(weightName)) { transFuncScaling = (*wts)[weightName]; } } } //Process Traceback Commands //Parse the TO Traceback Labels in the function tag const std::string tbLabels[]= {"TO_LABEL","TB->LABEL","TO_GFF","TB->GFF","TO_STATE","TB->STATE","TO_START","TB->START","DIFF_STATE"}; const tracebackIdentifier typs[]= {STATE_LABEL,STATE_LABEL,STATE_GFF,STATE_GFF,STATE_NAME,STATE_NAME,START_INIT,START_INIT,DIFF_STATE}; for(int i=0; i<9; i++) { if (lst.contains(tbLabels[i])) { transFuncTraceback=true; idx=lst.indexOf(tbLabels[i]); transFuncTracebackIdentifier=typs[i]; if (typs[i]!=START_INIT || typs[i]!=DIFF_STATE) { transFuncTracebackString=lst[idx+1]; } } } // Parse the Combine tags if (transFuncTraceback) { //Process Traceback Combining Commands std::string combineLabels[] = {"COMBINE_LABEL","COMBINE_GFF","COMBINE_STATE", "NO_COMBINE"}; const combineIdentifier comtyps[] = {STATELABEL,STATEGFF,STATENAME,FULL}; bool combineTypeProvided=false; for(int i=0; i<4; i++) { if (lst.contains(combineLabels[i])) { idx=lst.indexOf(combineLabels[i]); transFuncCombineIdentifier=comtyps[i]; transFuncCombineString=lst[idx+1]; combineTypeProvided=true; } } if (!combineTypeProvided) { std::cerr << "Transition Function tag with a traceback was called, but no CombineType was provided. If no traceback is needed then please remove traceback command. \n" << std::endl; return false; //errorInfo(sTagIncorrect, "Transition Function tag with a traceback was called, but no CombineType was provided. If no traceback is needed then please remove traceback command. \n"); } } return true; }
//!Parse the stringList from model import bool emissionFuncParam::parse(stringList& lst, tracks& trcks, weights* wts, StateFuncs* funcs) { size_t idx; //FUNCTION NAME (REQUIRED) if (lst.contains("FUNCTION")) { idx=lst.indexOf("FUNCTION"); idx++; emissionFuncName = lst[idx]; if (funcs!=NULL) { emissionFunction = funcs->getEmissionFunction(emissionFuncName); } } else { std::cerr << "Tag was parsed but contains no FUNCTION: . Please check the formatting of the tags\n" << std::endl; return false; //errorInfo(sCantParseLine, "Tag was parsed but contains no FUNCTION: . Please check the formatting of the tags\n"); } //Implement Which track to pass to function if (lst.contains("TRACK")) { idx=lst.indexOf("TRACK"); idx++; trackName=lst[idx]; emissionFuncTrack = trcks.getTrack(trackName); trackNumber = emissionFuncTrack->getIndex(); } else { std::cerr << "Tag was parsed but contains no TRACK: . Please check the formatting of the tags\n" << std::endl; return false; //errorInfo(sCantParseLine, "Tag was parsed but contains no TRACK: . Please check the formatting of the tags\n"); } if (lst.contains("SCALE")) { idx=lst.indexOf("SCALE"); idx++; if (isNumeric(lst[idx])) { emissionFuncScaling = new(std::nothrow) weight; if (emissionFuncScaling==NULL) { std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl; exit(1); } double tempValue; if (!stringToDouble(lst[idx], tempValue)) { std::cerr << "SCALE value could not be converted to numerical value: "<< lst[idx] << std::endl; return false; } emissionFuncScaling->setAbsolute(tempValue); } else { std::string weightName=lst[idx]; if (wts->count(weightName)) { emissionFuncScaling = (*wts)[weightName]; } } } return true; }