#Libraries----------------------------------------------------------------------

"""
Dependencies and modules necessary for analytical functions to work
"""


#Data processing

import seaborn as sns
import matplotlib.pyplot as plt


#General
import collections


##Exploratory plots----------------------------------------------------------------------



def feature_check(data,var1=None, var2=None, type=None):
   
    """
    #Function takes the data file provided by the data_prep function and plots analytical contour plots to assess chemical feature distribution when considering a specific chemical entity category. That is,a categorical type data needs to be provided, such as active or inactive, etc.
    #Input:  data frame generated by the data_prep function, two variables for disctribution check, e.g. "MW" and "TSPA", and
    a column name to select categorical data from.
    #Output: contour plot with feature distribution.
    """
    #Error handling
    if var1 is None:
        print("Please enter a var1 for feature check")
        return data.head()
    if var2 is None:
        print("Please enter a var2 for feature check")
        return data.head()
    if type is None:
        print("Please enter a type for feature check")
        return data.head()

    #Missing data capture
    if var1 not in data.columns:
        print("%s not in the data frame provided" % var1)
        return (data.head())

    if var2 not in data.columns:
        print("%s not in the data frame provided" % var2)
        return (data.head())
    

    if type not in data.columns:
        print("%s not in the data frame provided" % type)
        return (data.head())

    #Plot

    #set values for plotting 
    data[var1] = data[var1].astype(float)
    data[var2] = data[var2].astype(float)
    data[type] = data[type].astype(str)

    #report compoisition
    print("Feature composition")
    print(dict(collections.Counter(data[type])))

    #density plot
    sns.jointplot(data=data, x=var1, y=var2, hue=type, kind="kde")

    #scatter plot
    sns.jointplot(data=data, x=var1, y=var2, hue=type, kind="scatter")
    plt.show()

    return

