Egglib 2.1.11
C++ library reference manual
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Container Class Reference

Handles a set of sequence alignment (aligned or not) More...

#include <Container.hpp>

Inheritance diagram for Container:
Align

Public Member Functions

 Container ()
 Creates an empty object. More...
 
 Container (const Container &source)
 Copy constructor. More...
 
Containeroperator= (const Container &source)
 Assignment operator. More...
 
 Container (unsigned int number_of_sequences, char const *const *const cstring_array)
 Creates an object from a data matrix. More...
 
virtual ~Container ()
 Destructor. More...
 
virtual void clear ()
 Clears all content of the object. More...
 
virtual unsigned int append (const char *name, const char *sequence, unsigned int group=0)
 Adds a sequence to the object. More...
 
virtual unsigned int remove (unsigned int pos)
 Removes a sequence from the object. More...
 
virtual void name (unsigned int pos, const char *name)
 Changes the name of a given sequence. More...
 
virtual void sequence (unsigned int pos, const char *sequence)
 Changes the sequence string of a given sequence. More...
 
virtual void appendSequence (unsigned int pos, const char *sequence)
 Appends a string to the a given sequence. More...
 
virtual void set (unsigned int sequence, unsigned position, char ch)
 Changes a character. More...
 
virtual char get (unsigned int s, unsigned int p) const
 Gets a given character. More...
 
virtual void group (unsigned int pos, unsigned int group)
 Changes the group index of a given sequence. More...
 
Container hslice (unsigned int a, unsigned int b) const
 Extracts a range of sequences. More...
 
unsigned int ns () const
 Gets the number of sequences. More...
 
virtual unsigned int ls (unsigned int pos) const
 Gets the length of a given sequence. More...
 
virtual const char * name (unsigned int pos) const
 Gets the name of the a given sequence. More...
 
virtual const char * sequence (unsigned int pos) const
 Gets the name of a given sequence. More...
 
virtual unsigned int group (unsigned int pos) const
 Gets the group index of a given sequence. More...
 
bool isEqual () const
 Checks if all lengths are equal. More...
 
unsigned int equalize (char ch='?')
 Equalizes sequence lengths. More...
 
int find (const char *string, bool strict=true) const
 Finds a sequence by its name. More...
 

Protected Member Functions

virtual void setFromSource (unsigned int number_of_sequences, const char *const *const cstring_array)
 
virtual void copyObject (const Container &)
 
virtual void getNamesAndGroups (const Container &)
 

Protected Attributes

unsigned int _ns
 
unsigned int * lnames
 
char ** names
 
char ** sequences
 
unsigned int * groups
 

Detailed Description

Handles a set of sequence alignment (aligned or not)

Creation from a file or string stream should be performed using the class Fasta.

Sequences are represented by two strings (name and sequence) and an integer (group) that can be accessed or modified by index.The order of sequences is guaranteed to be conserved, as if Container was a list of triplets (name, sequence, group).

The data matrix is implemented as continuous arrays (char**) and allows efficient access and modification of data. For very large data matrices you might claim immediately the required memory using the constructor Container(unsigned int, char**).

Constructor & Destructor Documentation

Container ( )

Creates an empty object.

Container ( const Container source)

Copy constructor.

Container ( unsigned int  number_of_sequences,
char const *const *const  cstring_array 
)

Creates an object from a data matrix.

Allows you to create an object from data stored in a char* array. The array's size must be passed to the constructor. Since sequences can have different lengths, you need to terminate each sequence by a NULL character. This constructor is dedicated to very performance-critical tasks. For usual tasks, using the default constructor and subsequently adding sequences with addSeq should be enough.

Parameters
number_of_sequencesthe number of sequences (the length of the first dimension of the array).
cstring_arraythe pointer to the data matrix.
~Container ( )
virtual

Destructor.

Member Function Documentation

unsigned int append ( const char *  name,
const char *  sequence,
unsigned int  group = 0 
)
virtual

Adds a sequence to the object.

