ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/io_module.py
(Generate patch)
# Line 16 | Line 16
16    >>> ba1 = io.readclamp("spritdata.txt")
17    >>> ba1 = io.readicmtxt("icmdata.txt")
18    >>> ba1 = io.readbiosensor("icmdata.txt")
19 +  >>> ba1 = io.readcsv("rawdata.csv")
20    >>> ba2 = io.applygal(ba1, "galfile.gal")
21    >>> ba2 = io.applykey(ba1, "keyfile.tsv")
22    >>> ba3 = io.applymethod(ba2, "icmmethod.xls")
23    >>> io.writesprit(ba3, "newspritfile.txt")
24    >>> io.writeclamp(ba3, "newclampfile.txt")
25   """
26 < __version__ = "110204"
26 > __version__ = "110207"
27  
28  
29   ## Import libraries.
# Line 324 | Line 325
325      """End of writebiosensor()"""
326  
327  
328 + def readcsv(fname):
329 +    """
330 +    Read a comma-separated value text file into a ba class.
331 +    The first column contains time data while the others contain response data.
332 +    Here is a very simple example of the tab-delimited format::
333 +    
334 +      1.0001, 23.7644, 0.7139
335 +      2.0001, 23.4265, 0.0541
336 +      3.0001, 23.1625, 0.3327
337 +      4.0001, 23.5752, 0.8494
338 +    """
339 +
340 +    ## Try to open file. Return tiny ba object if it fails.
341 +    ba0 = ba.BiosensorArray(1,1)
342 +    try:
343 +        fp = open(fname, "r")
344 +    except IOError:
345 +        print 'Error: Cannot open file %s for reading' % fname
346 +        return ba0
347 +      
348 +    ## Put data into one big text string, determine array size, and close.
349 +    txtfile = fp.readlines()  ## One big text string.
350 +    fp.close()
351 +    dpoints = len(txtfile)  ## Rows in the csv file.
352 +    rois = len(txtfile[0].split(',')) - 1  ## Columns are comma-delimited.
353 +    
354 +    ## Move the data from txtfile to ba0.
355 +    ba0 = ba.BiosensorArray(rois, dpoints)
356 +    for i, txtline in enumerate(txtfile):
357 +        x = txtline.split(',')
358 +        for j in range(rois):
359 +            ba0.roi[j].time[i] = float(x[0])
360 +            ba0.roi[j].value[i] = float(x[j+1])
361 +    
362 +    print "The file %s has %i ROIs and %i datapoints." % (fname, rois, dpoints)
363 +    return ba0
364 +    """End of readcsv()"""
365 +
366 +
367   def applygal(ba0, fname):
368      """
369      Read a Gal file and apply its microarray information.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines