(autopeak.py, etc.) added noflatten option to autopeak, plus small stuff here and...
authordevicerandom <devnull@localhost>
Tue, 26 May 2009 16:32:47 +0000 (16:32 +0000)
committerdevicerandom <devnull@localhost>
Tue, 26 May 2009 16:32:47 +0000 (16:32 +0000)
autopeak.py
generalvclamp.py
hooke.conf
jpk.py
mcs.py

index 1eabb18ab9c990ab04cb583e262da4444c6b891c..ffacd826bc9756c899f47db79a46c7b92bdc0bad 100644 (file)
@@ -52,6 +52,8 @@ class autopeakCommands:
         
         usepoints : fit interval by number of points instead than by nanometers
         
+        noflatten : does not use the "flatten" plot manipulator
+        
         When you first issue the command, it will ask for the filename. If you are giving the filename
         of an existing file, autopeak will resume it and append measurements to it. If you are giving
         a new filename, it will create the file and append to it until you close Hooke.
@@ -66,7 +68,7 @@ class autopeakCommands:
         auto_fit_nm = number of nm to fit before the peak maximum, for WLC (if usepoints false)
         auto_fit_points = number of points to fit before the peak maximum, for WLC (if usepoints true)
         
-        baseline_clicks = -1: no baseline, f=0 at the contact point (whether hand-picked or automatically found)\r
+        baseline_clicks = -1: no baseline, f=0 at the contact point (whether hand-picked or automatically found)
                            0: automatic baseline
                            1: decide baseline with a single click and length defined in auto_left_baseline
                            2: let user click points of baseline
@@ -107,14 +109,15 @@ class autopeakCommands:
             contact_point_index=contact_point.index
             self.wlccontact_point=contact_point
             self.wlccontact_index=contact_point.index
-            self.wlccurrent=self.current.path\r
+            self.wlccurrent=self.current.path
             return contact_point, contact_point_index
         
-        def find_current_peaks():
+        def find_current_peaks(noflatten):
             #Find peaks.
             defplot=self.current.curve.default_plots()[0]
-            flatten=self._find_plotmanip('flatten') #Extract flatten plotmanip
-            defplot=flatten(defplot, self.current, customvalue=1) #Flatten curve before feeding it to has_peaks
+            if not noflatten:
+                flatten=self._find_plotmanip('flatten') #Extract flatten plotmanip
+                defplot=flatten(defplot, self.current, customvalue=1) #Flatten curve before feeding it to has_peaks
             peak_location,peak_size=self.has_peaks(defplot, self.convfilt_config['mindeviation'])
             return peak_location, peak_size
     
@@ -125,6 +128,7 @@ class autopeakCommands:
         slope_span=int(self.config['auto_slope_span'])
         delta_force=10
         rebase=False #if true=we select rebase
+        noflatten=False #if true=we avoid flattening
         
         #initialize output data vectors
         c_lengths=[]
@@ -149,6 +153,9 @@ class autopeakCommands:
         if 'rebase' in args or (self.basecurrent != self.current.path):
             rebase=True 
         
+        if 'noflatten' in args:
+            noflatten=True
+        
         #--Custom persistent length / custom temperature
         for arg in args.split():
             #look for a persistent length argument.
@@ -177,7 +184,7 @@ class autopeakCommands:
         #--END COMMAND LINE PARSING--
         
         
-        peak_location, peak_size = find_current_peaks()
+        peak_location, peak_size = find_current_peaks(noflatten)
         
         if len(peak_location) == 0:
             print 'No peaks to fit.'
@@ -187,7 +194,7 @@ class autopeakCommands:
         
         #Pick up force baseline
         if rebase:
-            clicks=self.config['baseline_clicks']\r
+            clicks=self.config['baseline_clicks']
             if clicks==0:
                 self.basepoints=[]
                 base_index_0=peak_location[-1]+fit_interval_nm(peak_location[-1], displayed_plot, self.config['auto_right_baseline'],False)
@@ -208,13 +215,13 @@ class autopeakCommands:
         boundaries=[self.basepoints[0].index, self.basepoints[1].index]
         boundaries.sort()
         to_average=displayed_plot.vectors[1][1][boundaries[0]:boundaries[1]] #y points to average
-        avg=np.mean(to_average)\r
-        \r
-        clicks=self.config['baseline_clicks']\r
-        if clicks==-1:\r
-            try:\r
+        avg=np.mean(to_average)
+        
+        clicks=self.config['baseline_clicks']
+        if clicks==-1:
+            try:
                 avg=displayed_plot.vectors[1][1][contact_point_index]
