function score = calc_classifiation_score(TP, FP, FN, TN, alg, perc)

% score = calc_classifiation_score(TP, FP, FN, TN, alg, perc)
% 
% This function calculates chosen classification score 
%
% TP        - true  positive
% FP        - false positive
% FN        - false negative
% TN        - true  negative
% alg       - algorithm used to calculate the score (e.g. TSS)
% perc      - return the classification score in percents
%             [0 = OFF, 1 = ON], default: 0 => score [-]
%
% score     - calculated classification score
%
%
%
% --
% ing. Zoltán Galáž
% xgalaz00@stud.feec.vutbr.cz       
% 
% Department of Telecommunications
% Faculty of Electrical Engineering and Communication
% Brno University of Technology

%% Paths and variables / calculate (TSS)
if ((nargin < 6) || (isempty(perc)))
    perc = 0;
end
if ((nargin < 5) || (isempty(alg)))
    alg = 'tss';
end

%% Lower the algorithm string (for consistency)
alg = lower(alg);

%% Calculate selected classification score
if (strcmp(alg, 'acc')                                              || ...
    strcmp(alg, 'accuracy')                                         || ...
    strcmp(alg, 'classification acc')                               || ...
    strcmp(alg, 'classification accuracy'))

    % Classification accuracy
    score = ...
        classification_accuracy(TP, FP, FN, TN, perc);
    
elseif (strcmp(alg, 'tss')                                          || ...
        strcmp(alg, 'tradeoff sen spe')                             || ...
        strcmp(alg, 'tradeoff between sen spe')                     || ...
        strcmp(alg, 'tradeoff between sen and spe'))
    
    % Tradeoff between sensitivity and specificity
    score = ...
        tradeoff_between_sen_spe(TP, FP, FN, TN);
    
elseif (strcmp(alg, 'f1')                                           || ...
        strcmp(alg, 'f1 alg')                                       || ...
        strcmp(alg, 'classification f1')                            || ...
        strcmp(alg, 'classification f1 alg'))
    
    % Classification F1 score
    score = ...
        classification_F1_alg(TP, FP, FN, perc);
    
elseif (strcmp(alg, 'inf')                                          || ...
        strcmp(alg, 'informedness')                                 || ...
        strcmp(alg, 'classification inf')                           || ...
        strcmp(alg, 'classification informedness'))
    
    % Classification informedness
    score = ...
        classification_informedness(TP, FP, FN, TN, perc);
    
elseif (strcmp(alg, 'mar')                                          || ...
        strcmp(alg, 'markedness')                                   || ...
        strcmp(alg, 'classification mar')                           || ...
        strcmp(alg, 'classification markedness'))
    
    % Classification markedness
    score = ...
        classification_markedness(TP, FP, FN, TN, perc);
    
elseif (strcmp(alg, 'pre')                                          || ...
        strcmp(alg, 'prevalence')                                   || ...
        strcmp(alg, 'classification pre')                           || ...
        strcmp(alg, 'classification prevalence'))
    
    % Classification prevalence
    score = ...
        classification_prevalence(TP, FP, FN, TN, perc);
    
elseif (strcmp(alg, 'sen')                                          || ...
        strcmp(alg, 'sensitivity')                                  || ...
        strcmp(alg, 'classification sen')                           || ...
        strcmp(alg, 'classification sensitivity'))
    
    % Classification sensitivity
    score = ...
        classification_sensitivity(TP, FN, perc);
    
elseif (strcmp(alg, 'spe')                                          || ...
        strcmp(alg, 'specificity')                                  || ...
        strcmp(alg, 'classification spe')                           || ...
        strcmp(alg, 'classification specificity'))
    
    % Classification specificity
    score = ...
        classification_specificity(FP, TN, perc);
    
elseif (strcmp(alg, 'dor')                                          || ...
        strcmp(alg, 'odds ratio')                                   || ...
        strcmp(alg, 'diagnostic odds')                              || ...
        strcmp(alg, 'diagnostic odds ratio')                        || ...
        strcmp(alg, 'classification odds')                          || ...
        strcmp(alg, 'classification odds ratio'))
    
    % Classification (diagnostic) odds ratio
    score = ...
        diagnostic_odds_ratio(TP, FP, FN, TN, perc);
    
elseif (strcmp(alg, 'fdr')                                          || ...
        strcmp(alg, 'false dr')                                     || ...
        strcmp(alg, 'false discovery r')                            || ...
        strcmp(alg, 'false discovery rate'))
    
    % False discovery rate
    score = ...
        false_discovery_rate(TP, FP, perc);
    
elseif (strcmp(alg, 'fnr')                                          || ...
        strcmp(alg, 'false nr')                                     || ...
        strcmp(alg, 'false negative r')                             || ...
        strcmp(alg, 'false negative rate'))
    
    % False negative rate
    score = ...
        false_negative_rate(TP, FN, perc);
    
elseif (strcmp(alg, 'for')                                          || ...
        strcmp(alg, 'false or')                                     || ...
        strcmp(alg, 'false omission r')                             || ...
        strcmp(alg, 'false omission rate'))
    
    % False omission rate
    score = ...
        false_omission_rate(TN, FN, perc);
    
elseif (strcmp(alg, 'fpr')                                          || ...
        strcmp(alg, 'false pr')                                     || ...
        strcmp(alg, 'false positive r')                             || ...
        strcmp(alg, 'false positive rate'))
    
    % False positive rate
    score = ...
        false_positive_rate(TN, FP, perc);
    
elseif (strcmp(alg, 'mcc')                                          || ...
        strcmp(alg, 'mathews cc')                                   || ...
        strcmp(alg, 'mathews corr coef')                            || ...
        strcmp(alg, 'mathews correlation coef'))
    
    % Mathew's correlation coefficient
    score = ...
        Mathews_correlation_coef(TP, FP, FN, TN);
    
elseif (strcmp(alg, 'nlr')                                          || ...
        strcmp(alg, 'negative lr')                                  || ...
        strcmp(alg, 'negative likelihood r')                        || ...
        strcmp(alg, 'negative likelihood ratio'))
    
    % Negative likelihood ration
    score = ...
        negative_likelihood_ratio(FP, TN, perc);
    
elseif (strcmp(alg, 'npv')                                          || ...
        strcmp(alg, 'negative pv')                                  || ...
        strcmp(alg, 'negative predictive v')                        || ...
        strcmp(alg, 'negative predictive value'))
    
    % Negative predictive value
    score = ...
        negative_predictive_value(TN, FN, perc);
    
elseif (strcmp(alg, 'plr')                                          || ...
        strcmp(alg, 'positive lr')                                  || ...
        strcmp(alg, 'positive likelihood r')                        || ...
        strcmp(alg, 'positive likelihood ratio'))
    
    % Positive likelihood ratio
    score = ...
        positive_likelihood_ratio(TP, FN, perc);
    
elseif (strcmp(alg, 'ppv')                                          || ...
        strcmp(alg, 'positive pv')                                  || ...
        strcmp(alg, 'positive predictive v')                        || ...
        strcmp(alg, 'positive predictive value'))
    
    % Positive predictive value
    score = ...
        positive_predictive_value(TP, FP, perc);
else
    error(['Classification score ' alg ' is not supported.']);
end