ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/osprai/osprai/trunk/io_module.py
(Generate patch)
# Line 347 | Line 347
347          txt = str(txtfile[i].strip())
348          keytable[i] = txt.split('\t')
349      ## Use list comprehensions to get one list for each column.
350 <    id = [int(x[0]) for x in keytable]   ## First column is integer.
351 <    desc1 = [x[1] for x in keytable]     ## Second column is text.
352 <    desc2 = [x[2] for x in keytable]     ## Third column is text.
353 <    bg = [int(x[3]) for x in keytable]   ## Fourth column is integer.
350 >    id = [int(x[0]) for x in keytable]    ## First column is integer.
351 >    desc1 = [x[1] for x in keytable]      ## Second column is text.
352 >    desc2 = [x[2] for x in keytable]      ## Third column is text.
353 >    bg = [int(x[3]) for x in keytable]    ## Fourth column is integer. Change base1 to base0?
354      col = [int(x[4]) for x in keytable]   ## Fifth column is integer.
355      row = [int(x[5]) for x in keytable]   ## Sixth column is integer.
356      
# Line 360 | Line 360
360          print "Error: We have %i ROIs but %i keyfile entries." % (ba0.rois, keys)
361          return ba0
362      if ((min(bg) < min(id)) or (max(bg) > max (id))):
363 <        print "Error: a specified background ROI does not exist"
363 >        print "Error: at least one specified background ROI does not exist"
364 >        print "Identifiers (id) range from %i to %i." % (min(id), max(id))
365 >        print "Background references range from %i to %i." % (min(bg), max(bg))
366          return ba0
367          
368      ## Create new object and put data in it.
# Line 368 | Line 370
370      for i in range(len(id)):
371          ba1.roi[id[i]-1].name = desc1[i]
372          ba1.roi[id[i]-1].desc = desc2[i]
373 <        ba1.roi[id[i]-1].bgroi = [bg[i]]
373 >        ba1.roi[id[i]-1].bgroi = [bg[i]]  ## ToDo: Decide if bg will be id or index. Base1 now.
374          ba1.roi[id[i]-1].spotx = col[i]
375          ba1.roi[id[i]-1].spoty = row[i]
376      
# Line 381 | Line 383
383      """Read a ICM Analyte/Method xls file and apply its information."""
384      print "This feature is under construction."
385      ## End of applymethod() function
386 +    
387 +    
388 +
389 + def outputbindinglevels(ba0, fname, interval, *baselines):
390 +    """
391 +    Measure the binding level changes at multiple intervals along a sensorgram.
392 +    Write the data to a file.  If interval is 500 and baselines are [100, 1100] then
393 +    binding levels are changes between 100-600s and between 1100-01600s.
394 +    Average 30s of data.
395 +    """
396 +    fp=file(fname,'w')
397 +    
398 +    ## Measurements
399 +    for iroi in ba0.roi:
400 +        fp.write("%i\t%s" % (iroi.index, iroi.name))
401 +        for j in baselines:
402 +            t1 = j
403 +            t2 = j + interval
404 +            y1 = np.average(iroi.time2val(t1-15, t1+15))
405 +            y2 = np.average(iroi.time2val(t2-15, t2+15))
406 +            fp.write("\t%.3f" % (y2-y1))
407 +        fp.write("\n")
408 +    fp.close
409 +    print "File %s saved in %s." % (fname, getcwd())
410 +    ## End of outputbindinglevels() function
411  
412  
413   ## Here are a few lines to test this module.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines