Package Bio :: Package Affy :: Module CelFile
[hide private]
[frames] | no frames]

Source Code for Module Bio.Affy.CelFile

 1  # Copyright 2004 by Harry Zuzan.  All rights reserved. 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6  """ 
 7  Classes for accessing the information in Affymetrix cel files. 
 8   
 9  Functions: 
10  read      Read a cel file and store its contents in a Record 
11   
12  Classes: 
13  Record    Contains the information from a cel file 
14  """ 
15   
16  import numpy 
17   
18   
19 -class Record(object):
20 """ 21 Stores the information in a cel file 22 """
23 - def __init__(self):
24 self.intensities = None 25 self.stdevs = None 26 self.npix = None 27 self.nrows = None 28 self.ncols = None
29 30
31 -def read(handle):
32 """ 33 Read the information in a cel file, and store it in a Record. 34 """ 35 # Needs error handling. 36 # Needs to know the chip design. 37 record = Record() 38 section = "" 39 for line in handle: 40 if not line.strip(): 41 continue 42 if line[:8] == "[HEADER]": 43 section = "HEADER" 44 elif line[:11] == "[INTENSITY]": 45 section = "INTENSITY" 46 record.intensities = numpy.zeros((record.nrows, record.ncols)) 47 record.stdevs = numpy.zeros((record.nrows, record.ncols)) 48 record.npix = numpy.zeros((record.nrows, record.ncols), int) 49 elif line[0] == "[": 50 section = "" 51 elif section == "HEADER": 52 keyword, value = line.split("=", 1) 53 if keyword == "Cols": 54 record.ncols = int(value) 55 elif keyword == "Rows": 56 record.nrows = int(value) 57 elif section == "INTENSITY": 58 if "=" in line: 59 continue 60 words = line.split() 61 y = int(words[0]) 62 x = int(words[1]) 63 record.intensities[x, y] = float(words[2]) 64 record.stdevs[x, y] = float(words[3]) 65 record.npix[x, y] = int(words[4]) 66 return record
67