<commit_before>#!/usr/bin/env python
#
#     batch.py: implements 'batch' version of RnaChipIntegrator
#     Copyright (C) University of Manchester 2018-2019 <NAME>,
#     <NAME> & <NAME>
#
#     This code is free software; you can redistribute it and/or modify it
#     under the terms of the Artistic License 2.0 (see the file LICENSE
#     included with the distribution).
#
########################################################################
#
# batch.py
#
#########################################################################

"""
batch.py

Batch version of RnaChipIntegrator for analysing genomic features
(genes) with peak data.
"""

#######################################################################
# Imports
#######################################################################

import sys
import os
import optparse
from .Features import FeatureSet
from .Peaks import PeakSet
import analysis
import output
import xls_output
import logging
from multiprocessing import Pool

from .cli import _DEFAULTS
from .cli import _PROGRAM_INFO
from .cli import CLI
from .cli import OutputFiles
from .cli import AnalysisParams
from .cli import read_feature_file
from .cli import read_peak_file
from .cli import find_nearest_features
from .cli import find_nearest_peaks

from . import get_version
__version__ = get_version()

logging.getLogger().setLevel(logging.WARNING)
logging.basicConfig(format='%(levelname)s: %(message)s')

#######################################################################
# Functions
#######################################################################

def find_nearest_features_as_list(params):
    """
    Wrapper to fetch results from 'find_nearest_features' as a list
    """
    return list(find_nearest_features(params))

def find_nearest_peaks_as_list(params):
    """
    Wrapper to fetch results from 'find_nearest_peaks' as a list
    """
    return list(find_nearest_peaks(params))

#######################################################################
# Main program
#######################################################################

def main(args=None):
    """
    Implements the 'RnaChipIntegrator-batch' CLI
    """

    # Command line arguments
    if args is None:
        args = sys.argv[1:]

    p = CLI(usage="%(prog)s [options] [GENES PEAKS]",
            description=
            "Analyse GENES (any set of genes or genomic "
            "features) against one or more sets of PEAKS "
            "(a set of regions) and report nearest genes "
            "to each peak (and vice versa)")

    p.add_option_group("Analysis options")
    p.add_edge_option(group="Analysis options")
    p.add_only_de_option(group="Analysis options")
    p.add_option('-n','--nprocessors',action='store',
                 type=int,dest='nprocs',default=1,
                 help="Number of processors/cores to run the "
                 "program using (default: 1)",
                 group="Analysis options")

    p.add_option_group("Reporting options")
    p.add_number_option(group="Reporting options")
    p.add_promoter_region_option(group="Reporting options")

    p.add_option_group("Output options")
    p.add_name_option(group="Output options")
    p.add_compact_option(group="Output options")
    p.add_summary_option(group="Output options")
    p.add_pad_option(group="Output options")
    p.add_xlsx_option(group="Output options")

    p.add_option_group("Batch options")
    p.add_option('--cutoffs',action='store',dest='cutoffs',
                 default=None,
                 help="Comma-separated list of one or more "
                 "maximum distances allowed between peaks "
                 "and genes (bp). An analysis will be "
                 "performed for each GENES-PEAKS pair at "<commit_msg>batch: update the description supplied to the CLI class for creating the parser.<commit_after>#!/usr/bin/env python
#
#     batch.py: implements 'batch' version of RnaChipIntegrator
#     Copyright (C) University of Manchester 2018-2019 <NAME>,
#     <NAME> & <NAME>
#
#     This code is free software; you can redistribute it and/or modify it
#     under the terms of the Artistic License 2.0 (see the file LICENSE
#     included with the distribution).
#
########################################################################
#
# batch.py
#
#########################################################################

"""
batch.py

Batch version of RnaChipIntegrator for analysing genomic features
(genes) with peak data.
"""

#######################################################################
# Imports
#######################################################################

import sys
import os
import optparse
from .Features import FeatureSet
from .Peaks import PeakSet
import analysis
import output
import xls_output
import logging
from multiprocessing import Pool

from .cli import _DEFAULTS
from .cli import _PROGRAM_INFO
from .cli import CLI
from .cli import OutputFiles
from .cli import AnalysisParams
from .cli import read_feature_file
from .cli import read_peak_file
from .cli import find_nearest_features
from .cli import find_nearest_peaks

from . import get_version
__version__ = get_version()

logging.getLogger().setLevel(logging.WARNING)
logging.basicConfig(format='%(levelname)s: %(message)s')

#######################################################################
# Functions
#######################################################################

def find_nearest_features_as_list(params):
    """
    Wrapper to fetch results from 'find_nearest_features' as a list
    """
    return list(find_nearest_features(params))

def find_nearest_peaks_as_list(params):
    """
    Wrapper to fetch results from 'find_nearest_peaks' as a list
    """
    return list(find_nearest_peaks(params))

#######################################################################
# Main program
#######################################################################

def main(args=None):
    """
    Implements the 'RnaChipIntegrator-batch' CLI
    """

    # Command line arguments
    if args is None:
        args = sys.argv[1:]

    p = CLI(usage="%(prog)s [options] [GENES PEAKS]",
            description=
            "Analyse GENES (any set of genes or genomic "
            "features) against PEAKS (a set of regions) "
            "and report nearest genes to each peak (and "
            "vice versa)")

    p.add_option_group("Analysis options")
    p.add_edge_option(group="Analysis options")
    p.add_only_de_option(group="Analysis options")
    p.add_option('-n','--nprocessors',action='store',
                 type=int,dest='nprocs',default=1,
                 help="Number of processors/cores to run the "
                 "program using (default: 1)",
                 group="Analysis options")

    p.add_option_group("Reporting options")
    p.add_number_option(group="Reporting options")
    p.add_promoter_region_option(group="Reporting options")

    p.add_option_group("Output options")
    p.add_name_option(group="Output options")
    p.add_compact_option(group="Output options")
    p.add_summary_option(group="Output options")
    p.add_pad_option(group="Output options")
    p.add_xlsx_option(group="Output options")

    p.add_option_group("Batch options")
    p.add_option('--cutoffs',action='store',dest='cutoffs',
                 default=None,
                 help="Comma-separated list of one or more "
                 "maximum distances allowed between peaks "
                 "and genes (bp). An analysis will be "
                 "performed for each GENES-PEAKS pair at "
{'fraction_non_alphanumeric': 0.2322767328686045, 'fraction_numerical': 0.003419702748914902, 'mean_word_length': 4.025776602775942, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '5276383', 'n_tokens_mistral': 2071, 'n_tokens_neox': 1959, 'n_words': 559}