Parser

This module provides elements for parsing data manually, i.e. getting a handful list of samples and extract specific structures (colony, lineage, cell) from such samples.

  • Parser: handles how to parse an experiment with a given filterset
class tunacell.base.parser.Parser(exp=None, filter_set=None)

Defines how user wants to parse data.

Parameters:
  • exp (Experiment instance) –
  • filter_set (FilterSet instance) – this is the set of filters used to read/build data, used for for iterators (usually, only .cell_filter and .container_filter are used)
add_sample(*args)

Add sample to sample list.

Parameters:args (list) – list of items such as: integer, strings, couple, and/or dict An integer denotes the number of sample_ids to be chosen randomly (if many integers are given, only the first is used) A string will result in loading the corresponding Container, with a cell identifier randomly chosen. A couple (str, cellID) denotes (container_label, cell_identifier) A dictionary should provide ‘container’ key, and ‘cellID’ key
clear_samples()

Erase all samples.

get_cell(sample_id)

Get Cell instance corresponding to sample_id.

Parameters:sample_id (dict) – element of self.samples
Returns:cell – corresponding to sample_id
Return type:Cell instance
get_colony(sample_id)

Get Colony instance corresponding to sample_id.

Parameters:sample_id (dict) – element of self.samples
Returns:colony – corresponding to sample_id
Return type:Colony instance
get_container(sample_id)

Get Container instance corresponding to sample_id.

Parameters:sample_id (dict) – element of self.samples
Returns:container
Return type:Container instance
get_lineage(sample_id)

Get Lineage instance corresponding to sample_id.

Parameters:sample_id (dict) – element of self.samples
Returns:lineage – corresponding to sample_id
Return type::class:` Lineage` instance
get_sample(index, level='cell')

Return sample corresponding to index.

Parameters:
  • index (int) – index of sample id in self.samples
  • level (str {'cell'|'lineage'|'colony'}) –
Returns:

structure level corresponding to sample id

Return type:

out

info_samples()

Table output showing stored samples.

iter_cells(mode='all', size=None, shuffle=False)

Iterate through valid cells.

Note

Deprecated in tunacell 0.0.7 mode ‘all’ is similar to run iter_containers from Experiment instance. This mode will be removed in the future.

Parameters:
  • mode (str {'all', 'samples'} (default 'all')) – whether to iterate over all cells (up to number limitation), or over registered samples
  • size (int (default None)) – limit the number of lineages to size. Works only in mode=’all’
  • shuffle (bool (default False)) – whether to shuffle the ordering of lineages when mode=’all’
Yields:

cell (Cell instance) – filtering removed outlier cells, containers, colonies, and lineages

iter_colonies(mode='all', size=None, shuffle=False)

Iterate through valid colonies.

Note

Deprecated in tunacell 0.0.7 mode ‘all’ is similar to run iter_containers from Experiment instance. This mode will be removed in the future.

Parameters:
  • mode (str {'all', 'samples'} (default 'all')) – whether to iterate over all colonies (up to number limitation), or over registered samples
  • size (int (default None)) – limit the number of colonies to size. Works only in mode=’all’
  • shuffle (bool (default False)) – whether to shuffle the ordering of colonies when mode=’all’
Yields:

colony (Colony instance) – filtering removed outlier cells, containers, and colonies

iter_containers(mode='all', size=None, shuffle=False)

Iterate through valid containers.

Note

Deprecated in tunacell 0.0.7 mode ‘all’ is similar to run iter_containers from Experiment instance. This mode will be removed in the future.

If mode ‘all’ is chosen, then the iterator browses all files, up to the size limit. If mode ‘samples’ is chosen, then only sample ids already stored in Parser instance are browsed. Only valid Container instance are yielded (valid under filtering against containers).

Parameters:
  • mode (str {'all', 'samples'} (default 'all')) – whether to iterate over all possible containers, or restrict to containers pointed by parser.samples
  • size (int (default None), number of containers to be parsed) –
  • shuffle (bool (default False)) – whether to randomize ordering of containers
Yields:

container (tunacell.core.Container instance) – filtering removed outlier cells, containers

iter_lineages(mode='all', size=None, shuffle=False)

Iterate through valid lineages.

Note

Deprecated in tunacell 0.0.7 mode ‘all’ is similar to run iter_containers from Experiment instance. This mode will be removed in the future.

Parameters:
  • mode (str {'all', 'samples'} (default 'all')) – whether to iterate over all lineages (up to number limitation), or over registered samples
  • size (int (default None)) – limit the number of lineages to size. Works only in mode=’all’
  • shuffle (bool (default False)) – whether to shuffle the ordering of lineages when mode=’all’
Yields:

lineage (Lineage instance) – filtering removed outlier cells, containers, colonies, and lineages

load_experiment(path, filetype='text')

Loads an experiment from path to file.

Parameters:
  • path (str) – path to root directory (‘text’), or to datafile (‘h5’)
  • filetype (str {'text', 'h5}) –
remove_sample(index, verbose=True)

Remove sample of index in sample list.

set_filter(fset)

Set build filter.

Parameters:fset (FilterSet instance) –