<commit_before>import numpy as np
from scipy import optimize as sciopt
from Bio import Phylo
from . import config as ttconf
from . import MissingDataError,UnknownMethodError,NotReadyError,TreeTimeError, TreeTimeOtherError
from .utils import tree_layout
from .clock_tree import ClockTree

rerooting_mechanisms = ["min_dev", "best", "least-squares"]
deprecated_rerooting_mechanisms = {"residual":"least-squares", "res":"least-squares",
                                   "min_dev_ML": "min_dev", "ML":"least-squares"}


def reduce_time_marginal_argument(input_time_marginal):
    '''
    This function maps deprecated arguments/terms for the timetree inference mode
    to recommended terms.
    '''
    if input_time_marginal in [False, 'false', 'never']:
        return 'never'
    elif input_time_marginal in [True, 'always', 'true']:
        return 'always'
    elif input_time_marginal in ['only-final', 'assign']:
        return 'only-final'
    elif input_time_marginal == 'confidence-only':
        return input_time_marginal
    else:
        raise UnknownMethodError(f"'{input_time_marginal}' is not a known time marginal argument")


class TreeTime(ClockTree):
    """
    TreeTime is a wrapper class to ClockTree that adds additional functionality
    such as reroot, detection and exclusion of outliers, resolution of polytomies
    using temporal information, and relaxed molecular clock models
    """

    def __init__(self, *args,**kwargs):
        """
        TreeTime constructor

        Parameters
        -----------
         *args
            Arguments to construct ClockTree

         **kwargs
            Keyword arguments to construct the GTR model

        """
        super(TreeTime, self).__init__(*args, **kwargs)


    def run(self, augur=False, **kwargs):
        import sys
        try:
            self._run(**kwargs)
        except TreeTimeError as err:
            print(f"ERROR: {err} \n", file=sys.stderr)
            if augur:
                raise err
            else:
                sys.exit(2)
        except BaseException as err:
            import traceback
            print(traceback.format_exc())
            print(f"ERROR: {err} \n ", file=sys.stderr)
            print("ERROR in TreeTime.run: An error has occurred which is not properly handled in TreeTime. If this error persists, please let us know "
                    "by filing a new issue including the original command and the error above at: https://github.com/neherlab/treetime/issues \n", file=sys.stderr)
            if augur:
                raise TreeTimeOtherError() from err<commit_msg>add back return statement<commit_after>import numpy as np
from scipy import optimize as sciopt
from Bio import Phylo
from . import config as ttconf
from . import MissingDataError,UnknownMethodError,NotReadyError,TreeTimeError, TreeTimeOtherError
from .utils import tree_layout
from .clock_tree import ClockTree

rerooting_mechanisms = ["min_dev", "best", "least-squares"]
deprecated_rerooting_mechanisms = {"residual":"least-squares", "res":"least-squares",
                                   "min_dev_ML": "min_dev", "ML":"least-squares"}


def reduce_time_marginal_argument(input_time_marginal):
    '''
    This function maps deprecated arguments/terms for the timetree inference mode
    to recommended terms.
    '''
    if input_time_marginal in [False, 'false', 'never']:
        return 'never'
    elif input_time_marginal in [True, 'always', 'true']:
        return 'always'
    elif input_time_marginal in ['only-final', 'assign']:
        return 'only-final'
    elif input_time_marginal == 'confidence-only':
        return input_time_marginal
    else:
        raise UnknownMethodError(f"'{input_time_marginal}' is not a known time marginal argument")


class TreeTime(ClockTree):
    """
    TreeTime is a wrapper class to ClockTree that adds additional functionality
    such as reroot, detection and exclusion of outliers, resolution of polytomies
    using temporal information, and relaxed molecular clock models
    """

    def __init__(self, *args,**kwargs):
        """
        TreeTime constructor

        Parameters
        -----------
         *args
            Arguments to construct ClockTree

         **kwargs
            Keyword arguments to construct the GTR model

        """
        super(TreeTime, self).__init__(*args, **kwargs)


    def run(self, augur=False, **kwargs):
        import sys
        try:
            return self._run(**kwargs)
        except TreeTimeError as err:
            print(f"ERROR: {err} \n", file=sys.stderr)
            if augur:
                raise err
            else:
                sys.exit(2)
        except BaseException as err:
            import traceback
            print(traceback.format_exc())
            print(f"ERROR: {err} \n ", file=sys.stderr)
            print("ERROR in TreeTime.run: An error has occurred which is not properly handled in TreeTime. If this error persists, please let us know "
                    "by filing a new issue including the original command and the error above at: https://github.com/neherlab/treetime/issues \n", file=sys.stderr)
            if augur:
                raise TreeTimeOtherError() from err
{'fraction_non_alphanumeric': 0.0900210687607738, 'fraction_numerical': 0.0003830683777054204, 'mean_word_length': 2.569377990430622, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1031075', 'n_tokens_mistral': 1471, 'n_tokens_neox': 1390, 'n_words': 455}