from ..plugin import Plugin, argument_to_setting
from ..util.callback import is_iterable
from ..util.fit import PoorFit, ModelFitter
+from ..util.peak import Peak
from ..util.si import join_data_label, split_data_label
from .curve import CurveArgument
from .vclamp import scale
])
self._commands = [
PolymerFitCommand(self), PolymerFitPeaksCommand(self),
+ TranslateFlatPeaksCommand(self),
]
def dependencies(self):
`1` selects the retracting curve.
""".strip()),
Argument(name='peak info name', type='string',
- default='flat filter peaks',
+ default='polymer peaks',
help="""
-Name for storing the distance offset in the `.info` dictionary.
+Name for the list of peaks in the `.info` dictionary.
""".strip()),
Argument(name='peak index', type='int', count=-1, default=None,
help="""
if not isinstance(ret, Success):
raise ret
+
+class TranslateFlatPeaksCommand (Command):
+ """Translate flat filter peaks into polymer peaks for fitting.
+
+ Use :class:`~hooke.plugin.flatfilt.FlatPeaksCommand` creates a
+ list of peaks for regions with large derivatives. For velocity
+ clamp measurements, these regions are usually the rebound phase
+ after a protein domain unfolds, the cantilever detaches, etc.
+ Because these features occur after the polymer loading phase, we
+ need to shift the selected regions back to align them with the
+ polymer loading regions.
+ """
+ def __init__(self, plugin):
+ plugin_arguments = [a for a in plugin._arguments
+ if a.name in ['input distance column',
+ 'input deflection column']]
+ arguments = [
+ CurveArgument,
+ Argument(name='block', aliases=['set'], type='int', default=0,
+ help="""
+Data block for which the fit should be calculated. For an
+approach/retract force curve, `0` selects the approaching curve and
+`1` selects the retracting curve.
+""".strip()),
+ ] + plugin_arguments + [
+ Argument(name='input peak info name', type='string',
+ default='flat filter peaks',
+ help="""
+Name for the input peaks in the `.info` dictionary.
+""".strip()),
+ Argument(name='output peak info name', type='string',
+ default='polymer peaks',
+ help="""
+Name for the ouptput peaks in the `.info` dictionary.
+""".strip()),
+ Argument(name='end offset', type='int', default=-1,
+ help="""
+Number of points between the end of a new peak and the start of the old.
+""".strip()),
+ Argument(name='start fraction', type='float', default=0.2,
+ help="""
+Place the start of the new peak at `start_fraction` from the end of
+the previous old peak to the end of the new peak. Because the first
+new peak will have no previous old peak, it uses a distance of zero
+instead.
+""".strip()),
+ ]
+ super(TranslateFlatPeaksCommand, self).__init__(
+ name='flat peaks to polymer peaks',
+ arguments=arguments,
+ help=self.__doc__, plugin=plugin)
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ data = params['curve'].data[params['block']]
+ z_data = data[:,data.info['columns'].index(
+ params['input distance column'])]
+ d_data = data[:,data.info['columns'].index(
+ params['input deflection column'])]
+ previous_old_stop = numpy.absolute(z_data).argmin()
+ new = []
+ for i,peak in enumerate(data.info[params['input peak info name']]):
+ next_old_start = peak.index
+ stop = next_old_start + params['end offset']
+ z_start = z_data[previous_old_stop] + params['start fraction']*(
+ z_data[stop] - z_data[previous_old_stop])
+ start = numpy.absolute(z_data - z_start).argmin()
+ p = Peak('polymer peak %d' % i,
+ index=start,
+ values=d_data[start:stop])
+ new.append(p)
+ previous_old_stop = peak.post_index()
+ data.info[params['output peak info name']] = new
+
+
# TODO:
# def dist2fit(self):
# '''Calculates the average distance from data to fit, scaled by