def filter_genome(genome_in, threshold=<NUM_LIT>, list_records=None):
if list_records is None:<EOL><INDENT>def truth(*args):<EOL><INDENT>del args<EOL>return True<EOL><DEDENT>is_a_record_to_keep = truth<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>with open(list_records) as records_handle:<EOL><INDENT>records_to_keep = records_handle.readlines()<EOL><DEDENT><DEDENT>except OSError:<EOL><INDENT>if not hasattr(list_records, "<STR_LIT>"):<EOL><INDENT>raise<EOL><DEDENT>else:<EOL><INDENT>records_to_keep = list_records<EOL><DEDENT><DEDENT>is_a_record_to_keep = records_to_keep.__contains__<EOL><DEDENT>records_to_write = (<EOL>record<EOL>for record in SeqIO.parse(genome_in, "<STR_LIT>")<EOL>if (len(record.seq) >= threshold and is_a_record_to_keep(record.id))<EOL>)<EOL>return records_to_write<EOL>
Filter fasta file according to various parameters.

    Filter a fasta file according to size and/or an explicit list of records
    to keep.

    Parameters
    ----------
    genome_in: file, str or pathlib.Path
        The input genome in FASTA format.
    threshold: int, optional
        The size below which genome records are discarded. Default is the
        default minimum chunk size, i.e. 500.
    list_records: array_like, optional
        A list of record ids to keep. If not None, records that don't belong
        to that list are discarded. Default is None, i.e. all records are
        kept.

    Returns
    -------
    records_to_write: generator
        Filtered records that were kept.