Commit d6b5b7e4 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

allow to run other function than process

parent c2a9cd3f
......@@ -269,23 +269,58 @@ class VCFReader(_AbstractFeatureReader):
yield self._process_line(line)
class MpileupReader(_AbstractFeatureReader):
"""
Reader for Mpileup files.
"""
def _streaming_iter(self):
for line in self.fp :
if line == None or line == "" : continue
row = line.rstrip().split('\t')
if len(row) < 4 : continue
libs_count=[]
i=3
while (i < len(row) ) :
libs_count.append(int(row[i]))
i += 3
pileup = Entry(**{
'chrom' : row [0],
'pos' : int(row[1]),
'ref' : row[2],
'libs' : libs_count ,
})
yield pileup
libs_count=[]
def _wholefile_iter(self):
wholefile = self.fp.read()
assert '\r' not in wholefile, "Sorry, currently don't know how to deal with files that contain \\r linebreaks"
assert len(wholefile) == 0 , "Empty VCF file"
for line in wholefile.split('\n') :
row = line.rstrip().split('\t')
libs_count=[]
i=3
while (i < len(row) ) :
libs_count.append(int(row[i]))
i += 3
pileup = Entry(**{
'chrom' : row [0],
'pos' : int(row[1]),
'ref' : row[2],
'lib' : libs_count ,
})
yield pileup
libs_count=[]
class OboReader(_AbstractFeatureReader):
"""
Reader for OBO files.
"""
def __init__(self, file, wholefile=False):
"""
file is a filename or a file-like object.
If file is a filename, then .gz files are supported.
If wholefile is True, then it is ok to read the entire file
into memory. This is faster when there are many newlines in
the file, but may obviously need a lot of memory.
keep_linebreaks -- whether to keep the newline characters in the sequence
"""
if isinstance(file, basestring):
file = xopen(file, "r")
self.fp = file
self.wholefile = wholefile
def _streaming_iter(self):
"""
......@@ -352,10 +387,3 @@ class OboReader(_AbstractFeatureReader):
yield Entry(**{ 'id' : id, 'name' : name, 'namespace' : namespace, "parents" : parents })
parents = []
def __enter__(self):
if self.fp is None:
raise ValueError("I/O operation on closed FastaReader")
return self
def __exit__(self, *args):
self.fp.close()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment