<commit_before>#!/usr/bin/env python
import argparse
from collections import OrderedDict
import itertools
import sys
errors=[]
try:
    from brewer2mpl import qualitative
except ImportError as ie:
    errors.append('brewer2mpl')
try:
    from mpl_toolkits.mplot3d import Axes3D
except ImportError as ie:
    errors.append('matplotlib')
if len(errors) != 0:
    for item in errors:
        print 'Import Error. Please install missing module:', item
    sys.exit()
from brewer2mpl import qualitative
from mpl_toolkits.mplot3d import Axes3D
from pylab import *
from phylotoast import util

def parse_colors(file, categories=None):
    """
    Function to create an array of colors to represent all the categories.

    :type file: str
    :param file: Path to the file containing list of user defined matplotlib
                 colors in hex. Each color must be provided in separate line.

    :type categories: list
    :param categories: Any mapping category, which will be used to group data
                       in output iTol table.

    :rtype: list
    :return: Returns a list of colors matched to the number of different
             mapping categories.
    """
    colors = []
    with open(file, 'rU') as colorfile:
        for line in colorfile:
            line = line.strip()
            if line:
                colors.append(line)

    diff = len(categories) - len(colors)
    bmap = qualitative.Paired[12]
    brewer_colors = itertools.cycle(bmap.hex_colors)
    colors.extend([brewer_colors.next() for _ in range(diff)])

    return colors

