1 '''Tools for working with files in the samtools pileup -c format.'''
5 PileupSubstitution = collections.namedtuple( "PileupSubstitution",
13 "rms_mapping_quality",
16 "base_qualities" ) ) )
18 PileupIndel = collections.namedtuple( "PileupIndel",
26 "rms_mapping_quality",
34 def iterate( infile ):
35 '''iterate over ``samtools pileup -c`` formatted file.
37 *infile* can be any iterator over a lines.
39 The function yields named tuples of the type :class:`pysam.Pileup.PileupSubstitution`
40 or :class:`pysam.Pileup.PileupIndel`.
43 The parser converts to 0-based coordinates
46 conv_subst = (str,lambda x: int(x)-1,str,str,int,int,int,int,str,str)
47 conv_indel = (str,lambda x: int(x)-1,str,str,int,int,int,int,str,str,int,int,int)
53 yield PileupIndel( *[x(y) for x,y in zip(conv_indel,d) ] )
55 raise pysam.SamtoolsError( "parsing error in line: `%s`" % line)
58 yield PileupSubstitution( *[x(y) for x,y in zip(conv_subst,d) ] )
60 raise pysam.SamtoolsError( "parsing error in line: `%s`" % line)