def extract_primer(seq, possible_primers, min_idx=None, max_idx=None):
 primer_idx = None
 primer = None
 for possible_primer in possible_primers:
  if (possible_primer in seq):
   primer_idx = seq.index(possible_primer)
   primer = possible_primer
   if (((min_idx is not None) and (primer_idx < min_idx)) or ((max_idx is not None) and (primer_idx > max_idx))):
    primer_idx = None
    primer = None
   else:
    break
 if (primer_idx is None):
  raise PrimerMismatchError('Sequence does not contain any primers from the mapping file, Please verify your mapping file.')
 before_primer = seq[:primer_idx]
 after_primer = seq.replace((before_primer + primer), '', 1)
 return (before_primer, primer, after_primer)

def extract_primer ( seq , possible_primers , min_idx = None , max_idx = None ) : primer_idx = None primer = None for possible_primer in possible_primers : if ( possible_primer in seq ) : primer_idx = seq . index ( possible_primer ) primer = possible_primer if ( ( ( min_idx is not None ) and ( primer_idx < min_idx ) ) or ( ( max_idx is not None ) and ( primer_idx > max_idx ) ) ) : primer_idx = None primer = None else : break if ( primer_idx is None ) : raise PrimerMismatchError ( 'Sequence does not contain any primers from the mapping file, Please verify your mapping file.' ) before_primer = seq [ : primer_idx ] after_primer = seq . replace ( ( before_primer + primer ) , '' , 1 ) return ( before_primer , primer , after_primer )
given possible primers .