void append_and_preserve_iter(Sequence &s, const Sequence &r, Iterator &, std::forward_iterator_tag) { // Here we boldly assume that anything that is not random-access // preserves validity. This is valid for the STL sequences. s.insert(s.end(), r.begin(), r.end()); }
int getLongestCommonPrefix(const Sequence &A, const Sequence &B) { auto it = A.begin(); auto jt = B.begin(); while (it != A.end() && jt != B.end()) if ((*it) != (*jt)) return it - A.begin(); else it++, jt++; return it - A.begin(); }
void erase_unordered( Sequence& s, typename Sequence::iterator pos ) { assert( ! s.empty() && pos != s.end() ); typename Sequence::iterator last = s.end(); --last; if ( pos != last ) *pos = *last; // *pos = std::move( *last ); s.pop_back(); }
void append_and_preserve_iter(Sequence &s, const Sequence &r, Iterator &it, std::random_access_iterator_tag) { // Convert the iterator to an index, and later back. typename std::iterator_traits<Iterator>::difference_type idx = it - s.begin(); s.insert(s.end(), r.begin(), r.end()); it = s.begin() + idx; }
void erase_if_dispatch(Sequence& c, Predicate p, sequence_tag, IteratorStability) { #if 0 c.erase(std::remove_if(c.begin(), c.end(), p), c.end()); #else if (! c.empty()) c.erase(std::remove_if(c.begin(), c.end(), p), c.end()); #endif }
vector<Operation> getModifiedOperationSequence(const Sequence &left_data_sequence, const Sequence &right_data_sequence) { vector<Operation> result; assert(left_data_sequence.size() == right_data_sequence.size() + 1 || left_data_sequence.size() + 1 == right_data_sequence.size()); auto ptr1 = left_data_sequence.begin(), ptr2 = right_data_sequence.begin(); while (ptr1 != left_data_sequence.end() && ptr2 != right_data_sequence.end()) if ((*ptr1) == (*ptr2)) result.push_back(Operation(*(ptr1), 0)), ptr1++, ptr2++; else if (left_data_sequence.size() == right_data_sequence.size() + 1) result.push_back(Operation(*(ptr1), -1)), ptr1++; else result.push_back(Operation(*(ptr2), 1)), ptr2++; if (ptr1 != left_data_sequence.end()) result.push_back(Operation(*(ptr1), -1)); if (ptr2 != right_data_sequence.end()) result.push_back(Operation(*(ptr2), 1)); return result; }
void compute_stats(Sequence<double,Allocator>& value_list) { //Format: min max sum mean median double min_value = 0.0; double max_value = 0.0; strtk::min_max_of_cont(value_list,min_value,max_value); std::cout << min_value << "\t" << max_value << "\t"; double sum = std::accumulate(value_list.begin(),value_list.end(),0.0); std::cout << sum << "\t"; std::cout << sum / value_list.size() << "\t"; std::nth_element(value_list.begin(),value_list.begin() + (value_list.size() / 2), value_list.end()); std::cout << *(value_list.begin() + (value_list.size() / 2)) << "\t"; }
int main(void) { Sequence seq = { 0 }; // legnth = 0 으로 초기화 seq.push_back(5); seq.push_back(4); seq.push_back(3); seq.push_back(2); seq.push_back(1); seq.push_front(6); cout <<"size: " <<seq.size() <<endl; cout <<"contents: "; for ( int* p = seq.begin(); p != seq.end(); p = seq.next(p) ) { cout <<*p <<" "; } cout <<endl; #ifdef _MSC_VER // 윈도우즈 명령창이 닫혀서 쓰는 꼼수 printf("\n\nPress Enter key to exit ..."); getchar(); #endif return 0; }
void sequence_iteration( Sequence &_sequence, UpdateAction const &_update_action ) { for( auto it( _sequence.begin() ); it != _sequence.end(); ) { switch( _update_action( *it ) ) { case fcppt::algorithm::update_action::remove: it = _sequence.erase( it ); break; case fcppt::algorithm::update_action::keep: ++it; break; } } }
Range<typename Sequence::value_type> make_range(const Sequence & sequence) { typedef typename Sequence::value_type T; // TODO: in C++11 second template parameter class T = Sequence::value_type const Iterator<T> & begin = IteratorAdapter<T, typename Sequence::const_iterator>(sequence.begin()); const Iterator<T> & end = IteratorAdapter<T, typename Sequence::const_iterator>(sequence.end()); return Range<T>(begin, end); }
// la séquence initiale est lue et découpée en sous-séquences de // longueur 20 ; // chaque sous-séquence est terminée par une observation END pour que // le HMM généré possède un état terminal Sequences build_initial_sequences(const std::string& name) { Sequence sequence = read_initial_sequence(name, false); Sequences sequences; unsigned int length = sequence.size() / 20; Sequence::const_iterator it = sequence.begin(); unsigned int added = 0; unsigned int index = 0; sequences.push_back(Sequence()); while (it != sequence.end()) { if (added == length) { sequences[index].push_back(Observation(0, END)); ++index; added = 0; sequences.push_back(Sequence()); } sequences[index].push_back(*it); ++added; ++it; } if (sequence.size() % 20 != 0) { sequences[index].push_back(Observation(0, END)); } return sequences; }
QKeySequence KeyLogger::keySequence(const Sequence & sequence) { int sum = std::accumulate(sequence.begin(), sequence.end(), 0, std::plus<int>()); return QKeySequence(sum); }
void Path::stitch(Sequence::iterator first_replaced, Sequence::iterator last_replaced, Sequence &source) { if (!source.empty()) { if ( first_replaced != get_curves().begin() ) { if ( (*first_replaced)->initialPoint() != source.front()->initialPoint() ) { Curve *stitch = new StitchSegment((*first_replaced)->initialPoint(), source.front()->initialPoint()); source.insert(source.begin(), boost::shared_ptr<Curve>(stitch)); } } if ( last_replaced != (get_curves().end()-1) ) { if ( (*last_replaced)->finalPoint() != source.back()->finalPoint() ) { Curve *stitch = new StitchSegment(source.back()->finalPoint(), (*last_replaced)->finalPoint()); source.insert(source.end(), boost::shared_ptr<Curve>(stitch)); } } } else if ( first_replaced != last_replaced && first_replaced != get_curves().begin() && last_replaced != get_curves().end()-1) { if ( (*first_replaced)->initialPoint() != (*(last_replaced-1))->finalPoint() ) { Curve *stitch = new StitchSegment((*(last_replaced-1))->finalPoint(), (*first_replaced)->initialPoint()); source.insert(source.begin(), boost::shared_ptr<Curve>(stitch)); } } }
vector<Operation> getOperationSequence(const Sequence &data_sequence, const int operation_type) { vector<Operation> result; for (auto it = data_sequence.begin(); it != data_sequence.end(); it++) result.push_back(Operation((*it), operation_type)); return result; }
ExprReturnSP LitMatrixExprReturn::multiply( LitMatrixExprReturn &litMatrixExprReturn ) { __int64 rows1, columns1; getRowsAndColumns( rows1, columns1 ); __int64 rows2, columns2; litMatrixExprReturn.getRowsAndColumns( rows2, columns2 ); if ( rows1 == 1 && columns1 == 1 ) { double multiplier = getSequence()[0]; Sequence sequence = litMatrixExprReturn.getSequence(); for( Sequence::iterator sqnItr = sequence.begin() ; sqnItr != sequence.end() ; (void)++sqnItr ) { *sqnItr *= multiplier; } return create( getBlock(), litMatrixExprReturn.getDT(), sequence ); } if ( rows2 == 1 && columns2 == 1 ) { double multiplier = litMatrixExprReturn.getSequence()[0]; Sequence sequence = getSequence(); for( Sequence::iterator sqnItr = sequence.begin() ; sqnItr != sequence.end() ; (void)++sqnItr ) { *sqnItr *= multiplier; } return create( getBlock(), getDT(), sequence ); } if ( columns1 != rows2 ) { if ( ( rows1 == 1 || columns1 == 1 ) && rows1 == rows2 ) std::swap( rows1, columns1 ); else if ( ( rows2 == 1 || columns2 == 1 ) && columns1 == columns2 ) std::swap( rows2, columns2 ); else { /* THROW ERROR */ } } Sequence sequence; Sequence &rhsSequence = litMatrixExprReturn.getSequence(); for( long long ix = 0 ; ix < rows1 ; (void)++ix ) { for( long long jx = 0 ; jx < columns2 ; (void)++jx ) { double sum = 0; for( long long kx = 0 ; kx < columns1 ; (void)++kx ) { sum += getSequence()[ ix*rows1 + kx ] * rhsSequence[ kx*rows2 + jx ]; } sequence.push_back( sum ); } } SFC::DT dominantDT = SFCTypesManager::getDominantType( getDT(), litMatrixExprReturn.getDT() ); return create( getBlock(), (int) rows1, (int) columns2, dominantDT, sequence ); }
void mark( MultiArray& m,const Sequence& pts, const point& p,int dx,int dy) { for(int k=p.x<0||p.y<0||p.x>=m.shape()[0]||p.y>=m.shape()[1]?1:0, k_end=distZ2inf(p,pts.begin(),pts.end()); k<k_end; ++k) { int x=p.x-k*dx; int y=p.y-k*dy; if(x>=0&&y>=0&&x<m.shape()[0]&&y<m.shape()[1])m[x][y]=true; } }
static void test_assign(BOOST_EXPLICIT_TEMPLATE_TYPE(Sequence)) { Sequence s; int a[]={0,1,2,3,4,5}; std::size_t sa=sizeof(a)/sizeof(a[0]); s.assign(&a[0],&a[sa]); BOOST_CHECK(s.size()==sa&&std::equal(s.begin(),s.end(),&a[0])); s.assign(&a[0],&a[sa]); BOOST_CHECK(s.size()==sa&&std::equal(s.begin(),s.end(),&a[0])); s.assign((std::size_t)18,37); BOOST_CHECK(s.size()==18&&std::accumulate(s.begin(),s.end(),0)==666); s.assign((std::size_t)12,167); BOOST_CHECK(s.size()==12&&std::accumulate(s.begin(),s.end(),0)==2004); }
Sequence CollationImpl::sort(Sequence data, const DynamicContext* context) const { // build a sequence made of strings Sequence stringSeq = Sequence(data.getLength(), context->getMemoryManager()); for(Sequence::iterator it=data.begin(); it!=data.end(); ++it) { const XMLCh *str = (*it)->asString(context); stringSeq.addItem(context->getItemFactory()->createString(str, context).get()); } stringSeq.sortWithCollation(this, context); return stringSeq; }
Sequence colourToNucleotideSpace(char anchor, const Sequence& seq) { int seed = baseToCode(anchor); ostringstream s; s << anchor; for (string::const_iterator it = seq.begin(); it != seq.end(); ++it) { seed = cstont[seed][baseToCode(*it)]; s << codeToBase(seed); } return s.str(); }
bool checkCorrectionSequence(const vector<Operation> &result, const Sequence &left_data_sequence, const Sequence &right_data_sequence) { auto it = left_data_sequence.begin(), jt = right_data_sequence.begin(); for (size_t i = 0; i < result.size(); i++) { if (result[i].type == 1) { if (jt != right_data_sequence.end() && (*jt) == result[i].value) jt++; else { cerr << "Wrong action " << result[i].type << ' ' << result[i].value << " at position " << i << endl; return false; } } else if (result[i].type == -1) { if (it != left_data_sequence.end() && (*it) == result[i].value) it++; else { cerr << "Wrong action " << result[i].type << ' ' << result[i].value << " at position " << i << endl; return false; } } else { if (it != left_data_sequence.end() && (*it) == result[i].value && jt != right_data_sequence.end() && (*jt) == result[i].value) it++, jt++; else { cerr << "Wrong action " << result[i].type << ' ' << result[i].value << " at position " << i << endl; return false; } } } return true; }
// construit une table avec les différentes valeurs d'une séquence et // compte le nombre d'itérations Table get_unique(const Sequence& sequence) { Table unique; Sequence::const_iterator it = sequence.begin(); while (it != sequence.end()) { if (unique.find(*it) == unique.end()) { unique[*it] = 1; } else { unique[*it]++; } ++it; } return unique; }
MatrixExprReturnSP LitMatrixExprReturn::appendRows( LitMatrixExprReturn &litMatrixExprReturn ) { __int64 thisRows, thisColumns; getRowsAndColumns( thisRows, thisColumns ); if ( thisRows == 0 ) return LitMatrixExprReturn::create( litMatrixExprReturn ); __int64 rhsRows, rhsColumns; litMatrixExprReturn.getRowsAndColumns( rhsRows, rhsColumns ); if ( rhsRows == 0 ) return LitMatrixExprReturn::create( *this ); assert( thisColumns == rhsColumns ); Sequence sequence = getSequence(); sequence.insert( sequence.end(), litMatrixExprReturn.getSequence().begin(), litMatrixExprReturn.getSequence().end() ); SFC::DT dominantDT = SFCTypesManager::getDominantType( getDT(), litMatrixExprReturn.getDT() ); return create( getBlock(), (int) thisRows + rhsRows, (int) thisColumns, dominantDT, sequence ); }
/** Return a consensus sequence of a and b. * @return an empty string if a consensus could not be found */ static string createConsensus(const Sequence& a, const Sequence& b) { assert(a.length() == b.length()); if (a == b) return a; string s; s.reserve(a.length()); for (string::const_iterator ita = a.begin(), itb = b.begin(); ita != a.end(); ++ita, ++itb) { bool mask = islower(*ita) || islower(*itb); char ca = toupper(*ita), cb = toupper(*itb); char c = ca == cb ? ca : ca == 'N' ? cb : cb == 'N' ? ca : 'x'; if (c == 'x') return string(""); s += mask ? tolower(c) : c; } return s; }
int main() { /////////////////////////// DSS4 ////////////////////////////////// { typedef PointVector<2,int> Point; typedef std::vector<Point> Sequence; typedef std::vector<Point>::iterator Iterator; typedef ArithmeticalDSS<Iterator,int,4> DSS4; // Input points Sequence contour; contour.push_back(Point(0,0)); contour.push_back(Point(1,0)); contour.push_back(Point(1,1)); contour.push_back(Point(2,1)); contour.push_back(Point(3,1)); contour.push_back(Point(3,2)); contour.push_back(Point(4,2)); contour.push_back(Point(5,2)); contour.push_back(Point(6,2)); contour.push_back(Point(6,3)); contour.push_back(Point(6,4)); // Add points while it is possible DSS4 theDSS4; Iterator i = contour.begin(); theDSS4.init(i); i++; while ( (i!=contour.end()) &&(theDSS4.extend(i)) ) { i++; } // Output parameters cout << theDSS4 << endl; // Draw the grid DGtalBoard board; Domain domain( Point(0,0), Point(8,8) ); board << SetMode(domain.styleName(), "Grid") << domain; // Draw the points of the DSS board << SetMode("PointVector", "Grid") << SetMode(theDSS4.styleName(), "Points") << theDSS4; // Draw the bounding box board << SetMode(theDSS4.styleName(), "BoundingBox") << theDSS4; board.saveSVG("DSS4.svg"); } ////////////////////// DSS8 /////////////////////////////// { typedef PointVector<2,int> Point; typedef std::vector<Point> Sequence; typedef std::vector<Point>::iterator Iterator; typedef ArithmeticalDSS<Iterator,int,8> DSS8; // Input points std::vector<Point> boundary; boundary.push_back(Point(0,0)); boundary.push_back(Point(1,1)); boundary.push_back(Point(2,1)); boundary.push_back(Point(3,2)); boundary.push_back(Point(4,2)); boundary.push_back(Point(5,2)); boundary.push_back(Point(6,3)); boundary.push_back(Point(6,4)); // Add points while it is possible DSS8 theDSS8; Iterator i = boundary.begin(); theDSS8.init(i); i++; while ( (i!=boundary.end()) &&(theDSS8.extend(i)) ) { i++; } // Output parameters cout << theDSS8 << endl; //Draw the pixels DGtalBoard board; Domain domain( Point(0,0), Point(8,8) ); board << SetMode(domain.styleName(), "Paving") << domain; //Draw the points of the DSS board << SetMode("PointVector", "Both"); board << SetMode(theDSS8.styleName(), "Points") << theDSS8; //Draw the bounding box of the DSS board << SetMode(theDSS8.styleName(), "BoundingBox") << theDSS8; board.saveSVG("DSS8.svg"); } return 1; }
static Real maxError(const Sequence& sequence) { return *std::max_element(sequence.begin(), sequence.end()); }
void erase_dispatch(Sequence& c, const T& x, sequence_tag) { c.erase(std::remove(c.begin(), c.end(), x), c.end()); }
// Evolve rNode a specific time void Tree::Evolve(Node &rNode, double dTime) { dTime = fabs(dTime); if(dTime < DBL_EPSILON) return; // Nothing to evolve //advance branch color branchColor += Nucleotide::ColorInc; // Substitutions unsigned int uNuc = 0; for(vector<Sequence>::iterator it = rNode.m_vSections.begin(); it != rNode.m_vSections.end(); ++it) { for(Sequence::iterator jt = it->begin(); jt != it->end(); ++jt) { // Skip any position that is a deletion if(jt->IsDeleted()) continue; // Total Evolution Rate for the position double dTemp = dTime*jt->GetRate(); if(dTemp < DBL_EPSILON) continue; // Invariant Site // if dTemp is different from the previous one, recalculate probability matrix if(dTemp != m_dOldTime) { m_dOldTime = dTemp; Vector4 vec; vec[0] = exp(dTemp*m_vecL[0]); vec[1] = exp(dTemp*m_vecL[1]); vec[2] = exp(dTemp*m_vecL[2]); vec[3] = exp(dTemp*m_vecL[3]); Matrix44 mat; mat.Scale(vec, m_matU); m_matSubst.Multiply(m_matV, mat); for(Matrix44::Pos i=0;i<4;++i) { m_matSubst(i,1) += m_matSubst(i,0); m_matSubst(i,2) += m_matSubst(i,1); //m_matSubst(i,3) = 1.0; } } // get the base of the current nucleotide and pick new base unsigned int uBase = jt->GetBase(); dTemp = rand_real(); if(dTemp < m_matSubst(uBase, 0)) jt->SetBase(0); else if(dTemp < m_matSubst(uBase, 1)) jt->SetBase(1); else if(dTemp < m_matSubst(uBase, 2)) jt->SetBase(2); else jt->SetBase(3); ++uNuc; // Increase position } } // Indel formation via Gillespie Algorithm // Check whether Indels are off if(m_dLambdaDel+m_dLambdaIns < DBL_EPSILON) return; // Get current length Sequence::size_type uLength = rNode.SeqLength(); double dLength = (double)uLength; double dW = 1.0/m_funcRateSum(dLength); // Do indels for(double dt = rand_exp(dW); dt <= dTime; dt += rand_exp(dW)) { // insertion or deletion if(rand_bool(m_funcRateIns(dLength)*dW)) { //Insertion Sequence::size_type ul = m_pInsertionModel->RandSize(); Sequence::size_type uPos = (Sequence::size_type)rand_uint((uint32_t)uLength); // pos is in [0,L] // Construct sequence to be inserted Sequence seq; for(unsigned int uc = 0; uc < ul; ++uc) { Nucleotide nuc = RandomNucleotide(uc); nuc.SetColor(branchColor); seq.push_back(nuc); } // Find Position of Insertion Node::iterator itPos = rNode.SeqPos(uPos); if(itPos.first == rNode.m_vSections.end()) { // Insert at end of sequence uLength += rNode.m_vSections.back().Insertion( rNode.m_vSections.back().end(), seq.begin(), seq.end()); } else { // Insert inside sequence uLength += itPos.first->Insertion(itPos.second, seq.begin(), seq.end()); } } else if(uLength > 0) { // Deletion // Draw random size and random pos and rearrange Sequence::size_type ul = m_pDeletionModel->RandSize(); Sequence::size_type uPos = rand_uint((uint32_t)(uLength+ul-2)); Sequence::size_type uB = max(ul-1, uPos); Sequence::size_type uSize = min(ul-1+uLength, uPos+ul)-uB; // If GapLimits are on, only process deletion if it is completely inside the acceptance // region as defined by the GapLimit. Check points are at sequence positions 0-uKeepFlank and // uLength-1+uKeepFlank. These become 0-uKeepFlank+ul-1 and uLength-1+uKeepFlank+ul-1, // when shifted to "deletion space". if(m_uKeepFlank == 0 || ( (ul-1) < uPos+m_uKeepFlank && uPos < uLength-1+m_uKeepFlank ) ) { uB -= (ul-1); // Find deletion point Node::iterator itPos = rNode.SeqPos(uB); Sequence::size_type uTemp = uSize; uTemp -= itPos.first->Deletion(itPos.second, uTemp); // Delete uSize nucleotides begin sensitive to gaps that overlap sections for(++itPos.first; uSize && itPos.first != rNode.m_vSections.end(); ++itPos.first) uTemp -= itPos.first->Deletion(itPos.first->begin(), uTemp); uLength -= (uSize-uTemp); } } // update length dLength = (double)uLength; // new waiting time parameter dW = 1.0/m_funcRateSum(dLength); } }
static void test_list_ops_non_unique_seq( BOOST_EXPLICIT_TEMPLATE_TYPE(Sequence)) { typedef typename Sequence::iterator iterator; Sequence ss; for(int i=0;i<10;++i){ ss.push_back(i); ss.push_back(i); ss.push_front(i); ss.push_front(i); } /* 9988776655443322110000112233445566778899 */ ss.unique(); CHECK_EQUAL( ss, {9 _ 8 _ 7 _ 6 _ 5 _ 4 _ 3 _ 2 _ 1 _ 0 _ 1 _ 2 _ 3 _ 4 _ 5 _ 6 _ 7 _ 8 _ 9}); iterator it=ss.begin(); for(int j=0;j<9;++j,++it){} /* it points to o */ Sequence ss2; ss2.splice(ss2.end(),ss,ss.begin(),it); ss2.reverse(); ss.merge(ss2); CHECK_EQUAL( ss, {0 _ 1 _ 1 _ 2 _ 2 _ 3 _ 3 _ 4 _ 4 _ 5 _ 5 _ 6 _ 6 _ 7 _ 7 _ 8 _ 8 _ 9 _ 9}); ss.unique(same_integral_div<3>()); CHECK_EQUAL(ss,{0 _ 3 _ 6 _ 9}); ss.unique(same_integral_div<1>()); CHECK_EQUAL(ss,{0 _ 3 _ 6 _ 9}); /* testcases for bugs reported at * http://lists.boost.org/boost-users/2006/09/22604.php */ { Sequence ss,ss2; ss.push_back(0); ss2.push_back(0); ss.splice(ss.end(),ss2,ss2.begin()); CHECK_EQUAL(ss,{0 _ 0}); BOOST_CHECK(ss2.empty()); ss.clear(); ss2.clear(); ss.push_back(0); ss2.push_back(0); ss.splice(ss.end(),ss2,ss2.begin(),ss2.end()); CHECK_EQUAL(ss,{0 _ 0}); BOOST_CHECK(ss2.empty()); ss.clear(); ss2.clear(); ss.push_back(0); ss2.push_back(0); ss.merge(ss2); CHECK_EQUAL(ss,{0 _ 0}); BOOST_CHECK(ss2.empty()); typedef typename Sequence::value_type value_type; ss.clear(); ss2.clear(); ss.push_back(0); ss2.push_back(0); ss.merge(ss2,std::less<value_type>()); CHECK_EQUAL(ss,{0 _ 0}); BOOST_CHECK(ss2.empty()); } }
template <typename Sequence> inline std::string make_string(Sequence const &seq) { return std::string(seq.begin(), seq.end()); }
template <typename Sequence> inline range<typename Sequence::const_iterator> make_range(Sequence const &seq) { return range<typename Sequence::const_iterator>(seq.begin(), seq.end()); }