code: def sortmerna_ref_cluster(seq_path=None,
                            sortmerna_db=None,
                            refseqs_fp=None,
                            result_path=None,
                            tabular=False,
                            max_e_value=1,
                            similarity=0.97,
                            coverage=0.97,
                            threads=1,
                            best=1,
                            HALT_EXEC=False
                            ):
      smr = Sortmerna(HALT_EXEC=HALT_EXEC)
      if seq_path is not None:
          smr.Parameters['--reads'].on(seq_path)
      else:
          raise ValueError("Error: a read file is mandatory input.")
      if sortmerna_db is not None:
          smr.Parameters['--ref'].on("%s,%s" % (refseqs_fp, sortmerna_db))
      else:
          raise ValueError("Error: an indexed database for reference set %s must"
                           " already exist.\nUse indexdb_rna to index the"
                           " database." % refseqs_fp)
      if result_path is None:
          raise ValueError("Error: the result path must be set.")
      output_dir = dirname(result_path)
      if output_dir is not None:
          output_file = join(output_dir, "sortmerna_otus")
          smr.Parameters['--aligned'].on(output_file)
      if max_e_value is not None:
          smr.Parameters['-e'].on(max_e_value)
      if similarity is not None:
          smr.Parameters['--id'].on(similarity)
      if coverage is not None:
          smr.Parameters['--coverage'].on(coverage)
      if best is not None:
          smr.Parameters['--best'].on(best)
      if tabular:
          smr.Parameters['--blast'].on("3")
      if threads is not None:
          smr.Parameters['-a'].on(threads)
      app_result = smr()
      f_otumap = app_result['OtuMap']
      rows = (line.strip().split('\t') for line in f_otumap)
      clusters = {r[0]: r[1:] for r in rows}
      f_failure = app_result['FastaForDenovo']
      failures = [re.split('>| ', label)[0]
                  for label, seq in parse_fasta(f_failure)]
      smr_files_to_remove = [app_result['FastaForDenovo'].name,
                             app_result['FastaMatches'].name,
                             app_result['OtuMap'].name]
      return clusters, failures, smr_files_to_remove