Parameters
namethe name of the sequence, as a c-string.
sequencethe sequence string, as a c-string.
groupthe group index of the sequence.
Returns
The new number of sequences.

Reimplemented in Align.

void appendSequence ( unsigned int  pos,
const char *  sequence 
)
virtual

Appends a string to the a given sequence.

Parameters
posthe sequence index.
sequencethe sequence to append at the end of the current one.

Reimplemented in Align.

void clear ( )
virtual

Clears all content of the object.

Reimplemented in Align.

unsigned int equalize ( char  ch = '?')

Equalizes sequence lengths.

Extends sequences as need to ensure that all sequences have the same length.

Parameters
chthe character to use for padding.
Returns
The final length obtained, which is the length of the longest sequence before the operation.
int find ( const char *  string,
bool  strict = true 
) const

Finds a sequence by its name.

Gets the position of the first sequence with the specified name.

Parameters
stringa sequence name.
strictif true, seeks an exact match. If false, compares only until the end of the requested name (for example: ATCFF will match ATCFF_01 if strict is false).
Returns
The lowest index where the name matches, -1 if no sequence has such name.
char get ( unsigned int  s,
unsigned int  p 
) const
virtual

Gets a given character.

Parameters
sthe sequence index.
pthe character index.
Returns
the character value.

The positions must fit in the current ranges.

Reimplemented in Align.

void group ( unsigned int  pos,
unsigned int  group 
)
virtual

Changes the group index of a given sequence.

Parameters
posthe sequence index.
groupthe new group index value.
unsigned int group ( unsigned int  pos) const
virtual

Gets the group index of a given sequence.

Parameters
posthe index of the sequence.
Returns
The group index of that particular sequence.
Container hslice ( unsigned int  a,
unsigned int  b 
) const

Extracts a range of sequences.

Parameters
athe index of the first sequence.
bthe index immediately passed the last sequence to extract.
Returns
A copy of the object containing the specified range of sequences.

Sequences a to b-1 are extracted, provided that the indices fit in the current number of sequences. To extract all sequences, use container.hslice(0, container.ns()).

Note: invalid ranges will be silently supported. If a>=ls or b<=a, an empty object is returned. If b>ns, ls will be substituted to a.

bool isEqual ( ) const

Checks if all lengths are equal.

Returns true if the length of all sequences are equal or if there is less thant two sequences.

unsigned int ls ( unsigned int  pos) const
virtual

Gets the length of a given sequence.

Parameters
posthe index of the sequence.
Returns
The length of that particular sequence.

Reimplemented in Align.

void name ( unsigned int  pos,
const char *  name 
)
virtual

Changes the name of a given sequence.

Parameters
posthe sequence index.
namethe new name as a C-like string.
const char * name ( unsigned int  pos) const
virtual

Gets the name of the a given sequence.

Parameters
posthe index of the sequence.
Returns
The name of that particular sequence.
unsigned int ns ( ) const

Gets the number of sequences.

Container & operator= ( const Container source)

Assignment operator.

unsigned int remove ( unsigned int  pos)
virtual

Removes a sequence from the object.

Parameters
posthe index of the sequence to remove.
Returns
The new number of sequences.

Reimplemented in Align.

void sequence ( unsigned int  pos,
const char *  sequence 
)
virtual

Changes the sequence string of a given sequence.

Parameters
posthe sequence index.
sequencethe new sequence as a C-like string.

Reimplemented in Align.

const char * sequence ( unsigned int  pos) const
virtual

Gets the name of a given sequence.

Parameters
posthe index of the sequence.
Returns
The sequence string for that particular sequence.

Reimplemented in Align.

void set ( unsigned int  sequence,
unsigned  position,
char  ch 
)
virtual

Changes a character.

Parameters
sequencethe sequence index.
positionthe character index.
chthe new character value.

The positions must fit in the current ranges.

Reimplemented in Align.


The documentation for this class was generated from the following files:

Hosted by 
Get EggLib at SourceForge.net. Fast, secure and Free Open Source software downloads