示例#1
0
文件: ranges.cpp 项目: anobel/icd
// [[Rcpp::export]]
CV icd9ChildrenShortUnordered(const CV &icd9Short,
                              const VecStr &icd9cmReal,
                              const bool onlyReal) {
  icd_set out;
  if (icd9Short.size() == 0) {
    CV out;
    out.attr("icd_short_diag") = true;
    return out;
  }
  List parts         = icd9ShortToParts(icd9Short, "");
  CV mjr             = parts[0];
  CV mnr             = parts[1];
  CV::iterator itmjr = mjr.begin();
  CV::iterator itmnr = mnr.begin();
  for (; itmjr != mjr.end(); ++itmjr, ++itmnr) {
    Str thismjr = as<Str>(*itmjr);
    Str thismnr = as<Str>(*itmnr);
    const CV newminors =
      icd9ExpandMinor(thismnr, icd9IsASingleE(thismjr.c_str()));
    VecStr newshort = as<VecStr>(icd9MajMinToShort(thismjr, newminors));
    out.insert(newshort.begin(), newshort.end());
  }
  if (onlyReal) {
    icd_set out_real;
    icd_set reals(icd9cmReal.begin(), icd9cmReal.end());
    for (icd_set::iterator j = out.begin(); j != out.end(); ++j) {
      if (reals.find(*j) != reals.end()) out_real.insert(*j);
    }
    out = out_real;
  }
  CV rcppOut                     = wrap(out);
  rcppOut.attr("icd_short_diag") = true;
  return rcppOut;
}
示例#2
0
文件: ranges.cpp 项目: anobel/icd
// [[Rcpp::export]]
CV icd9ChildrenShort(CV icd9Short, const VecStr &icd9cmReal, bool onlyReal) {
  std::set<Str> out;
  if (icd9Short.size() == 0) {
    icd9Short.attr("icd_short_diag") = true;
    return icd9Short;
  }
  List parts         = icd9ShortToParts(icd9Short, "");
  CV mjr             = parts[0];
  CV mnr             = parts[1];
  CV::iterator itmjr = mjr.begin();
  CV::iterator itmnr = mnr.begin();
  for (; itmjr != mjr.end(); ++itmjr, ++itmnr) {
    Str thismjr = as<Str>(*itmjr);
    Str thismnr = as<Str>(*itmnr);
    const CV newminors =
      icd9ExpandMinor(thismnr, icd9IsASingleE(thismjr.c_str()));
    VecStr newshort = as<VecStr>(icd9MajMinToShort(thismjr, newminors));
    out.insert(newshort.begin(), newshort.end());
  }
  if (onlyReal) {
    std::set<Str> out_real;
    const std::set<Str> reals(icd9cmReal.begin(), icd9cmReal.end());
    std::set_intersection(out.begin(),
                          out.end(),
                          reals.begin(),
                          reals.end(),
                          std::inserter(out_real, out_real.begin()));
    out = out_real;
  }
  CV rcppOut                     = wrap(out);
  rcppOut.attr("icd_short_diag") = true;
  return rcppOut;
}
示例#3
0
std::vector<READ> vecStrToReadObjs(const VecStr & strs, const std::string & stubName){
	std::vector<READ> ans;
	for(const auto & strPos : iter::range(strs.size())){
		ans.emplace_back(READ(seqInfo(stubName + "." + leftPadNumStr(strPos, strs.size()), strs[strPos])));
	}
	return ans;
}
示例#4
0
VecStr readObjsToVecStr(const std::vector<T> & vec){
	VecStr ans;
	for(const auto & read : vec){
		ans.emplace_back(read.seqBase_.seq_);
	}
	return ans;
}
示例#5
0
void ParserMgr::InitParsers()
{
#ifdef DEBUG_PM_FUNC
    ScopeTracker st("ParserMgr::InitParsers", std::this_thread::get_id());
#endif
    try
    {
        VecStr expressions;
        for (size_t i=0; i<ds::NUM_MODELS; ++i)
        {
            const ParamModelBase* model = _modelMgr->Model((ds::PMODEL)i);
            if (model->DoEvaluate())
            {
                VecStr model_exprns = model->Expressions();
                expressions.insert(expressions.end(),
                                       model_exprns.begin(),
                                       model_exprns.end());
            }
        }
        SetExpression(expressions);
            //Note that the expressions are not actually evaluated at this point
    }
    catch (mu::ParserError& e)
    {
        _log->AddExcept("ParserMgr::InitParsers: " + std::string(e.GetMsg()));
    }
}
示例#6
0
VecStr findLongestSharedSeqFromReads(const std::vector<T>& reads) {
  VecStr seqs;
  for (const auto& rIter : reads) {
    seqs.push_back(rIter.seqBase_.seq_);
  }
  return seqUtil::findLongestShardedMotif(seqs);
}
示例#7
0
VecStr TableReader::extractCols(const VecStr & row, const VecStr & cols) const{
	VecStr ret;
	ret.reserve(cols.size());
	for(const auto & col : cols){
		ret.emplace_back(row[header_.getColPos(col)]);
	}
	return ret;
}
VecStr ParamModelBase::Keys() const
{
    VecStr vs;
    const size_t num_pars = _parameters.size();
    for (size_t i=0; i<num_pars; ++i)
        vs.push_back(Key(i));
    return vs;
}
示例#9
0
VecStr getStringsContains(const VecStr& vec, const std::string& contains) {
  VecStr ans;
  for (const auto& iter : vec) {
    if (iter.find(contains) != std::string::npos) {
      ans.push_back(iter);
    }
  }
  return ans;
}
示例#10
0
const VecStr fastPermuteVectorOneLength(std::string vec) {
  VecStr ans;
  int numOfPermutes = Factorial((int)vec.size());
  ans.reserve(numOfPermutes);
  do {
    ans.push_back(vec);
  } while (std::next_permutation(vec.begin(), vec.end()));
  return ans;
}
示例#11
0
VecStr numVecToVecStr(const std::vector<T>& nums) {
	VecStr ans;
	ans.reserve(nums.size());
	// std::generate_n(ans.begin(), nums.size(), [](const T & num) {return
	// estd::to_string(num);});
	for (const auto& num : nums) {
		ans.emplace_back(estd::to_string(num));
	}
	return ans;
}
示例#12
0
VecStr alignToSeqStrings(const std::vector<READ>& reads, const REF& reference,
                         aligner& alignObj, bool local, bool usingQuality) {
  VecStr output;
  output.push_back(reference.seqBase_.seq_);
  for (const auto read : reads) {
    alignObj.alignCache(reference, read, local);
    output.push_back(alignObj.alignObjectB_.seqBase_.seq_);
  }
  return output;
}
示例#13
0
VecStr tokenizeString(const std::string& str, const std::string& delim,
                      bool addEmptyToEnd = false) {
  VecStr output;
  if("whitespace" == delim){
    std::stringstream tempStream(str);
    while (!tempStream.eof()) {
      std::string tempName;
      tempStream >> tempName;
      output.emplace_back(tempName);
    }
  }else{
示例#14
0
int longToRagged(const SEXP& icd9df, VecVecStr& ragged, VecStr& visitIds,
		const std::string visitId, const std::string icd9Field =
				"icd9", bool aggregate = true) {
#ifdef ICD9_VALGRIND
	CALLGRIND_START_INSTRUMENTATION;
#endif
	SEXP icds = PROTECT(getRListOrDfElement(icd9df, icd9Field.c_str()));
	SEXP vsexp = PROTECT(getRListOrDfElement(icd9df, visitId.c_str()));
	const int approx_cmb_per_visit = 15; // just an estimate. Prob best to overestimate.
	int vlen = Rf_length(icds);
	visitIds.reserve(vlen / approx_cmb_per_visit);
	ragged.reserve(vlen / approx_cmb_per_visit);
	int max_per_pt = 1;
	if (TYPEOF(vsexp) != STRSXP)
	  Rcpp::stop("need string input to longToRagged\n");
#ifdef ICD9_DEBUG
	Rcpp::Rcout << "longToRagged SEXP is STR\n";
#endif

	const char* lastVisitId = "";
	for (int i = 0; i < vlen; ++i) {
	  // always STRING? may get numeric, integer, factor? Can always handle this on R side
		const char* icd = CHAR(STRING_ELT(icds, i));
		const char* vi = CHAR(STRING_ELT(vsexp, i));

		if (strcmp(lastVisitId, vi) != 0
				&& (!aggregate
						|| std::find(visitIds.rbegin(), visitIds.rend(), vi)
								== visitIds.rend())) {
			VecStr vcodes;
			vcodes.reserve(approx_cmb_per_visit); // estimate of number of codes per patient.
			vcodes.push_back(icd); // new vector of ICD codes with this first item
			ragged.push_back(vcodes); // and add that vector to the intermediate structure
			visitIds.push_back(vi);
		} else {
#ifdef ICD9_DEBUG
			if (ragged.size()==0) {
				Rcout << "ragged size is ZERO! aborting\n";
				break;
			}
#endif
			ragged[ragged.size() - 1].push_back(icd); // augment vec for current visit and N/V/E type // EXPENSIVE.
			int len = ragged[ragged.size() - 1].size(); // get new count of cmb for one patient
			if (len > max_per_pt)
				max_per_pt = len;
		}
#ifdef ICD9_DEBUG_TRACE
		Rcout << "ragged size is " << ragged.size() << "\n";
#endif

		lastVisitId = vi;
	} // end loop through all visit-code input data

#ifdef ICD9_VALGRIND
	CALLGRIND_STOP_INSTRUMENTATION;
	//        CALLGRIND_DUMP_STATS;
#endif
	UNPROTECT(2); // do sooner if possible?
	return max_per_pt;
}
示例#15
0
bool TableReader::getNextRow(VecStr & row){
	std::string currentLine = "";
	row.clear();
	if(njh::files::crossPlatGetline(*in_, currentLine)){
		row = tokenizeString(currentLine, tabOpts_.inDelim_, true);
		if(row.size() != header_.nCol()){
			std::stringstream ss;
			ss << __PRETTY_FUNCTION__ << ", error the row has a different number of columns than the first line" << "\n";
			ss << "rowSize: " << row.size() << ", firstLineSize: " << header_.nCol() << "\n";
			ss << "row: " << currentLine << "\n";
			throw std::runtime_error{ss.str()};
		}
		return true;
	}
	return false;
}
示例#16
0
文件: tutorial.cpp 项目: Lucki/Lix
void GameplayChat::set_hint(const std::string& hi)
{
    set_draw_required();
    hints.clear();
    if (hi.empty()) return;

    const std::string replaced = hint_replace_keywords_except_newlines(hi);

    typedef std::vector <std::string> VecStr;
    VecStr lines;
    Console::break_lines(lines, replaced, font_med, LEMSCR_X - 6);

    for (VecStr::iterator itr = lines.begin(); itr != lines.end(); ++itr) {
        Api::Label lab(3, y_hint_first + y_hint_plus * hints.size());
        hints.push_back(lab);
        hints.back().set_text(*itr);
        hints.back().set_undraw_color(color[COL_PINK]);
    }
}
示例#17
0
TableReader::TableReader(const TableIOOpts & tabOpts): tabOpts_(tabOpts){
	//inital header reader
	njh::files::checkExistenceThrow(tabOpts_.in_.inFilename_);
	std::string currentLine = njh::files::getFirstLine(
			tabOpts_.in_.inFilename_);
	auto toks = tokenizeString(currentLine, tabOpts_.inDelim_, true);
	VecStr columnNames;
	if (!tabOpts_.hasHeader_) {
		for (const auto i : iter::range(toks.size())) {
			columnNames.emplace_back("col." + leftPadNumStr(i, toks.size()));
		}
	} else {
		columnNames = toks;
	}
	header_ = table(columnNames);
	in_ = std::make_unique<InputStream>(tabOpts_.in_);
	if(tabOpts_.hasHeader_){
		njh::files::crossPlatGetline(*in_, currentLine);
	}
}
示例#18
0
std::vector<uint32_t> getPositionsMatchingPattern(const VecStr& vec,
		const std::regex & pattern){
	std::vector<uint32_t> positions;
	for(const auto pos : iter::range(vec.size())){
		std::smatch match;
		if(std::regex_match(vec[pos], match, pattern) ){
			positions.emplace_back(pos);
		}
	}
	return positions;
}
示例#19
0
// open files to plot transient
void open_tran_plot_files(Nodelist & nodelist,
                          vector<FILE *> & fplot) {
    string name;
    // open plot transient files
    for(size_t i=0; i<g_plot_tran_node.size(); i++) {
        name = g_plot_tran_node[i];
        string of = g_basename + "_" + name + "_t.dat";
        cout<<"Node \""<<name<<"\" transient plot : "<<of<<endl;
        FILE * ofs=fopen(of.c_str(),"w");
        fplot.push_back(ofs);
    }
}
示例#20
0
CharacterVector raggedToWide(const VecVecStr& ragged, int max_per_pt,
		const VecStr &visitIds) {
#ifdef ICD9_DEBUG_TRACE
	Rcpp::Rcout << "visitIds = ";
	// printIt(visitIds); // broken, not sure why.
#endif
	VecStr::size_type distinct_visits = ragged.size();
	CharacterVector out(distinct_visits * max_per_pt, NA_STRING); // optionally default empty strings? NA? User can do this for now.
#ifdef ICD9_DEBUG
			if (distinct_visits==0) {
				Rcpp::Rcout << "no visits. returning blank data\n";
				return CharacterVector::create();
			}
			if (distinct_visits != visitIds.size()) {
				Rcpp::Rcout << "visit and ragged sizes differ. visits = " << visitIds.size() <<
				  ", ragged size = " << distinct_visits << ": returning blank data\n";
				return CharacterVector::create();
			}
#endif
	for (VecVecStr::size_type row_it = 0; row_it < distinct_visits; ++row_it) {
		const VecStr& this_row = ragged[row_it];
		VecStr::size_type this_row_len = this_row.size();
		for (VecStr::size_type col_it = 0; col_it < this_row_len; ++col_it) {
		  // write in row major format, but this means transpose needed later
			VecVecStr::size_type out_idx = row_it + (distinct_visits * col_it);
			out[out_idx] = this_row[col_it];
		}
	}
#ifdef ICD9_DEBUG
	Rcpp::Rcout << "writing dimensions\n";
#endif
			// set dimensions in reverse (row major for parallel step)
	out.attr("dim") = Dimension(distinct_visits, max_per_pt);
#ifdef ICD9_DEBUG
			Rcpp::Rcout << "writing labels\n";
#endif
	CharacterVector nonames;
	rownames(out) = wrap(visitIds);
	return out;
}
示例#21
0
bool areAllOccupiedBySuperstring(Array2D<VecStr> const& occupied,
                                 std::string            str,
                                 Coord const&           coord,
                                 Direction const&       dir)
{
    /**
      * @brief Given the array of squares in the wordsearch that are occupied,
      *        we check to see if the word str is "allowed" to be at the coord
      *        of ld and have direction dir. See wsSolveDoc.h for more information
      *        on what's "allowed" and what's not.
      */

    //Assert that you remain in the bounds; this is a "private" function, and
    //you should never leave the bounds when wsSolve() is called.
    assert((coord.pX + (str.size() - 1) * dir.dX >= 0) &&
           (coord.pX + (str.size() - 1) * dir.dX < occupied.getWidth()) &&
           (coord.pY + (str.size() - 1) * dir.dY >= 0) &&
           (coord.pY + (str.size() - 1) * dir.dY < occupied.getHeight()));

    //The string's length can't be 0.
    assert(str.size() != 0);

    //First check if the square that the first letter of str occupies is occupied
    //by any superstring of str. If not, exit; if so, make a list of them.
    VecStr firstVecStr = occupied(coord.pX, coord.pY);
    if (firstVecStr.size() == 0)
        return false;

    //Executes iff above code didn't return false.
    VecStr possibleSuperstrList;

    for (unsigned i = 0; i != firstVecStr.size(); ++i)
    {
        //The below statement is equivalent to "if str is not a substring of
        //firstVecStr[i].
        if (firstVecStr[i].find(str) == std::string::npos)
            return false;
        else
            possibleSuperstrList.push_back(firstVecStr[i]);
    }

    //If the string is only one letter long, and we didn't return false yet, it means
    //that the string is on a spot occupied by one of its superstrings. Hence, we
    //return true.
    if (str.size() == 1)
        return true;

    //Something important to note is that str can only be a substring of any
    //superstring of str if its first is contained by a superstring of str.
    //Therefore, the set of all possible superstrings of str that overlap with str
    //entirely has already been determined. In the following code, we either find a
    //square which is empty or does not contain a superstring of str (and therefore
    //we return false) or find a square in which some element of possibleSuperstrList
    //is not found on the square (implying that that element is not a superstring of
    //str that overlaps with str entirely; make sure you see why); we therefore
    //remove that element from possibleSuperStrList. In the end, any remaining elements
    //in possibleSuperstrList is definitely a superstring of str that overlaps with
    //str entirely; hence, if it is empty by the end, this function returns false,
    //and if it isn't empty, this function returns true.

    for (unsigned i = 1; i < str.size(); ++i)
    {
        //Vector obtained at the current position in the array.
        VecStr vecStrCurrent = occupied(coord.pX + i * dir.dX, coord.pY + i * dir.dY);

        //List of superstrings of str on the current square.
        VecStr superstrListCurrent;

        //If the vector is empty, the position is unoccupied.
        if (vecStrCurrent.size() == 0)
            return false;

        //See if str is a substring of any strings currently held in vecStrCurrent.
        for (unsigned j = 0; j != vecStrCurrent.size(); ++j)
        {
            //The below statement is equivalent to "if str is not a substring of
            //vecStrCurrent[i].
            if (vecStrCurrent[j].find(str) == std::string::npos)
                return false;
            else
                superstrListCurrent.push_back(vecStrCurrent[j]);
        }

        //Get rid of all the elements of possibleSuperstrList that don't appear in
        //vecSuperStrListCurrent. We do this by creating a new vector containing all
        //elements that DO appear in vecSuperStrListCurrent, and then copy
        //possibleSuperstrList to the new one.
        VecStr newPossibleSuperstrList;
        for (unsigned j = 0; j != possibleSuperstrList.size(); ++j)
        {
            for (unsigned k = 0; k != superstrListCurrent.size(); ++k)
            {
                if (possibleSuperstrList[j] == superstrListCurrent[k])
                {
                    newPossibleSuperstrList.push_back(possibleSuperstrList[j]);
                    break;
                }
            }
        }
        possibleSuperstrList = newPossibleSuperstrList;

        //If it's empty, you're done.
        if (possibleSuperstrList.size() == 0)
            return false;
    }

    //Reached if and only if the above code doesn't execute.
    return true;
}
示例#22
0
VecStr toVecStr(const T&... items) {
	VecStr ret;
	ret.reserve(sizeof...(items));
	toVecStrAdd(ret, items...);
	return ret;
}
示例#23
0
void addAsStrToVec(VecStr& vec, const std::vector<T>& items) {
	for (const auto& e : items) {
		vec.emplace_back(estd::to_string(e));
	}
}
示例#24
0
void addAsStrToVec(VecStr& vec, const T& e) {
	vec.emplace_back(estd::to_string(e));
}
示例#25
0
void processArgsFile(string filename, VecPlayerType& players, bool& alwaysCheckPayoffs, string& domainString,
                     string& problemString, int& nGames) {
    const bool Verbose = true;
    VecStr args;
    ifstream infile(filename.c_str(), std::ios::in);
    if (!infile) {
        cerr << "Error reading file: " << filename << std::endl;
        exit(1);
    }
    string oneline;
    while (!infile.eof()) {
        getline(infile, oneline);
        if (oneline == "")
            break;
        std::istringstream linestring(oneline);
        string nextArg;
        linestring >> nextArg; // dummy text at the front of a line
        linestring >> nextArg; // actual arg
        args.push_back(nextArg);
    }
    StringToPlayerType playerTypes = GameModerator::getPlayerTypes();
    for (unsigned i = 0; i < args.size(); i++) {
        if (Verbose)
            cout << i << " " << args[i] << "\n";
        switch (i) {
        case 0:
            players[0] = playerTypes[args[0]];
            break;
        case 1:
            players[1] = playerTypes[args[1]];
            break;
        case 2:
            players[2] = playerTypes[args[2]];
            break;
        case 3:
            assignGame(atoi(args[3].c_str()), alwaysCheckPayoffs, domainString, problemString);
            break;
        case 4:
            nGames = atoi(args[4].c_str());
            break;
        case 5:
            GameModerator::manySamples = atoi(args[5].c_str());
            break;
        case 6:
            GameModerator::fewSamples = atoi(args[6].c_str());
            break;
        case 7:
            GameModerator::maxSize = atoi(args[7].c_str());
            break;

        }
    }
    if (Verbose) {
        cout << "PT0: " << GameModerator::typeString(players[0]) << std::endl;
        cout << "PT1: " << GameModerator::typeString(players[1]) << std::endl;
        cout << "PT2: " << GameModerator::typeString(players[2]) << std::endl;
        cout << "Game: " << domainString << " " << problemString << std::endl;
        cout << "nGames: " << nGames << std::endl;
        cout << "maxSamples: " << GameModerator::manySamples << std::endl;
        cout << "minSamples: " << GameModerator::fewSamples << std::endl;
        cout << "infoSet size: " << GameModerator::maxSize << std::endl;
    }
}