示例#1
0
def subplotsNeeded(data):
    num = 0
    if hasattr(data, 'donor') and hasattr(data, 'acceptor'):
        num += 1
    if hasattr(data, 'fret'):
        num += 1
    if hasTrapData(data):
        num += 1
    return num
示例#2
0
def subplotsNeeded(data):
  num = 0
  if hasattr(data, 'donor') and hasattr(data, 'acceptor'):
    num += 1
  if hasattr(data,'fret'):
    num += 1
  if hasTrapData(data):
    num += 1
  return num
示例#3
0
 def __init__(self, trap, fret, metadata):
   if trap and not hasTrapData(trap):
     raise ValueError(
         "__init__ argument 'trap' <{}> does not have trap data".format(trap))
   if fret and not hasFretData(fret):
     raise ValueError(
         "__init__ argument 'fret' <{}> does not have fret data".format(fret))
   self.trap = trap
   self._fret = fret
   self.metadata = nesteddict.from_dict(metadata)
   self.metadata['trap'] = getattr(trap, 'metadata', nesteddict())
   self.metadata['fret'] = getattr(fret, 'metadata', nesteddict())
   # Move 'fret' metadata fields found in trap metadata (recorded in .str files)
   # to the fret.metadata dictionary
   for key in ifilter(lambda s: s.startswith('fret'), self.metadata['trap'].keys()):
     self['fret'].update(self.metadata['trap'].pop(key))
示例#4
0
def plot(data, pull=None, **kwargs):
  loc = kwargs.get('legend', 'best')
  title = kwargs.get('title','')
  FEC = kwargs.get('FEC',False)
  displayFRET = kwargs.get('show_fret', hasattr(data,'fret'))

  hold=kwargs.pop('hold', None)
  if hold is not None:
    plt.hold(hold)

  if hasattr(data, '_to_plot'):
    args, kwargs = data._to_plot()
    return _subplot(*args, **kwargs)

  if not pull and hasTrapData(data):
    pull = TrapData.fromObject(data)

  if not displayFRET and data is not None: num = 1
  elif hasFretData(data): num = 2
  else: num = 0
  if pull: num += 1
  if num==0:
    raise ValueError("Don't know how to plot argument: missing named fields")

  layout = iter((num,1,x) for x in range(1,num+1))

  ax1 = None
  if hasFretData(data):
    plt.subplot(*next(layout))
    not hold and plt.cla()
    plt.hold(True)
    ax1 = _subplot(data.time, data.donor, label='donor')
    _subplot(data.time, data.acceptor, label='acceptor', axes=('','counts'))
    plt.hold(hold)
    plt.legend(loc=loc,ncol=2,prop={'size':'small'})
    if displayFRET:
      _subplot(data.time, data.fret, layout=next(layout), 
                axes=('Seconds','FRET'))

  ax2 = None
  if pull:
    x_coord,x_label = (pull.ext,'Extension (nm)') if FEC else (pull.sep,'Separation (nm)')
    ax2 = _subplot(x_coord, pull.f, '.', layout=next(layout), axes=(x_label,'Force (pN)'))

  first_plot = ax1 if ax1 else ax2
  first_plot.set_title(title)
  plt.show()
示例#5
0
 def __init__(self, trap, fret, metadata):
     if trap and not hasTrapData(trap):
         raise ValueError(
             "__init__ argument 'trap' <{}> does not have trap data".format(
                 trap))
     if fret and not hasFretData(fret):
         raise ValueError(
             "__init__ argument 'fret' <{}> does not have fret data".format(
                 fret))
     self.trap = trap
     self._fret = fret
     self.metadata = nesteddict.from_dict(metadata)
     self.metadata['trap'] = getattr(trap, 'metadata', nesteddict())
     self.metadata['fret'] = getattr(fret, 'metadata', nesteddict())
     # Move 'fret' metadata fields found in trap metadata (recorded in .str files)
     # to the fret.metadata dictionary
     for key in ifilter(lambda s: s.startswith('fret'),
                        self.metadata['trap'].keys()):
         self['fret'].update(self.metadata['trap'].pop(key))
