Source code for rhapsody.predict.figures

# -*- coding: utf-8 -*-
"""This module defines functions for generating figures that help
inspect the predictions obtained from the main class."""

import os
import warnings
import numpy as np
from string import Template
from prody import LOGGER, SETTINGS
from .core import Rhapsody

__all__ = ['print_sat_mutagen_figure']

__author__ = "Luca Ponzoni"
__date__ = "December 2019"
__maintainer__ = "Luca Ponzoni"
__email__ = "lponzoni@pitt.edu"
__status__ = "Production"


def _try_import_matplotlib():
    try:
        import matplotlib as plt
        plt.rcParams.update({'font.size': 20, 'font.family': 'Arial'})
    except ImportError:
        LOGGER.warn('matplotlib is required for generating figures')
        return None
    return plt


def _adjust_res_interval(res_interval, upper_lim, min_size=10):
    res_i = max(1, res_interval[0])
    res_f = max(1, res_interval[1])
    n = min_size - 1
    while (res_f - res_i) < n:
        if res_i > 1:
            res_i -= 1
        if (res_f - res_i) >= n:
            break
        res_f += 1
    res_f = min(upper_lim, res_f)
    return (res_i, res_f)