(mcs.py , generaltccd.py) added first version of TCCD driver and utilities
authordevicerandom <devnull@localhost>
Thu, 7 May 2009 11:25:23 +0000 (11:25 +0000)
committerdevicerandom <devnull@localhost>
Thu, 7 May 2009 11:25:23 +0000 (11:25 +0000)
generaltccd.py [new file with mode: 0644]
hooke.conf
mcs.py [new file with mode: 0644]

diff --git a/generaltccd.py b/generaltccd.py
new file mode 100644 (file)
index 0000000..70ad513
--- /dev/null
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+
+'''
+generaltccd.py
+
+General utilities for TCCD stuff
+'''
+
+class generaltccdCommands:
+    
+    def plotmanip_threshold(self, plot, current, customvalue=False):
+        '''
+        Cuts from the plot everything below the threshold.
+        Set the threshold with "set tccd_threshold"
+        '''
+        
+        if current.curve.experiment != 'smfluo':
+            return plot
+        
+        if not self.config['tccd_threshold'] and (not customvalue):
+            return plot
+        
+        if customvalue:
+            thresh=customvalue
+        else:
+            thresh=self.config['tccd_threshold']
+        
+        for set in plot.vectors:
+            newy=[]
+            for value in set[1]:
+                if abs(value) < thresh:
+                    newy.append(0)
+                else:
+                    newy.append(value)
+            
+            set[1]=newy
+                    
+        return plot
+                
+
+    def plotmanip_coincident(self,plot,current, customvalue=False):
+        '''
+        Shows only coincident events
+        '''
+        if current.curve.experiment != 'smfluo':
+            return plot
+        
+        if not self.config['tccd_coincident'] and (not customvalue):
+            return plot
+        
+        newred=[]
+        newblue=[]
+        for index in range(len(plot.vectors[0][1])):
+            if abs(plot.vectors[0][1][index])>self.config['tccd_threshold'] and abs(plot.vectors[1][1][index])>self.config['tccd_threshold']:
+                newred.append(plot.vectors[0][1][index])
+                newblue.append(plot.vectors[1][1][index])
+            else:
+                newred.append(0)
+                newblue.append(0)
+                
+        plot.vectors[0][1]=newred
+        plot.vectors[1][1]=newblue
+     
+        return plot
\ No newline at end of file
index 439816da8458f5d0829cb7eb186aecdfb89d1d47..5fe84ba97fe2913015b73d72896bf19a9328ec0e 100755 (executable)
@@ -2,7 +2,7 @@
 <!-- To comment something, put dashes and ! like here -->
 <config>
 <!-- Internal variabls. -->
-    <display ext="1" colour_ext="None" ret="1" colour_ret="None" correct="1" colour_correct="None" contact_point="0" medfilt="0" xaxes="0" yaxes="0" flatten="1" temperature="301" auto_fit_points="50" auto_slope_span="20" auto_delta_force="10" auto_fit_nm="5" auto_min_p="0.005" auto_max_p="10" baseline_clicks="0" auto_left_baseline="20" auto_right_baseline="20" fc_showphase="0" fc_showimposed="0" fc_interesting="0"/>
+    <display ext="1" colour_ext="None" ret="1" colour_ret="None" correct="1" colour_correct="None" contact_point="0" medfilt="0" xaxes="0" yaxes="0" flatten="1" temperature="301" auto_fit_points="50" auto_slope_span="20" auto_delta_force="10" auto_fit_nm="5" auto_min_p="0.005" auto_max_p="10" baseline_clicks="0" auto_left_baseline="20" auto_right_baseline="20" fc_showphase="0" fc_showimposed="0" fc_interesting="0" tccd_threshold="0" tccd_coincident="0"/>
 
 <!-- 
 The following section defines your own work directory. Substitute your work directory.
@@ -35,6 +35,7 @@ This section defines which plugins have to be loaded by Hooke.
     <macro/>
     <autopeak/>
     <pcluster/>
+    <generaltccd/>
 </plugins>
 
 <!--
@@ -47,6 +48,7 @@ This section defines which drivers have to be loaded by Hooke.
     <csvdriver/>
     <!-- tutorialdriver/ -->
     <jpk/>
+    <mcs/>
 </drivers>
 
 <!--
@@ -59,6 +61,8 @@ and -IMPORTANTLY- their order.
     <!-- absvalue/ -->
     <flatten/>
     <clamp/>
+    <threshold/>
+    <coincident/>
 </plotmanips>
 
 </config>
diff --git a/mcs.py b/mcs.py
new file mode 100644 (file)
index 0000000..7ddd892
--- /dev/null
+++ b/mcs.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+
+'''
+mcs.py
+
+driver for mcs fluorescence files
+
+Massimo Sandal, Allen Chen (c) 2009
+'''
+
+import libhookecurve as lhc
+import libhooke as lh
+import struct
+
+class mcsDriver(lhc.Driver):
+    
+    def __init__(self, filename):
+        '''
+        Open the RED (A) ones; the BLUE (D) mirror ones will be automatically opened
+        '''
+        #obtain name of blue files
+        othername=filename
+        if othername[-8]=='a':
+            oth=list(othername)
+            oth[-8]='d'
+            othername=''.join(oth)
+        self.filename=filename
+        self.othername=othername    
+        
+        #print self.filename, self.othername
+        
+        self.filedata=open(filename,'rb')
+        self.reddata=self.filedata.read()
+        self.filedata.close()
+        
+        self.filebluedata=open(othername,'rb') #open also the blue ones
+        self.bluedata=self.filebluedata.read()
+        self.filebluedata.close()
+        
+        self.filetype = 'mcs'
+        self.experiment = 'smfluo'
+        
+    def is_me(self):
+        if self.filename[-3:]=='mcs':
+            return True
+        else:
+            return False
+        
+    def close_all(self):
+        self.filedata.close()
+        self.filebluedata.close()
+        
+        
+    def default_plots(self):
+        red_data=self.read_file(self.reddata)
+        blue_data=self.read_file(self.bluedata)
+        blue_data=[-1*float(item) for item in blue_data] #visualize blue as "mirror" of red
+        
+        main_plot=lhc.PlotObject()
+        main_plot.add_set(range(len(red_data)),red_data)
+        main_plot.add_set(range(len(blue_data)),blue_data)
+        main_plot.normalize_vectors()
+        main_plot.units=['time','count']  #FIXME: if there's an header saying something about the time count, should be used
+        main_plot.destination=0
+        main_plot.title=self.filename
+        main_plot.colors=['red','blue']
+        
+        return [main_plot]
+    
+    def read_file(self, raw_data):    
+        real_data=[]
+        intervalsperfile=struct.unpack('h', raw_data[10:12])[0] #read in number of intervals in this file
+                                                                #this data is contained in bit offset 10-12 in mcs file
+        #see http://docs.python.org/library/struct.html#module-struct for additional explanation
+        
+        numbytes=len(raw_data) #data is stored in 4-byte chunks, starting with pos 256
+        for j in range(0,intervalsperfile): #read in all intervals in file
+            temp=raw_data[256+j*4:256+j*4+4]    #data starts at byte offset 256
+            real_data.append(struct.unpack('i', temp)[0]) #[0] because it returns a 1-element tuple
+        return real_data
\ No newline at end of file