bpp-core3
3.0.0
|
This class corresponds to a 'dataset', i.e. a table with data by rows and variable by columns. More...
#include <Bpp/Numeric/Table.h>
Public Member Functions | |
Table (size_t nRow, size_t nCol) | |
Build a new void Table object with nRow rows and nCol columns. More... | |
Table (const std::vector< std::string > &colNames) | |
Build a new void Table object with named columns. More... | |
Table (const Table &table) | |
Table (const std::vector< std::vector< T > > &vt) | |
Table & | operator= (const Table &table) |
Table & | operator= (const std::vector< std::vector< T > > &vt) |
Table * | clone () const |
Create a copy of this object and send a pointer to it. More... | |
virtual | ~Table () |
const std::vector< std::vector< T > > & | getData () const |
T & | operator() (size_t rowIndex, size_t colIndex) |
const T & | operator() (size_t rowIndex, size_t colIndex) const |
T & | operator() (const std::string &rowName, const std::string &colName) |
const T & | operator() (const std::string &rowName, const std::string &colName) const |
T & | operator() (const std::string &rowName, size_t colIndex) |
const T & | operator() (const std::string &rowName, size_t colIndex) const |
T & | operator() (size_t rowIndex, const std::string &colName) |
const T & | operator() (size_t rowIndex, const std::string &colName) const |
Work on columns. | |
size_t | getNumberOfColumns () const |
void | setColumnNames (const std::vector< std::string > &colNames) |
Set the column names of this table. More... | |
const std::vector< std::string > & | getColumnNames () const |
Get the column names of this table. More... | |
std::vector< std::string > & | getColumnNames () |
std::string | getColumnName (size_t index) const |
Get a given column name. More... | |
bool | hasColumnNames () const |
std::vector< T > & | getColumn (size_t index) |
const std::vector< T > & | getColumn (size_t index) const |
std::vector< T > & | getColumn (const std::string &colName) |
const std::vector< T > & | getColumn (const std::string &colName) const |
bool | hasColumn (const std::string &colName) const |
Tell is a given column exists. More... | |
void | deleteColumn (size_t index) |
Delete the given column. More... | |
void | deleteColumn (const std::string &colName) |
Delete the given column. More... | |
void | addColumn (const std::vector< T > &newColumn, int pos=-1) |
Add a new column. More... | |
void | addColumn (const std::string &colName, const std::vector< T > &newColumn, int pos=-1) |
Add a new column. More... | |
void | addColumn (std::string &st, const std::string &sep="\t", int pos=-1, int rowCol=-1) |
Add a new column. More... | |
void | setColumn (const std::vector< T > &newColumn, size_t pos) |
Set a new column. More... | |
void | setColumn (const std::string &colName, const std::vector< T > &newColumn, size_t pos) |
Set a new column. More... | |
Work on rows. | |
size_t | getNumberOfRows () const |
void | setRowNames (const std::vector< std::string > &rowNames) |
Set the row names of this table. More... | |
std::vector< std::string > | getRowNames () |
Get the row names of this table. More... | |
const std::vector< std::string > & | getRowNames () const |
bool | hasRow (const std::string &rowName) const |
Tell is a given row exists. More... | |
std::string | getRowName (size_t index) const |
Get a given row name. More... | |
bool | hasRowNames () const |
std::vector< T > | getRow (size_t index) const |
std::vector< T > | getRow (const std::string &rowName) const |
void | deleteRow (size_t index) |
Delete the given row. More... | |
void | deleteRows (size_t index, size_t len) |
Delete the given rows. More... | |
void | deleteRow (const std::string &rowName) |
Delete the given row. More... | |
void | addRow (const std::vector< T > &newRow, int pos=-1) |
Add a new row. More... | |
void | addRow (const std::string &rowName, const std::vector< T > &newRow, int pos=-1) |
Add a new row at a given position. More... | |
void | addRow (std::string &st, const std::string &sep="\t", int pos=-1, int rowCol=-1) |
Add a new row. More... | |
Static Public Member Functions | |
static Table< T > * | read (std::istream &in, bool byRow, const std::string &sep="\t", bool header=true, int names=-1) |
Read a table form a stream in CSV-like. More... | |
static void | write (const Table &data, std::ostream &out, bool byRow, const std::string &sep="\t", bool alignHeaders=false) |
Write a Table object to stream in CVS-like format. More... | |
static void | write (const Table &data, bpp::OutputStream &out, bool byRow, const std::string &sep="\t", bool alignHeaders=false) |
Protected Attributes | |
size_t | nRow_ |
size_t | nCol_ |
std::vector< std::vector< T > > | data_ |
std::vector< std::string > | rowNames_ |
std::vector< std::string > | colNames_ |
This class corresponds to a 'dataset', i.e. a table with data by rows and variable by columns.
Data are stored as T objects, by column.
|
inline |
Build a new void Table object with nRow rows and nCol columns.
Definition at line 83 of file Table.h.
References bpp::Table< T >::data_.
Referenced by bpp::Table< T >::clone().
|
inline |
Build a new void Table object with named columns.
colNames | The names of the columns of the Table. |
DuplicatedTableColumnNameException | If colnames contains identical names. |
Definition at line 103 of file Table.h.
References bpp::Table< T >::setColumnNames().
|
inline |
|
inline |
|
inlinevirtual |
|
inline |
Add a new column.
colName | The name of the column. |
newColumn | The new column values. |
pos | The position optional (default : -1 for nb columns) |
DimensionException | If the number of values does not match the number of rows. |
NoTableColumnNamesException | If the table does not have row names. |
DuplicatedTableColumnNameException | If colName is already used. |
Definition at line 595 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.
|
inline |
Add a new column.
newColumn | The new column values. |
pos | The position optional (default : -1 for nb columns) |
DimensionException | If the number of values does not match the number of rows. |
TableColumnNamesException | If the table has row names. |
Definition at line 569 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.
Referenced by bpp::Table< T >::read().
|
inline |
Add a new column.
st | the input sting |
sep | The row delimiter |
pos | The position optional (default : nb cols) |
rowCol | the indice of row where colnames are, starting from 0 (default -1 means no such column) |
Definition at line 624 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::StringTokenizer::getTokens(), bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.
|
inline |
Add a new row at a given position.
rowName | The name of the row. |
newRow | The new row values. |
pos | The position optional (default : -1 for nb rows) |
Definition at line 957 of file Table.h.
References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.
|
inline |
Add a new row.
newRow | The new row values. |
pos | The position optional (default : -1 for nb rows) |
Definition at line 931 of file Table.h.
References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.
Referenced by bpp::Table< T >::read().
|
inline |
Add a new row.
st | the input string |
sep | The column delimiter |
pos | The position optional (default : nb rows) |
rowCol | the indice of column where rownames are, starting from 0 (default -1 means no such column) |
Definition at line 988 of file Table.h.
References bpp::Table< T >::data_, bpp::StringTokenizer::getTokens(), bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.
|
inlinevirtual |
Create a copy of this object and send a pointer to it.
Implements bpp::Clonable.
Definition at line 159 of file Table.h.
References bpp::Table< T >::Table().
|
inline |
Delete the given column.
colName | The name of the column. |
NoTableColumnNamesException | If no column names are associated to this table. |
TableColumnNameNotFoundException | If colName do not match existing column names. |
Definition at line 543 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::VectorTools::which().
|
inline |
Delete the given column.
index | The index of the column. |
IndexOutOfBoundsException | If index is >= number of columns. |
Definition at line 526 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, and bpp::Table< T >::nCol_.
|
inline |
Delete the given row.
rowName | The name of the row. |
NoTableRowNamesException | If no row names are associated to this table. |
TableRowNameNotFoundException | If rowName do not match existing column names. |
Definition at line 903 of file Table.h.
References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, bpp::Table< T >::rowNames_, and bpp::VectorTools::which().
|
inline |
Delete the given row.
index | The index of the row. |
IndexOutOfBoundsException | If index is >= number of row. |
Definition at line 860 of file Table.h.
References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.
|
inline |
Delete the given rows.
index | The index of the first row. |
len | the number of rows to delete |
IndexOutOfBoundsException | If index is >= number of row. |
Definition at line 881 of file Table.h.
References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.
|
inline |
colName | The name of the column. |
NoTableColumnNamesException | If no column names are associated to this table. |
TableColumnNameNotFoundException | If colName do not match existing column names. |
Definition at line 464 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, and bpp::VectorTools::which().
|
inline |
colName | The name of the column. |
NoTableColumnNamesException | If no column names are associated to this table. |
TableColumnNameNotFoundException | If colName do not match existing column names. |
Definition at line 485 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, and bpp::VectorTools::which().
|
inline |
index | The index of the column. |
IndexOutOfBoundsException | If index is >= number of columns. |
Definition at line 438 of file Table.h.
References bpp::Table< T >::data_, and bpp::Table< T >::nCol_.
|
inline |
index | The index of the column. |
IndexOutOfBoundsException | If index is >= number of columns. |
Definition at line 450 of file Table.h.
References bpp::Table< T >::data_, and bpp::Table< T >::nCol_.
|
inline |
Get a given column name.
index | The index of the column. |
NoTableColumnNamesException | If no column names are associated to this table. |
IndexOutOfBoundsException | If index is >= number of columns. |
Definition at line 418 of file Table.h.
References bpp::Table< T >::colNames_, and bpp::Table< T >::nCol_.
Referenced by bpp::Table< T >::write().
|
inline |
Definition at line 403 of file Table.h.
References bpp::Table< T >::colNames_.
|
inline |
Get the column names of this table.
NoTableColumnNamesException | If no column names are associated to this table. |
Definition at line 396 of file Table.h.
References bpp::Table< T >::colNames_.
Referenced by bpp::Table< T >::write().
|
inline |
|
inline |
Definition at line 370 of file Table.h.
References bpp::Table< T >::nCol_.
Referenced by bpp::Table< T >::write().
|
inline |
Definition at line 722 of file Table.h.
References bpp::Table< T >::nRow_.
Referenced by bpp::Table< T >::write().
|
inline |
rowName | The name of the row. |
NoTableRowNamesException | If no row names are associated to this table. |
TableRowNameNotFoundException | If rowName do not match existing row names. |
Definition at line 833 of file Table.h.
References bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::rowNames_, and bpp::VectorTools::which().
|
inline |
index | The index of the row. |
IndexOutOfBoundsException | If index is >= number of rows. |
Definition at line 814 of file Table.h.
References bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.
|
inline |
Get a given row name.
index | The index of the row. |
NoTableRowNamesException | If no row names are associated to this table. |
IndexOutOfBoundsException | If index is >= number of rows. |
Definition at line 794 of file Table.h.
References bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.
Referenced by bpp::Table< T >::write().
|
inline |
Get the row names of this table.
NoTableRowNamesException | If no row names are associated to this table. |
Definition at line 752 of file Table.h.
References bpp::Table< T >::rowNames_.
Referenced by bpp::Table< T >::write().
|
inline |
Definition at line 759 of file Table.h.
References bpp::Table< T >::rowNames_.
|
inline |
Tell is a given column exists.
colName | The name of the column to look for. |
Definition at line 507 of file Table.h.
References bpp::Table< T >::colNames_.
|
inline |
Definition at line 431 of file Table.h.
References bpp::Table< T >::colNames_.
Referenced by bpp::Table< T >::write().
|
inline |
Tell is a given row exists.
rowName | The name of the row to look for. |
Definition at line 773 of file Table.h.
References bpp::Table< T >::rowNames_.
|
inline |
Definition at line 807 of file Table.h.
References bpp::Table< T >::rowNames_.
Referenced by bpp::Table< T >::write().
|
inline |
rowName | Row name. |
colName | Column name. |
NoTableRowNamesException | If the table does not have names associated to rows. |
NoTableColumnNamesException | If the table does not have names associated to columns. |
TableNameNotFoundException | If one of rowName or colName do not match existing names. |
Definition at line 212 of file Table.h.
References bpp::Table< T >::colNames_, bpp::ElementNotFoundException< T >::getElement(), bpp::Table< T >::rowNames_, and bpp::VectorTools::which().
|
inline |
rowName | Row name. |
colName | Column name. |
NoTableRowNamesException | If the table does not have names associated to rows. |
NoTableColumnNamesException | If the table does not have names associated to columns. |
TableNameNotFoundException | If one of rowName or colName do not match existing names. |
Definition at line 239 of file Table.h.
References bpp::Table< T >::colNames_, bpp::ElementNotFoundException< T >::getElement(), bpp::Table< T >::rowNames_, and bpp::VectorTools::which().
|
inline |
rowName | Row name. |
colIndex | Column number. |
NoTableRowNamesException | If the table does not have names associated to rows. |
IndexOutOfBoundsException | If the index is greater or equal to the number of columns. |
TableNameNotFoundException | If rowName do not match existing names. |
Definition at line 266 of file Table.h.
References bpp::ElementNotFoundException< T >::getElement(), bpp::Table< T >::nCol_, bpp::Table< T >::rowNames_, and bpp::VectorTools::which().
|
inline |
rowName | Row name. |
colIndex | Column number. |
NoTableRowNamesException | If the table does not have names associated to rows. |
IndexOutOfBoundsException | If the index is greater or equal to the number of columns. |
TableNameNotFoundException | If rowName do not match existing names. |
Definition at line 292 of file Table.h.
References bpp::ElementNotFoundException< T >::getElement(), bpp::Table< T >::nCol_, bpp::Table< T >::rowNames_, and bpp::VectorTools::which().
|
inline |
rowIndex | Row number. |
colName | Column name. |
IndexOutOfBoundsException | If the index is greater or equal to the number of rows. |
NoTableColumnNamesException | If the table does not have names associated to columns. |
TableNameNotFoundException | If colName do not match existing names. |
Definition at line 318 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::ElementNotFoundException< T >::getElement(), and bpp::VectorTools::which().
|
inline |
rowIndex | Row number. |
colName | Column name. |
IndexOutOfBoundsException | If the index is greater or equal to the number of rows. |
NoTableColumnNamesException | If the table does not have names associated to columns. |
TableNameNotFoundException | If colName do not match existing names. |
Definition at line 344 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::ElementNotFoundException< T >::getElement(), and bpp::VectorTools::which().
|
inline |
rowIndex | Row number. |
colIndex | Column number. |
IndexOutOfBoundsException | If one of the index is greater or equal to the corresponding number of columns/rows. |
Definition at line 180 of file Table.h.
References bpp::Table< T >::data_, and bpp::Table< T >::nCol_.
|
inline |
rowIndex | Row number. |
colIndex | Column number. |
IndexOutOfBoundsException | If one of the index is greater or equal to the corresponding number of columns/rows. |
Definition at line 195 of file Table.h.
References bpp::Table< T >::data_, and bpp::Table< T >::nCol_.
|
inline |
Definition at line 140 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.
|
inline |
Definition at line 130 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.
|
inlinestatic |
Read a table form a stream in CSV-like.
By default, if the first line as one column less than the second one, the first line is taken as column names, and the first column as row names. Otherwise, no column names and no row names are specified, unless explicitely precised by the user. Note: if byRow=false, exchange row and column roles.
in | The input stream. |
byRow | Tell if the table is filled by rows |
sep | The line delimiter. |
header | Tell if the first line must be used for names, otherwise use default. |
names | Use a column as rowNames (or a row as columnNames). If positive, use the specified column to compute rownames, otherwise use default; |
Definition at line 1046 of file Table.h.
References bpp::Table< T >::addColumn(), bpp::Table< T >::addRow(), bpp::FileTools::getNextLine(), bpp::StringTokenizer::getTokens(), bpp::TextTools::isEmpty(), bpp::Table< T >::setColumnNames(), and bpp::Table< T >::setRowNames().
|
inline |
Set a new column.
colName | The name of the column. |
newColumn | The new column values. |
pos | The position |
DimensionException | If the number of values does not match the number of rows. |
NoTableColumnNamesException | If the table does not have row names. |
DuplicatedTableColumnNameException | If colName is already used. |
Definition at line 692 of file Table.h.
References bpp::Table< T >::colNames_, bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.
|
inline |
Set a new column.
newColumn | The new column values. |
pos | The position |
DimensionException | If the number of values does not match the number of rows. |
TableColumnNamesException | If the table has row names. |
Definition at line 671 of file Table.h.
References bpp::Table< T >::data_, bpp::Table< T >::nCol_, and bpp::Table< T >::nRow_.
|
inline |
Set the column names of this table.
colNames | The row names. |
DimensionException | If the number of names do not match the number of columns in the table. |
DuplicatedTableColumnNameException | If names are not unique. |
Definition at line 379 of file Table.h.
References bpp::Table< T >::colNames_, bpp::VectorTools::isUnique(), and bpp::Table< T >::nCol_.
Referenced by bpp::Table< T >::read(), and bpp::Table< T >::Table().
|
inline |
Set the row names of this table.
rowNames | The row names. |
DimensionException | If the number of names do not match the number of rows in the table. |
DuplicatedTableRowNameException | If names are not unique. |
Definition at line 731 of file Table.h.
References bpp::VectorTools::isUnique(), bpp::Table< T >::nRow_, and bpp::Table< T >::rowNames_.
Referenced by bpp::Table< T >::read().
|
inlinestatic |
Definition at line 1148 of file Table.h.
References bpp::OutputStream::endLine(), bpp::Table< T >::getColumnName(), bpp::Table< T >::getColumnNames(), bpp::Table< T >::getNumberOfColumns(), bpp::Table< T >::getNumberOfRows(), bpp::Table< T >::getRowName(), bpp::Table< T >::getRowNames(), bpp::Table< T >::hasColumnNames(), and bpp::Table< T >::hasRowNames().
|
inlinestatic |
Write a Table object to stream in CVS-like format.
data | The table to write. |
out | The output stream. |
byRow | Tell if the table is written by rows. |
sep | The column delimiter. |
alignHeaders | If true, add a delimiter before the first column header if there is row names. |
Definition at line 1107 of file Table.h.
References bpp::Table< T >::getColumnName(), bpp::Table< T >::getColumnNames(), bpp::Table< T >::getNumberOfColumns(), bpp::Table< T >::getNumberOfRows(), bpp::Table< T >::getRowName(), bpp::Table< T >::getRowNames(), bpp::Table< T >::hasColumnNames(), and bpp::Table< T >::hasRowNames().
|
protected |
Definition at line 73 of file Table.h.
Referenced by bpp::Table< T >::addColumn(), bpp::Table< T >::deleteColumn(), bpp::Table< T >::getColumn(), bpp::Table< T >::getColumnName(), bpp::Table< T >::getColumnNames(), bpp::Table< T >::hasColumn(), bpp::Table< T >::hasColumnNames(), bpp::Table< T >::operator()(), bpp::Table< T >::operator=(), bpp::Table< T >::setColumn(), and bpp::Table< T >::setColumnNames().
|
protected |
Definition at line 71 of file Table.h.
Referenced by bpp::Table< T >::addColumn(), bpp::Table< T >::addRow(), bpp::Table< T >::deleteColumn(), bpp::Table< T >::deleteRow(), bpp::Table< T >::deleteRows(), bpp::Table< T >::getColumn(), bpp::Table< T >::getData(), bpp::Table< T >::getRow(), bpp::Table< T >::operator()(), bpp::Table< T >::operator=(), bpp::Table< T >::setColumn(), and bpp::Table< T >::Table().
|
protected |
Definition at line 70 of file Table.h.
Referenced by bpp::Table< T >::addColumn(), bpp::Table< T >::addRow(), bpp::Table< T >::deleteColumn(), bpp::Table< T >::deleteRow(), bpp::Table< T >::deleteRows(), bpp::Table< T >::getColumn(), bpp::Table< T >::getColumnName(), bpp::Table< T >::getNumberOfColumns(), bpp::Table< T >::getRow(), bpp::Table< T >::operator()(), bpp::Table< T >::operator=(), bpp::Table< T >::setColumn(), and bpp::Table< T >::setColumnNames().
|
protected |
Definition at line 70 of file Table.h.
Referenced by bpp::Table< T >::addColumn(), bpp::Table< T >::addRow(), bpp::Table< T >::deleteRow(), bpp::Table< T >::deleteRows(), bpp::Table< T >::getNumberOfRows(), bpp::Table< T >::getRow(), bpp::Table< T >::getRowName(), bpp::Table< T >::operator=(), bpp::Table< T >::setColumn(), and bpp::Table< T >::setRowNames().
|
protected |
Definition at line 72 of file Table.h.
Referenced by bpp::Table< T >::addRow(), bpp::Table< T >::deleteRow(), bpp::Table< T >::deleteRows(), bpp::Table< T >::getRow(), bpp::Table< T >::getRowName(), bpp::Table< T >::getRowNames(), bpp::Table< T >::hasRow(), bpp::Table< T >::hasRowNames(), bpp::Table< T >::operator()(), bpp::Table< T >::operator=(), and bpp::Table< T >::setRowNames().