metrics.py
def metrics(bcftools_vcf_file, vcf_files):
    """ Prints precision, recall, F1 score, accuracy, MCC score and 
    confusion matrix for each VCF file. Plots precision, recall, F1 score,
    accuracy and MCC score against probabilities. 
    
    Parameters
    ----------
    bfctools_vcf_file: str
        path to VCF file created by bfctools call tool
    vcf_files: list of str
        paths to VCF files created by our algorithm with different 
        probabilities
        
    """  
    
    p = []
    
    for vcf_file in vcf_files:
        info = vcf_file.split('.')
        p.append(float(info[2]) / 100)
    
    TP = []
    FP = []
    FN = []
    TN = []
    precision_list = []
    recall_list = []
    f1_score_list = []
    accuracy_list = []
    mcc_list = []
    predicted_variants = []
    true_variants = []
    
    for vcf_file in vcf_files:
        tp, fp, fn, tn = get_statistics(bcftools_vcf_file, vcf_file)
        TP.append(tp)
        FP.append(fp)
        FN.append(fn)
        TN.append(tn)
        predicted_variants.append(tp + fp)
        true_variants.append(tp + fn)
        precision_list.append(precision(tp, fp, fn))
        recall_list.append(recall(tp, fp, fn))
        f1_score_list.append(f1_score(tp, fp, fn))
        accuracy_list.append(accuracy(tp, fp, fn, tn))
        mcc_list.append(mcc(tp, fp, fn, tn))
       
    for i in range(len(vcf_files)):
        print('Probability: {}'.format(p[i]))
        print('Precision: {}'.format(precision_list[i]))
        print('Recall: {}'.format(recall_list[i]))
        print('F1 score: {}'.format(f1_score_list[i]))
        print('Accuracy: {}'.format(accuracy_list[i]))
        print('MCC score: {}'.format(mcc_list[i]))
        print('')
        
        confusion_matrix = np.array([[TN[i], FP[i]],[FN[i], TP[i]]])
        df_cm = pd.DataFrame(confusion_matrix, range(2), range(2))
        plt.figure(i)
        sn.set(font_scale=1.4)
        ax = sn.heatmap(df_cm, annot=True, annot_kws={"size": 16}, fmt="d", cmap="YlGnBu")
        
        ax.set(xlabel='Predicted', ylabel='True')

        plt.show() 
    
    plt.figure('Metrics')
    plt.title('Metrics')
    plt.xlabel('Probability')
    plt.ylabel('Metrics')
    plt.plot(p, precision_list, label = 'Precision')
    plt.plot(p, recall_list, label = 'Recall')
    plt.plot(p, f1_score_list, label = 'F1 score')
    plt.plot(p, accuracy_list, label = 'Accuracy')
    plt.plot(p, mcc_list, label = 'MCC score')
    plt.legend(loc = 'lower left')
    plt.show()
    
    plt.figure('Variants')
    plt.title('Variants')
    plt.xlabel('Probability')
    plt.ylabel('Number of variants')
    plt.plot(p, predicted_variants, label = 'Predicted variants')
    plt.plot(p, true_variants, label = 'True variants')
    plt.legend(loc = 'lower right')
    plt.show()
 Prints precision, recall, F1 score, accuracy, MCC score and 
    confusion matrix for each VCF file. Plots precision, recall, F1 score,
    accuracy and MCC score against probabilities. 
    
    Parameters
    ----------
    bfctools_vcf_file: str
        path to VCF file created by bfctools call tool
    vcf_files: list of str
        paths to VCF files created by our algorithm with different 
        probabilities
        
    
Prints precision, recall, F1 score, accuracy, MCC score and
confusion matrix for each VCF file. Plots precision, recall, F1 score,
accuracy and MCC score against probabilities.

Parameters

