ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/io_module.py
(Generate patch)
# Line 1 | Line 1
1   """
2 < io: Input/Output module for converting files to Biosensor Array class.
3 < Christopher Lausted, Institute for Systems Biology, OSPRAI developers
4 < Last modified on 100409 (yymmdd)
5 <
6 < Examples:
7 < #import io_module as io
8 < #ba1 = io.readsprit("spritdata.txt")
9 < #ba1 = io.readclamp("spritdata.txt")
10 < #ba1 = io.readicmtxt("icmdata.txt")
11 < #ba1 = io.readbiosensor("icmdata.txt")
12 < #ba2 = io.applygal(ba1, "galfile.gal")
13 < #ba2 = io.applykey(ba1, "keyfile.tsv")
14 < #ba3 = io.applymethod(ba2, "icmmethod.xls")
15 < #io.writesprit(ba3, "newspritfile.txt")
16 < #io.writeclamp(ba3, "newclampfile.txt")
2 > io_module
3 > ---------
4 >
5 > Input/Output module for converting files to Biosensor Array class.
6 > Supported sensorgram types include Biosensor, CLAMP, SPRit, and Plexera ICM.
7 > Supported microarray types include GAL and ISB Map.
8 >
9 > .. moduleauthor:: Christopher Lausted,
10 >                  Institute for Systems Biology,
11 >                  OSPRAI developers.                      
12 > Examples::
13 >
14 >  >>> import io_module as io
15 >  >>> ba1 = io.readsprit("spritdata.txt")
16 >  >>> ba1 = io.readclamp("spritdata.txt")
17 >  >>> ba1 = io.readicmtxt("icmdata.txt")
18 >  >>> ba1 = io.readbiosensor("icmdata.txt")
19 >  >>> ba2 = io.applygal(ba1, "galfile.gal")
20 >  >>> ba2 = io.applykey(ba1, "keyfile.tsv")
21 >  >>> ba3 = io.applymethod(ba2, "icmmethod.xls")
22 >  >>> io.writesprit(ba3, "newspritfile.txt")
23 >  >>> io.writeclamp(ba3, "newclampfile.txt")
24   """
25 < __version__ = "100409"
25 > __version__ = "110204"
26 >
27  
28   ## Import libraries.
29   from copy import deepcopy
# Line 29 | Line 37
37      """
38      Read a SPRit text file into a ba class.
39      It has two tab-delimited columns and two header lines.
40 <    Here is a very simple example with 2 rois and 3 datapoints:
40 >    Here is a very simple example with 2 rois and 3 datapoints::
41      
42 <    Elapsed Time (Seconds)   Average Intensity (Pixel Intensity)
43 <    BEGIN
44 <    0.000000e+000            2.863145e+003
45 <    5.013000e+000            2.863367e+003
46 <    1.002500e+001            2.862950e+003
47 <    0.000000e+000            2.862875e+003
48 <    5.013000e+000            2.862510e+003
42 >      Elapsed Time (Seconds)   Average Intensity (Pixel Intensity)
43 >      BEGIN
44 >      0.000000e+000            2.863145e+003
45 >      5.013000e+000            2.863367e+003
46 >      1.002500e+001            2.862950e+003
47 >      0.000000e+000            2.862875e+003
48 >      5.013000e+000            2.862510e+003
49      """
50      
51      ## Try to open file. Return tiny ba object if it fails.
# Line 84 | Line 92
92              k +=1
93              
94      return ba0
95 <    ## End of readsprit() function
95 >    """End of readsprit() function"""
96      
97      
98   def writesprit(ba0, fname):
99 <    """Write a ba class to a SPRit text file."""
99 >    """
100 >    Write a ba class to a SPRit text file.
101 >    """
102      fp=file(fname,'w')
103      fp.write("Elapsed Time (Seconds)\tAverage Intensity (Pixel Intensity)\r\n")
104      fp.write("BEGIN\r\n")
# Line 98 | Line 108
108              fp.write(txt)
109      fp.close
110      print "File %s saved in %s." % (fname, getcwd())
111 <    ## End of writesprit() function
111 >    return
112 >    """End of writesprit() function"""
113      
114      
115   def readclamp(fname):
# Line 106 | Line 117
117      Read a Clamp text file into a ba class.
118      It has two tab-delimited columns per SPR flowcell/roi..
119      It has a varying number of header lines with injection information.
120 <    Here is a very simple example with 2 rois and 3 datapoints:
120 >    Here is a very simple example with 2 rois and 3 datapoints::
121      
122 <    Vers 3.41 Data
123 <    Conc1   0       0       0       0
124 <    Start1  301.5   301.5   301.5   301.5
125 <    Stop1   949.8   949.8   949.8   949.8
126 <    RInd1   0       0       0       0
127 <    Conc2   0       0       0       0
128 <    Start2  986.4   0       0       0
129 <    Stop2   1626    0       0       0
130 <    RInd2   0       0       0       0
131 <    Flow    1       1       1       1
132 <    Time1   Data1   Time2   Data2
133 <    0.094   0.062   0.094   0.053
134 <    1.094   0.026   1.094   0.05
135 <    2.094   0.119   2.094   0.055
122 >      Vers 3.41 Data
123 >      Conc1   0       0       0       0
124 >      Start1  301.5   301.5   301.5   301.5
125 >      Stop1   949.8   949.8   949.8   949.8
126 >      RInd1   0       0       0       0
127 >      Conc2   0       0       0       0
128 >      Start2  986.4   0       0       0
129 >      Stop2   1626    0       0       0
130 >      RInd2   0       0       0       0
131 >      Flow    1       1       1       1
132 >      Time1   Data1   Time2   Data2
133 >      0.094   0.062   0.094   0.053
134 >      1.094   0.026   1.094   0.05
135 >      2.094   0.119   2.094   0.055
136      """
137      
138      print "This feature is under construction."
139 <    ## End of readclamp() function
139 >    return
140 >    """"End of readclamp() function"""
141      
142      
143   def writeclamp(ba0, fname):
144 <    """Write a ba class to a Clamp text file."""
144 >    """
145 >    Write a ba class to a Clamp text file.
146 >    """
147      
148      fp=file(fname,'w')
149      ## First header line.
# Line 167 | Line 181
181      ## Close file handle and print message.
182      fp.close
183      print "File %s saved in %s." % (fname, getcwd())
184 <    ## End of writeclamp() function
184 >    return
185 >    """End of writeclamp() function"""
186      
187      
188   def readicmtxt(fname):
189      """
190      Read a ICM text file into a ba class.
191 <    Here is a very simple example of the tab-delimited format:
191 >    Here is a very simple example of the tab-delimited format::
192      
193 <    03/05/2010 13:37:21.312   249.408   0.000   0.000
194 <    03/05/2010 13:37:22.312   249.306   0.000   0.000
193 >      03/05/2010 13:37:21.312   249.408   0.000   0.000
194 >      03/05/2010 13:37:22.312   249.306   0.000   0.000
195      """
196  
197      ## Try to open file. Return tiny ba object if it fails.
# Line 210 | Line 225
225              ba0.roi[j].value[i] = float(x[j])
226              
227      return ba0
228 <    ## End of readicmtxt
228 >    """End of readicmtxt"""
229  
230  
231   def icmtime2sec(timetxt):
# Line 222 | Line 237
237      hh, min, ss = clock.split(":")
238      stime = (int(yy), int(mm), int(dd), int(hh), int(min), 0, 0, 0, 0)
239      return mktime(stime) + float(ss)
240 +    """End of icmtime2sec"""
241      
242      
243   def readbiosensor(fname):
244      """
245      Read a Biacore-style text file into a ba class.
246 <    Here is a very simple example of the tab-delimited format:
246 >    Here is a very simple example of the tab-delimited format::
247      
248 <    Ab1 Fc=4- 1_X  Ab1 Fc=4 -1_Y  Ab2 Fc=4 -1_X  Ab2 Fc=4 -1_Y
249 <    13.1           23.7644        93.1           0.713912
250 <    13.6           23.4265        93.6           0.0541172
251 <    14.1           23.1625        94.1           0.332768
252 <    14.6           23.5752        94.6           0.849459
248 >      Ab1 Fc=4- 1_X  Ab1 Fc=4 -1_Y  Ab2 Fc=4 -1_X  Ab2 Fc=4 -1_Y
249 >      13.1           23.7644        93.1           0.713912
250 >      13.6           23.4265        93.6           0.0541172
251 >      14.1           23.1625        94.1           0.332768
252 >      14.6           23.5752        94.6           0.849459
253      """
254  
255      ## Try to open file. Return tiny ba object if it fails.
# Line 279 | Line 295
295              ba0.roi[j].value[i] = float(x[j*2+1])
296      
297      return ba0
298 <    ## End of readbiosensor.
298 >    """End of readbiosensor()"""
299  
300  
301   def writebiosensor(ba0, fname):
302 <    """Write a ba class to a Biosensor text file."""
302 >    """
303 >    Write a ba class to a Biosensor text file.
304 >    """
305      
306      ## This is like a simplified Clamp file.
307      fp=file(fname,'w')
# Line 302 | Line 320
320      ## Close file handle and print message.
321      fp.close
322      print "File %s saved in %s." % (fname, getcwd())
323 <    ## End of writebiosensor() function
323 >    return
324 >    """End of writebiosensor()"""
325  
326  
327   def applygal(ba0, fname):
328 <    """Read a Gal file and apply its microarray information."""
328 >    """
329 >    Read a Gal file and apply its microarray information.
330 >    
331 >    *(This function is under construction)*
332 >    """
333      print "This feature is under construction."
334 <    ## End of applygal() function
334 >    return
335 >    """End of applygal()"""
336      
337      
338   def applykey(ba0, fname):
339      """
340      Read a Key file and apply its microarray information.
341      Multiple background ROIs are not yet supported.
342 <    Here is a very simple example :
342 >    Here is a very simple example::
343      
344 <    No. Description1    Description2    Background ROI  Col     Row
345 <    1   Rat TNF         Antibody01      2               1       1
346 <    2   ratIgG          Antibody02      4               2       1
347 <    3   Hum TNF         Antibody03      4               3       1
348 <    4   humIgG          Antibody04      2               4       1
344 >      No. Description1    Description2    Background ROI  Col     Row
345 >      1   Rat TNF         Antibody01      2               1       1
346 >      2   ratIgG          Antibody02      4               2       1
347 >      3   Hum TNF         Antibody03      4               3       1
348 >      4   humIgG          Antibody04      2               4       1
349      """
350      
351      ## Try to open file. Return unchanged ba object if it fails.
# Line 376 | Line 400
400      
401      print "Successfully loaded information for %i ROIs." % keys
402      return ba1
403 <    ## End of applykey() function
403 >    """End of applykey()"""
404      
405      
406   def applymethod(ba0, fname):
407 <    """Read a ICM Analyte/Method xls file and apply its information."""
407 >    """
408 >    Read a ICM Analyte/Method xls file and apply its information.
409 >    
410 >    *(This feature is under construction.)*
411 >    """
412      print "This feature is under construction."
413 <    ## End of applymethod() function
413 >    return
414 >    """End of applymethod()"""
415      
416      
417  
# Line 407 | Line 436
436          fp.write("\n")
437      fp.close
438      print "File %s saved in %s." % (fname, getcwd())
439 <    ## End of outputbindinglevels() function
439 >    return
440 >    """End of outputbindinglevels()"""
441  
442  
443   ## Here are a few lines to test this module.
444   if __name__ == '__main__':
445      print "This module isn't a stand-alone app."
446  
417 ################################# End of module #################################
447 + ################################# End of module #################################

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines