def filter_otus_from_otu_map(input_otu_map_fp, output_otu_map_fp, min_count, min_sample_count=1):
 results = set()
 output_otu_map_f = open(output_otu_map_fp, 'w')
 for line in open(input_otu_map_fp, 'U'):
  fields = line.strip().split(' DCTB ')
  sample_ids = set([e.split('_')[0] for e in fields[1:]])
  if ((len(fields) > min_count) and (len(sample_ids) >= min_sample_count)):
   output_otu_map_f.write(line)
   results.add(fields[0].split(' DCTB ')[0])
 output_otu_map_f.close()
 return results

def filter_otus_from_otu_map ( input_otu_map_fp , output_otu_map_fp , min_count , min_sample_count = 1 ) : results = set ( ) output_otu_map_f = open ( output_otu_map_fp , 'w' ) for line in open ( input_otu_map_fp , 'U' ) : fields = line . strip ( ) . split ( ' DCTB ' ) sample_ids = set ( [ e . split ( '_' ) [ 0 ] for e in fields [ 1 : ] ] ) if ( ( len ( fields ) > min_count ) and ( len ( sample_ids ) >= min_sample_count ) ) : output_otu_map_f . write ( line ) results . add ( fields [ 0 ] . split ( ' DCTB ' ) [ 0 ] ) output_otu_map_f . close ( ) return results
filter otus with fewer than min_count sequences from input_otu_map_fp with very large data sets the number of singletons can be very large .