Back to index

python-biopython  1.60
CelFile.py
Go to the documentation of this file.
00001 # Copyright 2004 by Harry Zuzan.  All rights reserved.
00002 # This code is part of the Biopython distribution and governed by its
00003 # license.  Please see the LICENSE file that should have been included
00004 # as part of this package.
00005 
00006 """
00007 Classes for accessing the information in Affymetrix cel files.
00008 
00009 Functions:
00010 read      Read a cel file and store its contents in a Record
00011 
00012 Classes:
00013 Record    Contains the information from a cel file
00014 """
00015 
00016 import numpy
00017 
00018 class Record(object):
00019     """
00020     Stores the information in a cel file
00021     """
00022     def __init__(self):
00023         self.intensities = None
00024         self.stdevs = None
00025         self.npix = None
00026         self.nrows = None
00027         self.ncols = None
00028 
00029 
00030 def read(handle):
00031     """
00032     Read the information in a cel file, and store it in a Record.
00033     """
00034     # Needs error handling.
00035     # Needs to know the chip design.
00036     record = Record()
00037     section = ""
00038     for line in handle:
00039         if not line.strip():
00040             continue
00041         if line[:8]=="[HEADER]":
00042             section = "HEADER"
00043         elif line[:11]=="[INTENSITY]":
00044             section = "INTENSITY"
00045             record.intensities  = numpy.zeros((record.nrows, record.ncols))
00046             record.stdevs = numpy.zeros((record.nrows, record.ncols))
00047             record.npix = numpy.zeros((record.nrows, record.ncols), int)
00048         elif line[0]=="[":
00049             section = ""
00050         elif section=="HEADER":
00051             keyword, value = line.split("=", 1)
00052             if keyword=="Cols":
00053                 record.ncols = int(value)
00054             elif keyword=="Rows":
00055                 record.nrows = int(value)
00056         elif section=="INTENSITY":
00057             if "=" in line:
00058                 continue
00059             words = line.split()
00060             y, x = map(int, words[:2])
00061             record.intensities[x,y]  = float(words[2])
00062             record.stdevs[x,y] = float(words[3])
00063             record.npix[x,y]  = int(words[4])
00064     return record