<commit_before>##
## GFF Writer (writer): serializing gffutils records as GFF text files.
##
##   Dear Sir or Madam, will you read my code?
##   It took me years to write, will you take a look?
##   It's based on code by a man named Daler
##   And I need a job, so I want to be a GFF Writer, GFF Writer.
##
import os
import sys
import time
import tempfile
import shutil
from time import strftime, localtime


class GFFWriter:
    """
    Simple GFF writer class for serializing gffutils
    records to a file.

    Parameters:
    -----------

    out: string or file-like object
        If a string, parsed as a filename. The strings `':stdout:'` and
        `':stderr:'` are treated specially to mean write to stdout/stderr,
        respectively. If `out` is not a string, then it is assumed to be
        a write-able stream.

    with_header: bool
        If True, output a header file for the GFF

    in_place: bool
        If True and if `out` is a filename, then write the file in place (uses
        named temporary files.)

    TODO: Add make separate GTFWriter class or add support
    for GTF here.
    """
    def __init__(self, out, with_header=True, in_place=False):
        self.out = out
        self.with_header = with_header
        self.in_place = in_place
        # Temporary file to be used (only applies when in_place is True)
        self.temp_file = None
        # Output stream to write to
        self.out_stream = None
        if type(out) == str:
            if self.in_place:
                # Use temporary file
                self.temp_file = tempfile.NamedTemporaryFile(delete=False)
                self.out_stream = open(self.temp_file.name, "w")
            else:
                # Just use the filename given
                self.out_stream = open(self.out, "w")
        else:
            # Assumed to be a write-able stream<commit_msg>be more flexible with output filenames<commit_after>##
## GFF Writer (writer): serializing gffutils records as GFF text files.
##
##   Dear Sir or Madam, will you read my code?
##   It took me years to write, will you take a look?
##   It's based on code by a man named Daler
##   And I need a job, so I want to be a GFF Writer, GFF Writer.
##
import os
import sys
import time
import tempfile
import shutil
from time import strftime, localtime


class GFFWriter:
    """
    Simple GFF writer class for serializing gffutils
    records to a file.

    Parameters:
    -----------

    out: string or file-like object
        If a string, parsed as a filename. The strings `':stdout:'` and
        `':stderr:'` are treated specially to mean write to stdout/stderr,
        respectively. If `out` is not a string, then it is assumed to be
        a write-able stream.

    with_header: bool
        If True, output a header file for the GFF

    in_place: bool
        If True and if `out` is a filename, then write the file in place (uses
        named temporary files.)

    TODO: Add make separate GTFWriter class or add support
    for GTF here.
    """
    def __init__(self, out, with_header=True, in_place=False):
        self.out = out
        self.with_header = with_header
        self.in_place = in_place
        # Temporary file to be used (only applies when in_place is True)
        self.temp_file = None
        # Output stream to write to
        self.out_stream = None
        if isinstance(out, basestring):
            if self.in_place:
                # Use temporary file
                self.temp_file = tempfile.NamedTemporaryFile(delete=False)
                self.out_stream = open(self.temp_file.name, "w")
            else:
                # Just use the filename given
                self.out_stream = open(self.out, "w")
        else:
            # Assumed to be a write-able stream
{'fraction_non_alphanumeric': 0.07637420718816068, 'fraction_numerical': 0.0, 'mean_word_length': 2.1726739312657166, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6573321', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1058, 'n_words': 460}