Attachment '__init__.py'
import GRID
import Cytoscape
import PSI_MI
_FormatToIterator ={"grid" : GRID.GRIDIterator,
"cytoscape" : Cytoscape.InteractionReader
}
def parse(handle, format) :
"""Turns an interaction file into a iterator returning InteractionRecords
handle - handle to the file.
format - string describing the file format.
If you have the file name in a string 'filename', use:
import InteractionIO
my_iterator = InteractionIO.parse(open(filename), format)
If you have a string 'data' containing the file contents, use:
import InteractionIO
from StringIO import StringIO
my_iterator = InteractionIO.parse(StringIO(data), format)
"""
#Try and give helpful error messages:
if isinstance(handle, basestring) :
raise TypeError("Need a file handle, not a string (i.e. not a filename)")
if not isinstance(format, basestring) :
raise TypeError("Need a string for the file format (lower case)")
if not format :
raise ValueError("Format required (lower case string)")
if format <> format.lower() :
raise ValueError("Format string '%s' should be lower case" % format)
#Map the file format to a sequence iterator:
try :
iterator_generator = _FormatToIterator[format]
except KeyError :
raise ValueError("Unknown format '%s'" % format)
#Its up to the caller to close this handle - they opened it.
return iterator_generator(handle)
You are not allowed to view this page.