def handle_program_options():
    parser = argparse.ArgumentParser(description="Create a 2D or 3D PCoA plot.\
                                     By default, this script opens a window\
                                     with the plot displayed if you want to\
                                     change certain aspects of the plot (such\
                                     as rotate the view in 3D mode). If the -o\
                                     option is specified, the plot will be\
                                     saved directly to an image without\
                                     the initial display window.")
    parser.add_argument('-i', '--coord_fp', required=True,
                        help="Input principal coordinates filepath (i.e.,\
                        resulting file from principal_coordinates.py)\
                        [REQUIRED].")
    parser.add_argument('-m', '--map_fp', required=True,
                        help="Input metadata mapping filepath [REQUIRED].")
    parser.add_argument('-b', '--colorby', required=True,
                        help="Any mapping categories, such as treatment type, \
                              that will be used to group the data in the \
                              output iTol table. For example, one category \
                              with three types will result in three data \
                              columns in the final output. Two categories with\
                              three types each will result in six data \
                              columns. Default is no categories and all the \
                              data will be treated as a single group.")
    parser.add_argument('-d', '--dimensions', default=2, type=int,
                        choices=[2, 3],
                        help="Choose whether to plot 2D or 3D.")
    parser.add_argument('-c', '--colors', default=None,
                        help="A file containing group colors (hex values).\
                        Each color should appear on a separate line, in the\
                        order in which the groups appear in the mapping file.\
                        If no file is specified, group colors will be assigned\
                        using the Brewer color set (Qualitative Set1 color\
                        scheme from brewer2mpl library). This color set will\
                        also be used if the user-specified list of colors is\
                        insufficient to cover all groups found in the mapping\
                        file.")
    parser.add_argument('-s', '--point_size', default=100, type=int,
                        help="Specify the size of the circles representing each\
                        of the samples in the plot")
    parser.add_argument('--pc_order', default=[1,2], type=int, nargs=2,
                        help="Choose which Principle Coordinates are displayed\
                              and in which order, for example: 1 2. This option\
                              is only used when a 2D plot is specified.")
    parser.add_argument('--x_limits', type=float, nargs=2,
                        help="Specify limits for the x-axis instead of\
                        automatic setting based on the data range. Should\
                        take the form: --x_limits -0.5 0.5")
    parser.add_argument('--y_limits', type=float, nargs=2,
                        help="Specify limits for the y-axis instead of\
                        automatic setting based on the data range. Should\
                        take the form: --y_limits -0.5 0.5")
    parser.add_argument('--z_limits', type=float, nargs=2,
                        help="Specify limits for the z-axis instead of\
                        automatic setting based on the data range. Should\
                        take the form: --z_limits -0.5 0.5")
    parser.add_argument('-t', '--title', default='', help="Title of the plot.")
    parser.add_argument('--figsize', default=[14, 8], type=int, nargs=2,
                        help="Set plot quality in Dots Per Inch (DPI). Larger\
                              DPI will result in larger file size.")
    parser.add_argument('-o', '--out_fp', default=None,
                        help="The path and file name to save the plot under.\
                              If specified, the figure will be saved directly\<commit_msg>Fixes the parameter name for point annotating in PCoA.py<commit_after>#!/usr/bin/env python
import argparse
from collections import OrderedDict
import itertools
import sys
errors=[]
try:
    from brewer2mpl import qualitative
except ImportError as ie:
    errors.append('brewer2mpl')
try:
    from mpl_toolkits.mplot3d import Axes3D
except ImportError as ie:
    errors.append('matplotlib')
if len(errors) != 0:
    for item in errors:
        print 'Import Error. Please install missing module:', item
    sys.exit()
from brewer2mpl import qualitative
from mpl_toolkits.mplot3d import Axes3D
from pylab import *
from phylotoast import util

def parse_colors(file, categories=None):
    """
    Function to create an array of colors to represent all the categories.

    :type file: str
    :param file: Path to the file containing list of user defined matplotlib
                 colors in hex. Each color must be provided in separate line.

    :type categories: list
    :param categories: Any mapping category, which will be used to group data
                       in output iTol table.

    :rtype: list
    :return: Returns a list of colors matched to the number of different
             mapping categories.
    """
    colors = []
    with open(file, 'rU') as colorfile:
        for line in colorfile:
            line = line.strip()
            if line:
                colors.append(line)

    diff = len(categories) - len(colors)
    bmap = qualitative.Paired[12]
    brewer_colors = itertools.cycle(bmap.hex_colors)
    colors.extend([brewer_colors.next() for _ in range(diff)])

    return colors

def handle_program_options():
    parser = argparse.ArgumentParser(description="Create a 2D or 3D PCoA plot.\
                                     By default, this script opens a window\
                                     with the plot displayed if you want to\
                                     change certain aspects of the plot (such\
                                     as rotate the view in 3D mode). If the -o\
                                     option is specified, the plot will be\
                                     saved directly to an image without\
                                     the initial display window.")
    parser.add_argument('-i', '--coord_fp', required=True,
                        help="Input principal coordinates filepath (i.e.,\
                        resulting file from principal_coordinates.py)\
                        [REQUIRED].")
    parser.add_argument('-m', '--map_fp', required=True,
                        help="Input metadata mapping filepath [REQUIRED].")
    parser.add_argument('-b', '--colorby', required=True,
                        help="Any mapping categories, such as treatment type, \
                              that will be used to group the data in the \
                              output iTol table. For example, one category \
                              with three types will result in three data \
                              columns in the final output. Two categories with\
                              three types each will result in six data \
                              columns. Default is no categories and all the \
                              data will be treated as a single group.")
    parser.add_argument('-d', '--dimensions', default=2, type=int,
                        choices=[2, 3],
                        help="Choose whether to plot 2D or 3D.")
    parser.add_argument('-c', '--colors', default=None,
                        help="A file containing group colors (hex values).\
                        Each color should appear on a separate line, in the\
                        order in which the groups appear in the mapping file.\
                        If no file is specified, group colors will be assigned\
                        using the Brewer color set (Qualitative Set1 color\
                        scheme from brewer2mpl library). This color set will\
                        also be used if the user-specified list of colors is\
                        insufficient to cover all groups found in the mapping\
                        file.")
    parser.add_argument('-s', '--point_size', default=100, type=int,
                        help="Specify the size of the circles representing each\
                        of the samples in the plot")
    parser.add_argument('--pc_order', default=[1,2], type=int, nargs=2,
                        help="Choose which Principle Coordinates are displayed\
                              and in which order, for example: 1 2. This option\
                              is only used when a 2D plot is specified.")
    parser.add_argument('--x_limits', type=float, nargs=2,
                        help="Specify limits for the x-axis instead of\
                        automatic setting based on the data range. Should\
                        take the form: --x_limits -0.5 0.5")
    parser.add_argument('--y_limits', type=float, nargs=2,
                        help="Specify limits for the y-axis instead of\
                        automatic setting based on the data range. Should\
                        take the form: --y_limits -0.5 0.5")
    parser.add_argument('--z_limits', type=float, nargs=2,
                        help="Specify limits for the z-axis instead of\
                        automatic setting based on the data range. Should\
                        take the form: --z_limits -0.5 0.5")
    parser.add_argument('-t', '--title', default='', help="Title of the plot.")
    parser.add_argument('--figsize', default=[14, 8], type=int, nargs=2,
                        help="Set plot quality in Dots Per Inch (DPI). Larger\
                              DPI will result in larger file size.")
    parser.add_argument('--annotate_points', action='store_true',
                        help="If specified, each graphed point will be\
                              labeled with its sample ID.")
    parser.add_argument('-o', '--out_fp', default=None,
                        help="The path and file name to save the plot under.\
                              If specified, the figure will be saved directly\
{'fraction_non_alphanumeric': 0.07787188553572896, 'fraction_numerical': 0.007894087657265028, 'mean_word_length': 1.5827139520067954, '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': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2516836', 'n_tokens_mistral': 3020, 'n_tokens_neox': 2868, 'n_words': 1165}