<commit_before>import subprocess
from bipy.utils import (replace_suffix, which, flatten,
                         remove_suffix)
import os
import logging
from bcbio.utils import file_exists

logger = logging.getLogger(__name__)


def count_overlaps(in_file, bed, out_file=None):
    """ calculates coverage across the features in the bedfile
    bed """

    if not which("coverageBed"):
        logger.error("Cannot find coverageBed. Make sure it is in your "
                     "path or install bedtools.")
        exit(-1)

    if not out_file:
        out_file = replace_suffix(in_file, ".counts")

    if os.path.exists(out_file):<commit_msg>Added intersect.<commit_after>import subprocess
from bipy.utils import (replace_suffix, which, flatten,
                         remove_suffix)
import os
import logging
from bcbio.utils import file_exists
import sh

logger = logging.getLogger(__name__)

def intersect(bam_file, bed_file, exclude=False, out_file=None):
    """
    return the entries in bam_file that overlap (exclude=False) or
    do not overlap (exclude=True) with a feature bed_file.

    """

    (bam_base, bam_ext) = os.path.splitext(bam_file)
    (bed_base, bed_ext) = os.path.splitext(bed_file)

    if not out_file:
        out_prefix = bam_base + "_vs_" + bed_base
        if exclude:
            out_file = out_prefix + ".nointersect" + bam_ext
        else:
            out_file = out_prefix + ".intersect" + bam_ext

        if file_exists(out_file):
            return out_file

    if exclude:
        exclude_arg = "-v"
    else:
        exclude_arg = ""

        sh.bedtools.intersect("-u", exclude_arg, abam=bam_file, b=bed_file,
                              _out=out_file)

    return out_file


def count_overlaps(in_file, bed, out_file=None):
    """ calculates coverage across the features in the bedfile
    bed """

    if not which("coverageBed"):
        logger.error("Cannot find coverageBed. Make sure it is in your "
                     "path or install bedtools.")
        exit(-1)

    if not out_file:
        out_file = replace_suffix(in_file, ".counts")

    if os.path.exists(out_file):
{'fraction_non_alphanumeric': 0.09167446211412535, 'fraction_numerical': 0.0009354536950420954, 'mean_word_length': 2.5709515859766277, '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': '7115344', 'n_tokens_mistral': 683, 'n_tokens_neox': 647, 'n_words': 179}