def build_averaged_flowgrams(mapping, sff_fp, min_coverage=50, out_fp=None):
 l = len(mapping)
 (flowgrams, header) = lazy_parse_sff_handle(open(sff_fp))
 header['# of Reads'] = l
 header['Index Length'] = 'NA'
 if out_fp:
  out_filename = out_fp
 else:
  (fd, out_filename) = mkstemp(dir='/tmp/', prefix='prefix_dereplicated', suffix='.sff.txt')
  close(fd)
 outhandle = open(out_filename, 'w')
 write_sff_header(header, outhandle)
 seqs = {}
 sample_keys = sample_mapped_keys(mapping, min_coverage)
 for (ave_f, id) in _average_flowgrams(mapping, flowgrams, sample_keys):
  outhandle.write((ave_f.createFlowHeader() + '\n'))
  ave_f.Bases = ave_f.toSeq()
  seqs[id] = ave_f.Bases
 outhandle.close()
 return (out_filename, seqs)

def build_averaged_flowgrams ( mapping , sff_fp , min_coverage = 50 , out_fp = None ) : l = len ( mapping ) ( flowgrams , header ) = lazy_parse_sff_handle ( open ( sff_fp ) ) header [ '# of Reads' ] = l header [ 'Index Length' ] = 'NA' if out_fp : out_filename = out_fp else : ( fd , out_filename ) = mkstemp ( dir = '/tmp/' , prefix = 'prefix_dereplicated' , suffix = '.sff.txt' ) close ( fd ) outhandle = open ( out_filename , 'w' ) write_sff_header ( header , outhandle ) seqs = { } sample_keys = sample_mapped_keys ( mapping , min_coverage ) for ( ave_f , id ) in _average_flowgrams ( mapping , flowgrams , sample_keys ) : outhandle . write ( ( ave_f . createFlowHeader ( ) + '\n' ) ) ave_f . Bases = ave_f . toSeq ( ) seqs [ id ] = ave_f . Bases outhandle . close ( ) return ( out_filename , seqs )
build averaged flowgrams for each cluster in mapping .