6 Driver for mcs fluorescence files.
8 Copyright 2009 by Massimo Sandal, Allen Chen
9 with modifications by Dr. Rolf Schmidt (Concordia University, Canada)
11 This program is released under the GNU General Public License version 2.
21 class mcsDriver(lib.driver.Driver):
23 def __init__(self, filename):
25 Open the RED (A) ones; the BLUE (D) mirror ones will be automatically opened
27 #obtain name of blue files
29 if othername[-8]=='a': #fixme: how to make it general? (maybe should not be in driverspace but in environment...)
32 othername=''.join(oth)
33 self.filename=filename
34 self.othername=othername
36 #print self.filename, self.othername
38 self.filedata=open(filename,'rb')
39 self.reddata=self.filedata.read()
42 self.filebluedata=open(othername,'rb') #open also the blue ones
43 self.bluedata=self.filebluedata.read()
44 self.filebluedata.close()
47 self.experiment = 'smfluo'
51 self.filebluedata.close()
53 def default_plots(self):
54 #TODO: rename blue and red data to something more appropriate if possible
55 red_data=self.read_file(self.reddata)
56 blue_data=self.read_file(self.bluedata)
57 blue_data=[-1*float(item) for item in blue_data] #visualize blue as "mirror" of red
59 extension = lib.curve.Curve()
60 retraction = lib.curve.Curve()
62 extension.color = 'red'
63 extension.label = 'extension'
64 extension.style = 'plot'
65 extension.title = 'Force curve'
66 #FIXME: if there's an header saying something about the time count, should be used
67 #TODO: time is not really a unit
68 extension.units.x = 'time'
69 extension.units.y = 'count'
70 extension.x = range(len(red_data))
71 extension.y = red_data
72 retraction.color = 'blue'
73 retraction.label = 'retraction'
74 retraction.style = 'plot'
75 retraction.title = 'Force curve'
76 #FIXME: if there's an header saying something about the time count, should be used
77 #TODO: time is not really a unit
78 retraction.units.x = 'time'
79 retraction.units.y = 'count'
80 retraction.x = range(len(blue_data))
81 retraction.y = blue_data
83 plot = lib.plot.Plot()
84 plot.title = os.path.basename(self.filename)
85 plot.curves.append(extension)
86 plot.curves.append(retraction)
92 if self.filename[-3:].lower()=='mcs':
97 def read_file(self, raw_data):
99 intervalsperfile=struct.unpack('h', raw_data[10:12])[0] #read in number of intervals in this file
100 #this data is contained in bit offset 10-12 in mcs file
101 #see http://docs.python.org/library/struct.html#module-struct for additional explanation
103 numbytes=len(raw_data) #data is stored in 4-byte chunks, starting with pos 256
104 for j in range(0,intervalsperfile): #read in all intervals in file
105 temp=raw_data[256+j*4:256+j*4+4] #data starts at byte offset 256
106 real_data.append(struct.unpack('i', temp)[0]) #[0] because it returns a 1-element tuple