def remove_artifacts_from_biom_table(table_filename,
                                     fasta_filename,
                                     ref_fp,
                                     biom_table_dir,
                                     ref_db_fp,
                                     threads=1,
                                     verbose=False,
                                     sim_thresh=None,
                                     coverage_thresh=None):
    """Remove artifacts from a biom table using SortMeRNA

    Parameters
    ----------
    table : str
        name of the biom table file
    fasta_filename : str
        the fasta file containing all the sequences of the biom table

    Returns
    -------
    tmp_files : list of str
        The temp files created during the artifact removal step
    """
    logger = logging.getLogger(__name__)
    logger.info('getting 16s sequences from the biom table')

    # remove artifacts from the fasta file. output is in clean_fp fasta file
    clean_fp, num_seqs_left, tmp_files = remove_artifacts_seqs(fasta_filename, ref_fp,
                                                               working_dir=biom_table_dir,
                                                               ref_db_fp=ref_db_fp,
                                                               negate=False, threads=threads,
                                                               verbose=verbose,
                                                               sim_thresh=sim_thresh,
                                                               coverage_thresh=coverage_thresh)
    if clean_fp is None:
        logger.warn("No clean sequences in %s" % fasta_filename)
        return tmp_files

    logger.debug('removed artifacts from sequences input %s'
                 ' to output %s' % (fasta_filename, clean_fp))

    # read the clean fasta file
    good_seqs = {s for _, s in sequence_generator(clean_fp)}
    logger.debug('loaded %d sequences from cleaned biom table'
                 ' fasta file' % len(good_seqs))

    logger.debug('loading biom table %s' % table_filename)
    table = load_table(table_filename)

    # filter and save the artifact biom table
    artifact_table = table.filter(list(good_seqs),
                                  axis='observation', inplace=False,
                                  invert=True)
    # remove the samples with 0 reads
    filter_minreads_samples_from_table(artifact_table)
    output_nomatch_fp = join(biom_table_dir, 'reference-non-hit.biom')
    write_biom_table(artifact_table, output_nomatch_fp)
    logger.info('wrote artifact only filtered biom table to %s'
                % output_nomatch_fp)
    # and save the reference-non-hit fasta file
    output_nomatch_fasta_fp = join(biom_table_dir, 'reference-non-hit.seqs.fa')
    fasta_from_biom(artifact_table, output_nomatch_fasta_fp)

    # filter and save the only 16s biom table
    table.filter(list(good_seqs), axis='observation')
    # remove the samples with 0 reads
    filter_minreads_samples_from_table(table)
    output_fp = join(biom_table_dir, 'reference-hit.biom')
    write_biom_table(table, output_fp)
    logger.info('wrote 16s filtered biom table to %s' % output_fp)
    # and save the reference-non-hit fasta file
    output_match_fasta_fp = join(biom_table_dir, 'reference-hit.seqs.fa')
    fasta_from_biom(table, output_match_fasta_fp)

    # we also don't need the cleaned fasta file
    tmp_files.append(clean_fp)
    return tmp_files
def remove_artifacts_from_biom_table ( table_filename , fasta_filename , ref_fp , biom_table_dir , ref_db_fp , threads = 1 , verbose = False , sim_thresh = None , coverage_thresh = None ) : logger = logging . getLogger ( __name__ ) logger . info ( 'getting 16s sequences from the biom table' ) clean_fp , num_seqs_left , tmp_files = remove_artifacts_seqs ( fasta_filename , ref_fp , working_dir = biom_table_dir , ref_db_fp = ref_db_fp , negate = False , threads = threads , verbose = verbose , sim_thresh = sim_thresh , coverage_thresh = coverage_thresh ) if clean_fp is None : logger . warn ( "No clean sequences in %s" % fasta_filename ) return tmp_files logger . debug ( 'removed artifacts from sequences input %s' ' to output %s' % ( fasta_filename , clean_fp ) ) good_seqs = { s for _ , s in sequence_generator ( clean_fp ) } logger . debug ( 'loaded %d sequences from cleaned biom table' ' fasta file' % len ( good_seqs ) ) logger . debug ( 'loading biom table %s' % table_filename ) table = load_table ( table_filename ) artifact_table = table . filter ( list ( good_seqs ) , axis = 'observation' , inplace = False , invert = True ) filter_minreads_samples_from_table ( artifact_table ) output_nomatch_fp = join ( biom_table_dir , 'reference-non-hit.biom' ) write_biom_table ( artifact_table , output_nomatch_fp ) logger . info ( 'wrote artifact only filtered biom table to %s' % output_nomatch_fp ) output_nomatch_fasta_fp = join ( biom_table_dir , 'reference-non-hit.seqs.fa' ) fasta_from_biom ( artifact_table , output_nomatch_fasta_fp ) table . filter ( list ( good_seqs ) , axis = 'observation' ) filter_minreads_samples_from_table ( table ) output_fp = join ( biom_table_dir , 'reference-hit.biom' ) write_biom_table ( table , output_fp ) logger . info ( 'wrote 16s filtered biom table to %s' % output_fp ) output_match_fasta_fp = join ( biom_table_dir , 'reference-hit.seqs.fa' ) fasta_from_biom ( table , output_match_fasta_fp ) tmp_files . append ( clean_fp ) return tmp_files
Remove artifacts from a biom table using SortMeRNA

    Parameters
    ----------
    table : str
        name of the biom table file
    fasta_filename : str
        the fasta file containing all the sequences of the biom table

    Returns
    -------
    tmp_files : list of str
        The temp files created during the artifact removal step