Package mvpa :: Package misc :: Package io :: Module base :: Class ColumnData

[hide private]
[frames] | no frames]

# Class ColumnData

source code

Read data that is stored in columns of text files.

All read data is available via a dictionary-like interface. If column headers are available, the column names serve as dictionary keys. If no header exists an articfical key is generated: str(number_of_column).

Splitting of text file lines is performed by the standard split() function (which gets passed the `sep` argument as separator string) and each element is converted into the desired datatype.

Because data is read into a dictionary no two columns can have the same name in the header! Each column is stored as a list in the dictionary.

Instance Methods | [hide private]

    new empty dictionary

__init__(self, source, header=True, sep=None, headersep=None, dtype=float, skiplines=0) Read data from file into a dictionary. | source code

_getAttrib(self, key) Return corresponding value if given key is known to current instance | source code

__str__(self) str(x) | source code

_check(self) Performs some checks for data integrity. | source code

_fromFile(self, filename, header, sep, headersep, dtype, skiplines) Loads column data from file -- clears object first. | source code

__iadd__(self, other) Merge column data. | source code

selectSamples(self, selection) Return new ColumnData with selected samples | source code

getNColumns(self) Returns the number of columns. | source code

tofile(self, filename, header=True, header_order=None, sep=' ') Write column data to a text file. | source code

getNRows(self) Returns the number of rows. | source code

Inherited from `dict`: `__cmp__`, `__contains__`, `__delitem__`, `__eq__`, `__ge__`, `__getattribute__`, `__getitem__`, `__gt__`, `__iter__`, `__le__`, `__len__`, `__lt__`, `__ne__`, `__new__`, `__repr__`, `__setitem__`, `__sizeof__`, `clear`, `copy`, `fromkeys`, `get`, `has_key`, `items`, `iteritems`, `iterkeys`, `itervalues`, `keys`, `pop`, `popitem`, `setdefault`, `update`, `values`, `viewitems`, `viewkeys`, `viewvalues`

Inherited from `object`: `__delattr__`, `__format__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__subclasshook__`

Class Variables | [hide private]

| __doc__ = `enhancedDocString('ColumnData', locals())`
| ncolumns = `property(fget= getNColumns)`
| nrows = `property(fget= getNRows)`
Inherited from `dict`: `__hash__`

Properties | [hide private]

Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, source, header=True, sep=None, headersep=None, dtype=float, skiplines=0)
(Constructor)

source code

Read data from file into a dictionary.

Parameters:
  - `source` (basestring or dict) - If values is given as a string all data is read from the file and additonal keyword arguments can be sued to customize the read procedure. If a dictionary is passed a deepcopy is performed.
  - `header` (bool or list of basestring) - Indicates whether the column names should be read from the first line (`header=True`). If `header=False` unique column names will be generated (see class docs). If `header` is a python list, it's content is used as column header names and its length has to match the number of columns in the file.
  - `sep` (basestring or None) - Separator string. The actual meaning depends on the output format (see class docs).
  - `headersep` (basestring or None) - Separator string used in the header. The actual meaning depends on the output format (see class docs).
  - `dtype` (type or list(types)) - Desired datatype(s). Datatype per column get be specified by passing a list of types.
  - `skiplines` (int) - Number of lines to skip at the beginning of the file.
Returns:

    new empty dictionary

Overrides: object.__init__

### _getAttrib(self, key)

source code

Return corresponding value if given key is known to current instance

Is used for automatically added properties to the class.

Returns:
  Value if `key` is known

### __str__(self)
(Informal representation operator)

source code

str(x)

Overrides: object.__str__
  (inherited documentation)

### tofile(self, filename, header=True, header_order=None, sep=' ')

source code

Write column data to a text file.

Parameters:
  - `filename` (basestring) - Target filename
  - `header` (bool) - If `True` a column header is written, using the column keys. If `False` no header is written.
  - `header_order` (None or list of basestring) - If it is a list of strings, they will be used instead of simply asking for the dictionary keys. However these strings must match the dictionary keys in number and identity. This argument type can be used to determine the order of the columns in the output file. The default value is `None`. In this case the columns will be in an arbitrary order.
  - `sep` (basestring) - String that is written as a separator between to data columns.