def truncate_flowgrams_in_SFF(flowgrams, header, outhandle=None, outdir='/tmp/', barcode_mapping=None, primer=None, allow_num_ambigous=4):
 out_filename = ''
 if (not outhandle):
  (fd, out_filename) = mkstemp(dir=outdir, prefix='trunc_sff', suffix='.sff.txt')
  close(fd)
  outhandle = open(out_filename, 'w')
 write_sff_header(header, outhandle)
 l = 0
 for f in flowgrams:
  qual_trimmed_flowgram = f.getQualityTrimmedFlowgram()
  if barcode_mapping:
   if (f.Name in barcode_mapping):
    trunc_flowgram = qual_trimmed_flowgram.getPrimerTrimmedFlowgram(primerseq=((DEFAULT_KEYSEQ + barcode_mapping[f.Name]) + primer))
   else:
    continue
  else:
   prim = DEFAULT_KEYSEQ
   if primer:
    prim += primer
   trunc_flowgram = qual_trimmed_flowgram.getPrimerTrimmedFlowgram(primerseq=prim)
  if (trunc_flowgram is not None):
   outhandle.write((trunc_flowgram.createFlowHeader() + '\n'))
   l += 1
 return (out_filename, l)

def truncate_flowgrams_in_SFF ( flowgrams , header , outhandle = None , outdir = '/tmp/' , barcode_mapping = None , primer = None , allow_num_ambigous = 4 ) : out_filename = '' if ( not outhandle ) : ( fd , out_filename ) = mkstemp ( dir = outdir , prefix = 'trunc_sff' , suffix = '.sff.txt' ) close ( fd ) outhandle = open ( out_filename , 'w' ) write_sff_header ( header , outhandle ) l = 0 for f in flowgrams : qual_trimmed_flowgram = f . getQualityTrimmedFlowgram ( ) if barcode_mapping : if ( f . Name in barcode_mapping ) : trunc_flowgram = qual_trimmed_flowgram . getPrimerTrimmedFlowgram ( primerseq = ( ( DEFAULT_KEYSEQ + barcode_mapping [ f . Name ] ) + primer ) ) else : continue else : prim = DEFAULT_KEYSEQ if primer : prim += primer trunc_flowgram = qual_trimmed_flowgram . getPrimerTrimmedFlowgram ( primerseq = prim ) if ( trunc_flowgram is not None ) : outhandle . write ( ( trunc_flowgram . createFlowHeader ( ) + '\n' ) ) l += 1 return ( out_filename , l )
truncate flowgrams at low quality 3 end and strip key+primers .