示例#6
0
def plot(data, pull=None, style=None, **kwargs):
  """Plot FretData and/or TrapData as stacked subplots of counts, FRET, and FEC/FDC
  @data: datatypes.AbstractData
  @pull: datatypes.AbstractData
  @style: dict or str
  """
  if isinstance(style, str):
    style = Style.with_default_style(style)
  elif isinstance(style, dict):
    style = Style(**style)
  else:
    style = Style()
  loc = kwargs.pop('legend', 'best')
  title = kwargs.pop('title','')
  label = kwargs.pop('label', '')
  displayFRET = kwargs.pop('show_fret', True) and hasattr(data,'fret')
  kwargs.setdefault('markersize', 2)

  hold=kwargs.pop('hold', None)
  if hold is not None:
    plt.hold(hold)

  if not pull and hasTrapData(data):
    pull = TrapData.fromObject(data)

  num = 0
  if displayFRET:
    num += 2
  if pull:
    num += 1
    FEC = kwargs.pop('FEC', num==1)
  else:
    FEC = kwargs.pop('FEC', False)

  if num == 0:
    raise ValueError("Don't know how to plot arguments: need TrapData or FretData")

  if data is None and pull is not None:
    layout = iter([(num,1,num)])
  else:
    layout = iter((num,1,x) for x in range(1,num+1))

  ax1 = None
  donor, acceptor = 'donor', 'acceptor'
  if displayFRET:
    plt.subplot(*next(layout))
    not hold and plt.cla()
    plt.hold(True)
    ax1 = subplot(data.time, data.donor, style[donor], label=donor, **kwargs)
    subplot(data.time, data.acceptor, style[acceptor], label=acceptor, axes=('Time (s)','Counts'), **kwargs)
    plt.hold(hold)
    if loc is not None:
      plt.legend(loc=loc,ncol=2,prop={'size':'small'})
  if displayFRET:
    subplot(data.time, data.fret, style['fret'], layout=next(layout), 
              axes=('Time (s)','FRET'), **kwargs)
    plt.ylim(-0.1, 1.1)

  ax2 = None
  if pull:
    trap_style = Style.TRAP_STYLE_NAME
    x_coord,x_label = (pull.ext,'Extension (nm)') if FEC else (pull.sep,'Separation (nm)')
    ax2 = subplot(x_coord, pull.f, style[trap_style], layout=next(layout), axes=(x_label,'Force (pN)'), label=label, **kwargs)
    if loc is not None:
      plt.legend(loc=loc,ncol=2,prop={'size':'small'})

  first_plot = ax1 or ax2
  if title:
    first_plot.set_title(title)
示例#7
0
def plot(data, pull=None, style=None, **kwargs):
    """Plot FretData and/or TrapData as stacked subplots of counts, FRET, and FEC/FDC
  @data: datatypes.AbstractData
  @pull: datatypes.AbstractData
  @style: dict or str
  """
    if isinstance(style, str):
        style = Style.with_default_style(style)
    elif isinstance(style, dict):
        style = Style(**style)
    else:
        style = Style()
    loc = kwargs.pop('legend', 'best')
    title = kwargs.pop('title', '')
    label = kwargs.pop('label', '')
    displayFRET = kwargs.pop('show_fret', True) and hasattr(data, 'fret')
    kwargs.setdefault('markersize', 2)

    hold = kwargs.pop('hold', None)
    if hold is not None:
        plt.hold(hold)

    if not pull and hasTrapData(data):
        pull = TrapData.fromObject(data)

    num = 0
    if displayFRET:
        num += 2
    if pull:
        num += 1
        FEC = kwargs.pop('FEC', num == 1)
    else:
        FEC = kwargs.pop('FEC', False)

    if num == 0:
        raise ValueError(
            "Don't know how to plot arguments: need TrapData or FretData")

    if data is None and pull is not None:
        layout = iter([(num, 1, num)])
    else:
        layout = iter((num, 1, x) for x in range(1, num + 1))

    ax1 = None
    donor, acceptor = 'donor', 'acceptor'
    if displayFRET:
        plt.subplot(*next(layout))
        not hold and plt.cla()
        plt.hold(True)
        ax1 = subplot(data.time,
                      data.donor,
                      style[donor],
                      label=donor,
                      **kwargs)
        subplot(data.time,
                data.acceptor,
                style[acceptor],
                label=acceptor,
                axes=('Time (s)', 'Counts'),
                **kwargs)
        plt.hold(hold)
        if loc is not None:
            plt.legend(loc=loc, ncol=2, prop={'size': 'small'})
    if displayFRET:
        subplot(data.time,
                data.fret,
                style['fret'],
                layout=next(layout),
                axes=('Time (s)', 'FRET'),
                **kwargs)
        plt.ylim(-0.1, 1.1)

    ax2 = None
    if pull:
        trap_style = Style.TRAP_STYLE_NAME
        x_coord, x_label = (pull.ext,
                            'Extension (nm)') if FEC else (pull.sep,
                                                           'Separation (nm)')
        ax2 = subplot(x_coord,
                      pull.f,
                      style[trap_style],
                      layout=next(layout),
                      axes=(x_label, 'Force (pN)'),
                      label=label,
                      **kwargs)
        if loc is not None:
            plt.legend(loc=loc, ncol=2, prop={'size': 'small'})

    first_plot = ax1 or ax2
    if title:
        first_plot.set_title(title)