str
path to VCF file created by bfctools call tool
vcf_files: list of str
paths to VCF files created by our algorithm with different
probabilities
Prints precision recall F1 score accuracy MCC score and confusion matrix for each VCF file . Plots precision recall F1 score accuracy and MCC score against probabilities . Parameters str path to VCF file created by bfctools call tool vcf_files : list of str paths to VCF files created by our algorithm with different probabilities
def metrics(bcftools_vcf_file, vcf_files):
    p = []
    for vcf_file in vcf_files:
        info = vcf_file.split('.')
        p.append(float(info[2]) / 100)
    TP = []
    FP = []
    FN = []
    TN = []
    precision_list = []
    recall_list = []
    f1_score_list = []
    accuracy_list = []
    mcc_list = []
    predicted_variants = []
    true_variants = []
    for vcf_file in vcf_files:
        tp, fp, fn, tn = get_statistics(bcftools_vcf_file, vcf_file)
        TP.append(tp)
        FP.append(fp)
        FN.append(fn)
        TN.append(tn)
        predicted_variants.append(tp + fp)
        true_variants.append(tp + fn)
        precision_list.append(precision(tp, fp, fn))
        recall_list.append(recall(tp, fp, fn))
        f1_score_list.append(f1_score(tp, fp, fn))
        accuracy_list.append(accuracy(tp, fp, fn, tn))
        mcc_list.append(mcc(tp, fp, fn, tn))
    for i in range(len(vcf_files)):
        print('Probability: {}'.format(p[i]))
        print('Precision: {}'.format(precision_list[i]))
        print('Recall: {}'.format(recall_list[i]))
        print('F1 score: {}'.format(f1_score_list[i]))
        print('Accuracy: {}'.format(accuracy_list[i]))
        print('MCC score: {}'.format(mcc_list[i]))
        print('')
        confusion_matrix = np.array([[TN[i], FP[i]],[FN[i], TP[i]]])
        df_cm = pd.DataFrame(confusion_matrix, range(2), range(2))
        plt.figure(i)
        sn.set(font_scale=1.4)
        ax = sn.heatmap(df_cm, annot=True, annot_kws={"size": 16}, fmt="d", cmap="YlGnBu")
        ax.set(xlabel='Predicted', ylabel='True')
        plt.show() 
    plt.figure('Metrics')
    plt.title('Metrics')
    plt.xlabel('Probability')
    plt.ylabel('Metrics')
    plt.plot(p, precision_list, label = 'Precision')
    plt.plot(p, recall_list, label = 'Recall')
    plt.plot(p, f1_score_list, label = 'F1 score')
    plt.plot(p, accuracy_list, label = 'Accuracy')
    plt.plot(p, mcc_list, label = 'MCC score')
    plt.legend(loc = 'lower left')
    plt.show()
    plt.figure('Variants')
    plt.title('Variants')
    plt.xlabel('Probability')
    plt.ylabel('Number of variants')
    plt.plot(p, predicted_variants, label = 'Predicted variants')
    plt.plot(p, true_variants, label = 'True variants')
    plt.legend(loc = 'lower right')
    plt.show()
def metrics ( bcftools_vcf_file , vcf_files ) : p = [ ] for vcf_file in vcf_files : info = vcf_file . split ( '.' ) p . append ( float ( info [ 2 ] ) / 100 ) TP = [ ] FP = [ ] FN = [ ] TN = [ ] precision_list = [ ] recall_list = [ ] f1_score_list = [ ] accuracy_list = [ ] mcc_list = [ ] predicted_variants = [ ] true_variants = [ ] for vcf_file in vcf_files : tp , fp , fn , tn = get_statistics ( bcftools_vcf_file , vcf_file ) TP . append ( tp ) FP . append ( fp ) FN . append ( fn ) TN . append ( tn ) predicted_variants . append ( tp + fp ) true_variants . append ( tp + fn ) precision_list . append ( precision ( tp , fp , fn ) ) recall_list . append ( recall ( tp , fp , fn ) ) f1_score_list . append ( f1_score ( tp , fp , fn ) ) accuracy_list . append ( accuracy ( tp , fp , fn , tn ) ) mcc_list . append ( mcc ( tp , fp , fn , tn ) ) for i in range ( len ( vcf_files ) ) : print ( 'Probability: {}' . format ( p [ i ] ) ) print ( 'Precision: {}' . format ( precision_list [ i ] ) ) print ( 'Recall: {}' . format ( recall_list [ i ] ) ) print ( 'F1 score: {}' . format ( f1_score_list [ i ] ) ) print ( 'Accuracy: {}' . format ( accuracy_list [ i ] ) ) print ( 'MCC score: {}' . format ( mcc_list [ i ] ) ) print ( '' ) confusion_matrix = np . array ( [ [ TN [ i ] , FP [ i ] ] , [ FN [ i ] , TP [ i ] ] ] ) df_cm = pd . DataFrame ( confusion_matrix , range ( 2 ) , range ( 2 ) ) plt . figure ( i ) sn . set ( font_scale = 1.4 ) ax = sn . heatmap ( df_cm , annot = True , annot_kws = { "size" : 16 } , fmt = "d" , cmap = "YlGnBu" ) ax . set ( xlabel = 'Predicted' , ylabel = 'True' ) plt . show ( ) plt . figure ( 'Metrics' ) plt . title ( 'Metrics' ) plt . xlabel ( 'Probability' ) plt . ylabel ( 'Metrics' ) plt . plot ( p , precision_list , label = 'Precision' ) plt . plot ( p , recall_list , label = 'Recall' ) plt . plot ( p , f1_score_list , label = 'F1 score' ) plt . plot ( p , accuracy_list , label = 'Accuracy' ) plt . plot ( p , mcc_list , label = 'MCC score' ) plt . legend ( loc = 'lower left' ) plt . show ( ) plt . figure ( 'Variants' ) plt . title ( 'Variants' ) plt . xlabel ( 'Probability' ) plt . ylabel ( 'Number of variants' ) plt . plot ( p , predicted_variants , label = 'Predicted variants' ) plt . plot ( p , true_variants , label = 'True variants' ) plt . legend ( loc = 'lower right' ) plt . show ( )
Prints precision, recall, F1 score, accuracy, MCC score and
confusion matrix for each VCF file.
Prints precision recall F1 score accuracy MCC score and confusion matrix for each VCF file .
""" Prints precision, recall, F1 score, accuracy, MCC score and 
    confusion matrix for each VCF file. Plots precision, recall, F1 score,
    accuracy and MCC score against probabilities. 
    
    Parameters
    ----------
    bfctools_vcf_file: str
        path to VCF file created by bfctools call tool
    vcf_files: list of str
        paths to VCF files created by our algorithm with different 
        probabilities
        
    """
bcftools_vcf_file
vcf_files