Class Segment
A contiguous part of a sequence.

Implements RandomAccessContainerConcept, SegmentableConcept
All Subcl's InfixSegment, PrefixSegment, SuffixSegment
All Impl'd AssignableConcept, ContainerConcept, DestructibleConcept, ForwardContainerConcept, RandomAccessContainerConcept, ReversibleContainerConcept, SegmentableConcept
Defined in <seqan/sequence.h>
Signature template <typename THost, typename TSpec> class Segment;

Template Parameters

THost The underlying sequence type.
TSpec The tag to use for selecting the Segment specialization.

Member Function Overview

Member Functions Inherited From AssignableConcept

Member Functions Inherited From RandomAccessContainerConcept

Interface Function Overview

Interface Functions Inherited From AssignableConcept

Interface Functions Inherited From ContainerConcept

Interface Functions Inherited From RandomAccessContainerConcept

Interface Functions Inherited From SegmentableConcept

Interface Metafunction Overview

Interface Metafunctions Inherited From ContainerConcept

Interface Metafunctions Inherited From SegmentableConcept

Detailed Description

Also known as:


Segments are lightweight representations of an underlying sequence (host). Only a pointer to the host and begin and/or end position have to be stored.

Segments support element access (reading and writing) as well as random access iteration.

    typedef seqan::Prefix<seqan::String<char> >::Type TPrefix;
    typedef seqan::Infix<seqan::String<char> >::Type  TInfix;
    typedef seqan::Suffix<seqan::String<char> >::Type TSuffix;

    seqan::String<char> text = "This is a text!";

    TPrefix preA(text, 4);
    TInfix infA(text, 10, 14);
    TSuffix sufA(text, 10);
    std::cout << preA << " " << infA << " " << sufA << "\n";  // => "This text text!"

    seqan::String<char> str;
    append(str, preA);
    append(str, infA);
    append(str, sufA);
    std::cout << str << "\n";  // => "This text text!"

    std::cout << preA[0] << " " << infA[0] << " " << sufA[0] << "\n";  // => "T t t"

    preA[0] = 'X';
    infA[0] = 'X';
    sufA[1] = 'X';
    std::cout << text << "\n";  // => "Xhis is a XXxt!"

    typedef seqan::Iterator<TInfix, seqan::Standard>::Type TIter;
    TIter it = begin(preA, seqan::Standard());
    it += 2;
    *it = 'Y';
    std::cout << text << "\n";  // => "XhYs is a XXxt!"

You can get the type of the infix/prefix/suffix of a sequence using Infix, Prefix, and Suffix. These metafunctions will "flatten" the type such that using these metafunctions, the infix of an infix is an infix and not an Infix Segment with an Infix Segment as its host. Instead, it will again be an Infix Segment of the host of the inner type.

A suffix of a suffix remains a suffix, a prefix of a prefix remains a prefix. Any other combination leads to the resulting type being a infix segment.

    typedef seqan::Infix<TInfix>::Type  TInfix2;  // == TInfix
    typedef seqan::Prefix<TInfix>::Type TInfix3;  // == TInfix
    typedef seqan::Suffix<TInfix>::Type TInfix4;  // == TInfix

    typedef seqan::Infix<TPrefix>::Type  TInfix5;   // == TInfix
    typedef seqan::Prefix<TPrefix>::Type TPrefix2;  // == TPrefix
    typedef seqan::Suffix<TPrefix>::Type TInfix6;   // == TInfix

    typedef seqan::Infix<TSuffix>::Type  TInfix7;   // == TInfix
    typedef seqan::Prefix<TSuffix>::Type TInfix8;   // == TPrefix
    typedef seqan::Suffix<TSuffix>::Type TSuffix2;  // == TSuffix

If you explicitely need a segment and keep the underlying sequence as it is, explicitely use the Segment template class.

    typedef seqan::Segment<TSuffix, seqan::PrefixSegment> TExplicitPrefix;
    TExplicitPrefix preB(sufA, 3);
    std::cout << preB << "\n";  // => "XXx"

Interface Functions Detail

TPos beginPosition(seg);

Return segment's begin position.


seg The Segment to query for its begin position.


TPos The begin position of the segment. TPos is the position type of the Segment as returned by Position.

TPos endPosition(seg);

Return segment's end position.


seg The Segment to query for its end position.


TPos The end position of the segment. TPos is the position type of the Segment as returned by Position.