tritemio / FRETBursts

Burst analysis software for smFRET. **Moved to OpenSMFS organization**
https://github.com/OpenSMFS/FRETBursts
GNU General Public License v2.0
16 stars 17 forks source link

Improve definition of photon selections #1

Closed tritemio closed 10 years ago

tritemio commented 10 years ago

Problem

Currently different photons selections are identified by a string. For example 'DA' indicates all photons, 'D' donor channel photons during donor excitation, 'A' donor channel photons during donor excitation and 'AA' acceptor channel photons during acceptor excitation.

These names are ambiguous without reading the docs or the code and don't allow definition of arbitrary combinations.

Proposal

A simple and general way to handle the definition of photon selection would be defining an object with two keyword arguments:

Ph_sel(Dex='DAem', Aex='DAem')

Possible values for Dex or Aex are 'DAem' (default), 'Dem' and 'Aem'. This way the definition would be explicit and unambiguous but still compact and completely general.

To save some typing and increase legibility a useful shortcut would be Ph_sel('all') meaning all-photons (equivalent but more readable than Ph_sel(Dex='DAem', Aex='DAem')) .

Implementation

The easiest implementation would be using a dictionary or a named tuple. The named tuple has the advantage of defining the keywords (the dictionary would accept any key) and to be immutable. The latter property allow to use the Ph_sel object as dictionary key in cases where the strings 'DA', 'D', 'A' are currently used.

The only disadvantage of the named tuple is that we need to subclass it in order to support the special shortcut ('all') or default keyword values.

A quick search reveals possible solutions for the default values:

>>> from collections import namedtuple
>>> Node = namedtuple('Node', 'val left right')
>>> Node.__new__.__defaults__ = (None, None, None)

or

class Node(namedtuple('Node', ['value', 'left', 'right'])):
    def __new__(cls, value=None, left=None, right=None):
        return super(Node, cls).__new__(cls, value, left, right)

(from Named tuple and optional keyword arguments)

The latter approach would easily allow defining shortcut argument 'all'.