-            except:\r
+            except:
                 avg=displayed_plot.vectors[1][1][cindex]
         
         for peak in peak_location:
index ebd3e084067377b7ebfe73c134f49f24e229cbc2..7cccf0b2fc71e456c3e871dcfe2a42bd59de1b8e 100644 (file)
@@ -293,262 +293,3 @@ class generalvclampCommands:
     
     
     
-#====================
-#AUTOMATIC ANALYSES
-#====================
-    '''
-    def do_autopeak(self,args):
-        #FIXME: this function is too long. split it and make it rational.
-        #FIXME: also, *generalize fits* to allow FJC and any other model in the future!
-        
-        def fit_interval_nm(start_index,plot,nm,backwards):
-    '''
-            
-    '''
-            Calculates the number of points to fit, given a fit interval in nm
-            start_index: index of point
-            plot: plot to use
-            backwards: if true, finds a point backwards.
-    '''
-            
-    '''
-            x_vect=plot.vectors[1][0]
-            
-            c=0
-            i=start_index
-            start=x_vect[start_index]
-            maxlen=len(x_vect)
-            while abs(x_vect[i]-x_vect[start_index])*(10**9) < nm:
-                if i==0 or i==maxlen-1: #we reached boundaries of vector!
-                    return c
-                
-                if backwards:
-                    i-=1
-                else:
-                    i+=1
-                c+=1
-            return c
-            
-        
-        pl_value=None
-        T=self.config['temperature']
-        
-        if 'usepoints' in args.split():
-            fit_points=int(self.config['auto_fit_points'])
-            usepoints=True
-        else:
-            fit_points=None
-            usepoints=False
-            
-        slope_span=int(self.config['auto_slope_span'])
-        delta_force=10
-        rebase=False #if true=we select rebase
-        
-        #Pick up plot
-        displayed_plot=self._get_displayed_plot(0)
-        
-        if self.current.curve.experiment != 'smfs' or len(displayed_plot.vectors) < 2:
-            print 'Cannot work on this curve.'
-            return
-        
-        #Look for custom persistent length / custom temperature
-        for arg in args.split():
-            #look for a persistent length argument.
-            if 'pl=' in arg:
-                pl_expression=arg.split('=')
-                pl_value=float(pl_expression[1]) #actual value
-            #look for a T argument. FIXME: spaces are not allowed between 'pl' and value
-            if ('t=' in arg[0:2]) or ('T=' in arg[0:2]):
-                t_expression=arg.split('=')
-                T=float(t_expression[1])
-                              
-        #Handle contact point arguments
-        def pickup_contact_point():
-            #macro to pick up the contact point by clicking
-            contact_point=self._measure_N_points(N=1, whatset=1)[0]
-            contact_point_index=contact_point.index
-            self.wlccontact_point=contact_point
-            self.wlccontact_index=contact_point.index
-            self.wlccurrent=self.current.path
-            return contact_point, contact_point_index
-                
-        if 'reclick' in args.split():
-            print 'Click contact point'
-            contact_point, contact_point_index = pickup_contact_point()
-        elif 'noauto' in args.split():
-            if self.wlccontact_index==None or self.wlccurrent != self.current.path:
-                print 'Click contact point'
-                contact_point , contact_point_index = pickup_contact_point()
-            else:
-                contact_point=self.wlccontact_point
-                contact_point_index=self.wlccontact_index
-        else:
-            #Automatically find contact point
-            cindex=self.find_contact_point()
-            contact_point=ClickedPoint()
-            contact_point.absolute_coords=displayed_plot.vectors[1][0][cindex], displayed_plot.vectors[1][1][cindex]
-            contact_point.find_graph_coords(displayed_plot.vectors[1][0], displayed_plot.vectors[1][1])
-            contact_point.is_marker=True
-        
-        
-        #Find peaks.
-        defplot=self.current.curve.default_plots()[0]
-        flatten=self._find_plotmanip('flatten') #Extract flatten plotmanip
-        defplot=flatten(defplot, self.current, customvalue=1) #Flatten curve before feeding it to has_peaks
-        peak_location,peak_size=self.has_peaks(defplot, self.convfilt_config['mindeviation'])
-        
-        #Create a new plot to send
-        fitplot=copy.deepcopy(displayed_plot)
-        
-        #Pick up force baseline
-        whatset=1 #fixme: for all sets
-        if 'rebase' in args or (self.basecurrent != self.current.path):
-            rebase=True               
-        if rebase:
-            clicks=self.config['baseline_clicks']
-            if clicks==0:
-                self.basepoints=[]
-                self.basepoints.append(ClickedPoint())
-                self.basepoints.append(ClickedPoint())
-                self.basepoints[0].index=peak_location[-1]+fit_interval_nm(peak_location[-1], displayed_plot, self.config['auto_right_baseline'],False)
-                self.basepoints[1].index=self.basepoints[0].index+fit_interval_nm(self.basepoints[0].index, displayed_plot, self.config['auto_left_baseline'],False)
-                for point in self.basepoints:
-                    #for graphing etc. purposes, fill-in with coordinates
-                    point.absolute_coords=displayed_plot.vectors[1][0][point.index], displayed_plot.vectors[1][1][point.index]
-                    point.find_graph_coords(displayed_plot.vectors[1][0], displayed_plot.vectors[1][1])
-            elif clicks>0:
-                print 'Select baseline'
-                if clicks==1:
-                    self.basepoints=self._measure_N_points(N=1, whatset=whatset)
-                    self.basepoints.append(ClickedPoint())
-                    self.basepoints[1].index=self.basepoints[0].index+fit_interval_nm(self.basepoints[0].index, displayed_plot, self.config['auto_left_baseline'], False)
-                    #for graphing etc. purposes, fill-in with coordinates
-                    self.basepoints[1].absolute_coords=displayed_plot.vectors[1][0][self.basepoints[1].index], displayed_plot.vectors[1][1][self.basepoints[1].index]
-                    self.basepoints[1].find_graph_coords(displayed_plot.vectors[1][0], displayed_plot.vectors[1][1])
-                else:
-                    self.basepoints=self._measure_N_points(N=2, whatset=whatset)
-            
-            self.basecurrent=self.current.path
-        
-        boundaries=[self.basepoints[0].index, self.basepoints[1].index]
-        boundaries.sort()
-        to_average=displayed_plot.vectors[1][1][boundaries[0]:boundaries[1]] #y points to average
-        avg=np.mean(to_average)
-        
-        
-        #Initialize data vectors
-        c_lengths=[]
-        p_lengths=[]
-        forces=[]
-        slopes=[]
-        
-        
-        
-        #Cycle between peaks and do analysis.
-        for peak in peak_location:
-            #Do WLC fits.
-            #FIXME: clean wlc fitting, to avoid this clickedpoint hell
-            #-create a clicked point for the peak point
-            peak_point=ClickedPoint()
-            peak_point.absolute_coords=displayed_plot.vectors[1][0][peak], displayed_plot.vectors[1][1][peak]
-            peak_point.find_graph_coords(displayed_plot.vectors[1][0], displayed_plot.vectors[1][1])    
-            
-            if not usepoints:
-                fit_points=fit_interval_nm(peak, displayed_plot, self.config['auto_fit_nm'], True)
-            
-            #-create a clicked point for the other fit point
-            other_fit_point=ClickedPoint()
-            other_fit_point.absolute_coords=displayed_plot.vectors[1][0][peak-fit_points], displayed_plot.vectors[1][1][peak-fit_points]
-            other_fit_point.find_graph_coords(displayed_plot.vectors[1][0], displayed_plot.vectors[1][1])    
-            #do the fit
-            points=[contact_point, peak_point, other_fit_point]
-            
-            #Check if we have enough points for a fit. If not, wlc_fit could crash
-            if abs(peak_point.index-other_fit_point.index) < 2:
-                continue
-            
-            params, yfit, xfit = self.wlc_fit(points, displayed_plot.vectors[1][0], displayed_plot.vectors[1][1],pl_value,T)
-            #save wlc values (nm)
-            c_lengths.append(params[0]*(1.0e+9))
-            if len(params)==2: #if we did choose 2-value fit
-                p_lengths.append(params[1]*(1.0e+9))
-            else:
-                p_lengths.append(pl_value)
-            #Add WLC fit lines to plot
-            fitplot.add_set(xfit,yfit)
-            
-            if len(fitplot.styles)==0:
-                fitplot.styles=[]
-            else:
-                fitplot.styles.append(None)
-            #Measure forces
-            delta_to_measure=displayed_plot.vectors[1][1][peak-delta_force:peak+delta_force]
-            y=min(delta_to_measure)
-            #save force values (pN)
-            forces.append(abs(y-avg)*(1.0e+12))
-                
-            #Measure slopes
-            slope=self.linefit_between(peak-slope_span,peak)[0]
-            slopes.append(slope)
-        
-        #--DEBUG STUFF--
-        fitplot.add_set([self.basepoints[0].graph_coords[0],self.basepoints[1].graph_coords[0]],[self.basepoints[0].graph_coords[1],self.basepoints[1].graph_coords[1]]) 
-        fitplot.styles.append('scatter')
-        
-        #Show wlc fits and peak locations
-        self._send_plot([fitplot])
-        self.do_peaks('')
-        
-        #Ask the user what peaks to ignore from analysis.
-        print 'Peaks to ignore (0,1...n from contact point,return to take all)'
-        print 'N to discard measurement'
-        exclude_raw=raw_input('Input:')
-        if exclude_raw=='N':
-            print 'Discarded.'
-            return
-        if not exclude_raw=='':
-            exclude=exclude_raw.split(',')
-            try:
-                exclude=[int(item) for item in exclude]
-                for i in exclude:
-                    c_lengths[i]=None
-                    p_lengths[i]=None
-                    forces[i]=None
-                    slopes[i]=None
-            except:
-                 print 'Bad input, taking all...'
-        #Clean data vectors from ignored peaks        
-        c_lengths=[item for item in c_lengths if item != None]
-        p_lengths=[item for item in p_lengths if item != None]
-        forces=[item for item in forces if item != None]
-        slopes=[item for item in slopes if item != None]    
-        print 'contour (nm)',c_lengths
-        print 'p (nm)',p_lengths
-        print 'forces (pN)',forces
-        print 'slopes (N/m)',slopes
-        
-        #Save file info
-        if self.autofile=='':
-            self.autofile=raw_input('Autopeak filename? (return to ignore) ')
-            if self.autofile=='':
-                print 'Not saved.'
-                return
-        
-        if not os.path.exists(self.autofile):
-            f=open(self.autofile,'w+')
-            f.write('Analysis started '+time.asctime()+'\n')
-            f.write('----------------------------------------\n')
-            f.write('; Contour length (nm)  ;  Persistence length (nm) ;  Max.Force (pN)  ;  Slope (N/m) \n')
-            f.close()
-            
-        print 'Saving...'
-        f=open(self.autofile,'a+')
-        
-        f.write(self.current.path+'\n')
-        for i in range(len(c_lengths)):
-            f.write(' ; '+str(c_lengths[i])+' ; '+str(p_lengths[i])+' ; '+str(forces[i])+' ; '+str(slopes[i])+'\n')
-            
-        f.close()
-        self.do_note('autopeak')
-        '''
\ No newline at end of file
index 5fe84ba97fe2913015b73d72896bf19a9328ec0e..6391e3bab5ce19515710195b7c32bc30a96a5f71 100755 (executable)
@@ -48,6 +48,7 @@ This section defines which drivers have to be loaded by Hooke.
     <csvdriver/>
     <!-- tutorialdriver/ -->
     <jpk/>
+    <mfp1dexport/>
     <mcs/>
 </drivers>
 
diff --git a/jpk.py b/jpk.py
index d83c17f2d38ba4025d0dac4adbbfb8fe9e099f7f..4f643317891f685e6a42261079e01d7e25db04c5 100644 (file)
--- a/jpk.py
+++ b/jpk.py
@@ -42,7 +42,7 @@ class jpkDriver(lhc.Driver):
     
     def is_me(self):
         '''
-        we define our magic heuristic for HemingClamp files
+        we define our magic heuristic for jpk files
         '''
         myfile=file(self.filename)
         headerlines=myfile.readlines()[0:3]
diff --git a/mcs.py b/mcs.py
index 27f4fab78da66a393e3dca5384d3ff6868b08bed..711e8c359625e646ca8225b8476634695810fc35 100644 (file)
--- a/mcs.py
+++ b/mcs.py
@@ -20,7 +20,7 @@ class mcsDriver(lhc.Driver):
         '''
         #obtain name of blue files
         othername=filename
-        if othername[-8]=='a':
+        if othername[-8]=='a': #fixme: how to make it general? (maybe should not be in driverspace but in environment...)
             oth=list(othername)
             oth[-8]='d'
             othername=''.join(oth)