static std::string combineStringVector(const StringVector& v) { if (v.empty()) return ""; if (v.size() == 1) return v.front(); std::string s = v.front(); for(StringVector::size_type i = 1;i < v.size();i++) s += " " + v[i]; return s; }
// Extend each leaf node void StringThreader::extendLeaves() { STNodePtrList newLeaves; for(STNodePtrList::iterator iter = m_leaves.begin(); iter != m_leaves.end(); ++iter) { StringVector extensions = getDeBruijnExtensions(*iter); // Either extend the current node or branch it // If no extension, do nothing and this node // is no longer considered a leaf if(extensions.size() == 1) { // Single extension, do not branch (*iter)->extend(extensions.front()); newLeaves.push_back(*iter); } else if(extensions.size() > 1) { // Branch for(size_t i = 0; i < extensions.size(); ++i) { StringThreaderNode* pAdded = (*iter)->createChild(extensions[i]); newLeaves.push_back(pAdded); } } } m_leaves.clear(); m_leaves = newLeaves; }
std::string MetAssemble::processKmer(const std::string& str, int count) { MetagenomeBuilder builder; builder.setSource(str, count); builder.setKmerParameters(m_parameters.kmer, m_parameters.kmerThreshold); builder.setIndex(m_parameters.pBWT, m_parameters.pRevBWT, m_parameters.pBWTCache, m_parameters.pRevBWTCache); builder.run(); StringVector contigs; builder.getContigs(contigs); std::string out = contigs.empty() ? "" : contigs.front(); //std::cout << "Constructed " << contigs.size() << " contigs from kmer (size: " << out.size() << ")\n"; return out; }
virtual void AfterReinstall(const string & id, DistInfo & dist) { ServerInstanceInfo inst( Name, id ); uid_t uid = mgr_user::Uid( inst.UserName ); string user_home_dir = getpwuid( uid )->pw_dir; mgr_file::Attrs attrs(0744, uid, mgr_user::GroupGid(inst.UserName)); const string link_dir = mgr_file::ConcatPath( user_home_dir, ".steam/sdk32/" ); mgr_file::MkDir( link_dir, &attrs ); mgr_file::MkLink( mgr_file::ConcatPath( inst.GetInstancePath(), "bin/steamclient.so" ), mgr_file::ConcatPath( link_dir, "steamclient.so" ) ); Debug( "Link to steamclient.so created" ); StringVector maps; GetMaps(inst, maps); if( !maps.empty() ) inst.SetParam( "map", maps.front() ); }
std::string parseVocationString(StringVector vocStringVec) { std::string str = ""; if(!vocStringVec.empty()) { for(StringVector::iterator it = vocStringVec.begin(); it != vocStringVec.end(); ++it) { if((*it) != vocStringVec.front()) { if((*it) != vocStringVec.back()) str += ", "; else str += " and "; } str += (*it); str += "s"; } } return str; }
void ycom::NullTermArray::eraseAppended (StringVector const &values) { typedef typename StringVector::iterator SVIterator; SVIterator storedNewStringsEnd = priv->storedNewStrings.end (); /* Start search from at least values.size () from the end */ auto searchStartPoint = storedNewStringsEnd - (values.size ()); SVIterator firstStoredNewStringsIterator = std::find (searchStartPoint, storedNewStringsEnd, values.front ()); if (firstStoredNewStringsIterator != storedNewStringsEnd) { typedef typename StringVector::const_iterator CSVIterator; auto stringsEqual = [](SVIterator const &lhs, CSVIterator const &rhs) -> bool { return *lhs == *rhs; }; auto lastStoredNewStringIterator = rangeMatchingPredicate (values, firstStoredNewStringsIterator, storedNewStringsEnd, stringsEqual); typedef std::vector <char const *>::iterator CVIterator; /* Handle the duplicate-pointers edge case by * starting from end - distance (first, last) - 1 */ CVIterator vectorEnd = priv->vector.end (); auto searchStartPoint = vectorEnd - std::distance (firstStoredNewStringsIterator, lastStoredNewStringIterator) - 1; auto pointerInVectorMatchingRawStringPointer = [&firstStoredNewStringsIterator](char const *str) -> bool { /* We want to compare the pointers, as it was pointers * that were inserted, not new values */ return firstStoredNewStringsIterator->c_str () == str; }; CVIterator firstPointerInVector = std::find_if (searchStartPoint, vectorEnd, pointerInVectorMatchingRawStringPointer); if (firstPointerInVector != vectorEnd) { auto stringEqualsCharacterArray = [](CVIterator const &lhs, CSVIterator const &rhs) -> bool { return *lhs == rhs->c_str (); }; auto lastPointerInVector = rangeMatchingPredicate (values, firstPointerInVector, vectorEnd, stringEqualsCharacterArray); /* Erase this from the vector of pointers */ priv->vector.erase (firstPointerInVector, lastPointerInVector); } /* Erase this block from the vector of stored * new strings */ priv->storedNewStrings.erase (firstStoredNewStringsIterator, lastStoredNewStringIterator); } }
//--------------------------------------------------------------------- void GLSLProgramManagerCommon::extractConstantDefs(const String& src, GpuNamedConstants& defs, const String& filename) { // Parse the output string and collect all uniforms // NOTE this relies on the source already having been preprocessed // which is done in GLSLProgram::loadFromSource String line; String::size_type currPos = src.find("uniform"); while (currPos != String::npos) { // Now check for using the word 'uniform' in a larger string & ignore bool inLargerString = false; if (currPos != 0) { char prev = src.at(currPos - 1); if (prev != ' ' && prev != '\t' && prev != '\r' && prev != '\n' && prev != ';') inLargerString = true; } if (!inLargerString && currPos + 7 < src.size()) { char next = src.at(currPos + 7); if (next != ' ' && next != '\t' && next != '\r' && next != '\n') inLargerString = true; } // skip 'uniform' currPos += 7; if (!inLargerString) { String::size_type endPos; GpuSharedParametersPtr blockSharedParams; // Check for a type. If there is one, then the semicolon is missing // otherwise treat as if it is a uniform block String::size_type lineEndPos = src.find_first_of("\n\r", currPos); line = src.substr(currPos, lineEndPos - currPos); StringVector parts = StringUtil::split(line, " \t"); StringToEnumMap::iterator typei = mTypeEnumMap.find(parts.front()); if (typei == mTypeEnumMap.end()) { // Gobble up the external name String externalName = parts.front(); // Now there should be an opening brace String::size_type openBracePos = src.find("{", currPos); if (openBracePos != String::npos) { currPos = openBracePos + 1; } else { LogManager::getSingleton().logMessage("Missing opening brace in GLSL Uniform Block in file " + filename); break; } // First we need to find the internal name for the uniform block String::size_type endBracePos = src.find("}", currPos); // Find terminating semicolon currPos = endBracePos + 1; endPos = src.find(";", currPos); if (endPos == String::npos) { // problem, missing semicolon, abort break; } // TODO: We don't need the internal name. Just skip over to the end of the block // But we do need to know if this is an array of blocks. Is that legal? // Find the internal name. // This can be an array. // line = src.substr(currPos, endPos - currPos); // StringVector internalParts = StringUtil::split(line, ", \t\r\n"); // String internalName = ""; // uint16 arraySize = 0; // for (StringVector::iterator i = internalParts.begin(); i != internalParts.end(); ++i) // { // StringUtil::trim(*i); // String::size_type arrayStart = i->find("[", 0); // if (arrayStart != String::npos) // { // // potential name (if butted up to array) // String name = i->substr(0, arrayStart); // StringUtil::trim(name); // if (!name.empty()) // internalName = name; // // String::size_type arrayEnd = i->find("]", arrayStart); // String arrayDimTerm = i->substr(arrayStart + 1, arrayEnd - arrayStart - 1); // StringUtil::trim(arrayDimTerm); // arraySize = StringConverter::parseUnsignedInt(arrayDimTerm); // } // else // { // internalName = *i; // } // } // // // Ok, now rewind and parse the individual uniforms in this block // currPos = openBracePos + 1; // blockSharedParams = GpuProgramManager::getSingleton().getSharedParameters(externalName); // if(blockSharedParams.isNull()) // blockSharedParams = GpuProgramManager::getSingleton().createSharedParameters(externalName); // do // { // lineEndPos = src.find_first_of("\n\r", currPos); // endPos = src.find(";", currPos); // line = src.substr(currPos, endPos - currPos); // // // TODO: Give some sort of block id // // Parse the normally structured uniform // parseIndividualConstant(src, defs, currPos, filename, blockSharedParams); // currPos = lineEndPos + 1; // } while (endBracePos > currPos); } else { // find terminating semicolon endPos = src.find(";", currPos); if (endPos == String::npos) { // problem, missing semicolon, abort break; } parseIndividualConstant(src, defs, currPos, filename, blockSharedParams); } line = src.substr(currPos, endPos - currPos); } // not commented or a larger symbol // Find next one currPos = src.find("uniform", currPos); } }
//--------------------------------------------------------------------- void GLSLESProgramManagerCommon::extractConstantDefs(const String& src, GpuNamedConstants& defs, const String& filename) { // Parse the output string and collect all uniforms // NOTE this relies on the source already having been preprocessed // which is done in GLSLESProgram::loadFromSource String line; String::size_type currPos = src.find("uniform"); while (currPos != String::npos) { GpuConstantDefinition def; String paramName; // Now check for using the word 'uniform' in a larger string & ignore bool inLargerString = false; if (currPos != 0) { char prev = src.at(currPos - 1); if (prev != ' ' && prev != '\t' && prev != '\r' && prev != '\n' && prev != ';') inLargerString = true; } if (!inLargerString && currPos + 7 < src.size()) { char next = src.at(currPos + 7); if (next != ' ' && next != '\t' && next != '\r' && next != '\n') inLargerString = true; } // skip 'uniform' currPos += 7; if (!inLargerString) { String::size_type endPos; String typeString; GpuSharedParametersPtr blockSharedParams; // Check for a type. If there is one, then the semicolon is missing // otherwise treat as if it is a uniform block String::size_type lineEndPos = src.find_first_of("\n\r", currPos); line = src.substr(currPos, lineEndPos - currPos); StringVector parts = StringUtil::split(line, " \t"); // Skip over precision keywords if(StringUtil::match((parts.front()), "lowp") || StringUtil::match((parts.front()), "mediump") || StringUtil::match((parts.front()), "highp")) typeString = parts[1]; else typeString = parts[0]; StringToEnumMap::iterator typei = mTypeEnumMap.find(typeString); if (typei == mTypeEnumMap.end()) { // Gobble up the external name String externalName = parts.front(); // Now there should be an opening brace String::size_type openBracePos = src.find("{", currPos); if (openBracePos != String::npos) { currPos = openBracePos + 1; } else { LogManager::getSingleton().logMessage("Missing opening brace in GLSL Uniform Block in file " + filename); break; } // First we need to find the internal name for the uniform block String::size_type endBracePos = src.find("}", currPos); // Find terminating semicolon currPos = endBracePos + 1; endPos = src.find(";", currPos); if (endPos == String::npos) { // problem, missing semicolon, abort break; } } else { // find terminating semicolon endPos = src.find(";", currPos); if (endPos == String::npos) { // problem, missing semicolon, abort break; } parseIndividualConstant(src, defs, currPos, filename, blockSharedParams); } line = src.substr(currPos, endPos - currPos); } // not commented or a larger symbol // Find next one currPos = src.find("uniform", currPos); } }
MetAssembleResult MetAssemble::process(const SequenceWorkItem& item) { MetAssembleResult result; SeqRecord currRead = item.read; std::string w = item.read.seq.toString(); if(w.size() <= m_parameters.kmer) { return result; } // Perform a backwards search using the read sequence // Check which k-mers have already been visited using the // shared bitvector. If any bit in the range [l,u] is set // for a suffix of the read, then we do not visit those kmers // later int len = w.size(); int num_kmers = len - m_parameters.kmer + 1; std::vector<bool> visitedKmers(false, num_kmers); int j = len - 1; char curr = w[j]; BWTInterval interval; BWTAlgorithms::initInterval(interval, curr, m_parameters.pBWT); --j; for(;j >= 0; --j) { curr = w[j]; BWTAlgorithms::updateInterval(interval, curr, m_parameters.pBWT); assert(interval.isValid()); // At this point interval represents the suffix [j,len) // Check if the starting point of this interval is set if(j < num_kmers) visitedKmers[j] = m_parameters.pBitVector->test(interval.lower); } // Process the kmers that have not been previously visited for(j = 0; j < num_kmers; ++j) { if(visitedKmers[j]) continue; // skip std::string kmer = w.substr(j, m_parameters.kmer); // Get the interval for this kmer BWTInterval interval = BWTAlgorithms::findIntervalWithCache(m_parameters.pBWT, m_parameters.pBWTCache, kmer); // Check if this interval has been marked by a previous iteration of the loop assert(interval.isValid()); if(m_parameters.pBitVector->test(interval.lower)) continue; BWTInterval rc_interval = BWTAlgorithms::findIntervalWithCache(m_parameters.pBWT, m_parameters.pBWTCache, reverseComplement(kmer)); size_t count = interval.size(); if(rc_interval.isValid()) count += rc_interval.size(); if(count >= m_parameters.kmerThreshold) { // Process the kmer std::string contig = processKmer(kmer, count); // We must determine if this contig has been assembled by another thread. // Break the contig into lexicographically ordered set of kmers. The lowest kmer is chosen // to represent the contig. If this kmer has been marked as visited, we discard the contig // otherwise we mark all kmers in the contig and output the contig. StringVector kmers = getLexicographicKmers(contig); // Get the lowest kmer in the set assert(!kmers.empty()); std::string lowest = kmers.front(); BWTInterval lowInterval = BWTAlgorithms::findIntervalWithCache(m_parameters.pBWT, m_parameters.pBWTCache, lowest); BWTInterval lowRCInterval = BWTAlgorithms::findIntervalWithCache(m_parameters.pBWT, m_parameters.pBWTCache, reverseComplement(lowest)); bool marked = false; // If the kmer exists in the read set (the interval is valid), we attempt to mark it // Otherwise, we attempt to mark its reverse complement. If either call succeeds // we output the contig. This block of code gives the synchronization between threads. // If multiple threads attempt to assemble the same contig, marked will be true for only // one of the threads. if(lowInterval.isValid()) marked = m_parameters.pBitVector->updateCAS(lowInterval.lower, false, true); else marked = m_parameters.pBitVector->updateCAS(lowRCInterval.lower, false, true); // Mark all the kmers in the contig so they will not be visited again markSequenceKmers(contig); // If the collision check passed, output the contig if(marked) { if(contig.size() >= m_parameters.minLength) result.contigs.push_back(contig); } } // Update the bit vector for the source kmer for(int64_t i = interval.lower; i <= interval.upper; ++i) m_parameters.pBitVector->updateCAS(i, false, true); for(int64_t i = rc_interval.lower; i <= rc_interval.upper; ++i) m_parameters.pBitVector->updateCAS(i, false, true); } return result; }