File size: 3,018 Bytes
5032722
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.font_manager
import matplotlib.ticker as mticker
from matplotlib import rc
plt.rcParams['text.usetex'] = True
plt.rcParams["font.family"] = 'Optima'
plt.rcParams["font.size"] = 20
plt.rc('axes', unicode_minus=False)
plt.tight_layout()


def make_plots(log_scale: bool):
    aic_fig, aic_ax = plt.subplots(figsize=[8,6])
    xax_lab = 'Number of parameters'
    
    def add_to_plots(mixture_type,
                     label,
                     color,
                     linestyle = '-',
                     marker = 'o'):
        # extract
        sub_df = df[ df['model_type'] == mixture_type ]
        sub_df = sub_df.sort_values(by='parameters')
        assert len(sub_df) > 0
        
        # add to aic plot
        aic_ax.plot( sub_df['parameters'],
                     sub_df['aic_gain'],
                     marker = marker,
                     linestyle = linestyle,
                     color = color,
                     label = label,
                     linewidth = 3.5,
                     markersize = 10)
        
        del sub_df, label
    
    add_to_plots(mixture_type = 'pairhmm_domain_mix',
                 label = 'Mixture of domain classes',
                 color = 'tab:purple')
    
    add_to_plots(mixture_type = 'pairhmm_fragment_mix',
                 label = 'Mixture of fragment classes',
                 color = 'tab:green')
    
    add_to_plots(mixture_type = 'pairhmm_site_mix',
                 label = 'Mixture of site classes',
                 color = 'tab:orange')
    
    aic_ax.grid()
    aic_ax.legend()
    aic_ax.set_xlabel(xax_lab)
    aic_ax.set_ylabel('$\Delta$AIC (×$10^7$)')
    new_y_tick_labels = [f"{x:.1e}".split("e")[0] for x in aic_ax.get_yticks()]
    aic_ax.set_yticklabels( new_y_tick_labels )
    del new_y_tick_labels
    
    if log_scale:
        aic_ax.set_xscale('log')
    
    aic_fig.savefig(f'AIC_parameters_log_{log_scale}.pdf', 
                    bbox_inches="tight")


def read_file(file):
    df = pd.read_csv(file, sep='\t', index_col=0)
    sub_df = df[ (df['dataset'] == 'data1') &
                 (df['sub_model'] == 'f81') &
                 (df['indel_model'] == 'tkf92') ]
    sub_df = sub_df[['sub_model',
                     'indel_model',
                     'model_type',
                     'parameters',
                     'aic',
                     'bic']]
    sub_df = sub_df.sort_values(by='parameters')
    
    ref = sub_df[ sub_df['model_type']=='pairhmm_reference' ]
    sub_df['aic_gain'] = ref['aic'].item() - sub_df['aic']
    sub_df['bic_gain'] = ref['bic'].item() - sub_df['bic']
    
    sub_df = sub_df.drop( ['aic','bic'], axis=1 )
    sub_df = sub_df[ sub_df['model_type'] !='pairhmm_reference' ]
    return sub_df


if __name__ == '__main__':
    df = read_file('hierarchical_mixture_models_train_set_loglikes.tsv')
    make_plots(log_scale = True)