Package: cafaeval
CAFA-evaluatorCAFA-evaluator is a Python program designed to evaluate the performance of prediction methods on targets
with hierarchical concept dependencies.
It generalizes multi-label evaluation to modern ontologies where the prediction targets are drawn
from a directed acyclic graph and achieves high efficiency by leveraging matrix computation and topological sorting.The code replicates theCritical Assessment of protein Function Annotation (CAFA)benchmarking,
which evaluates predictions of the consistent subgraphs inGene Ontology.
The package also contains aJupyter Notebookto generate precision-recall and remaining uncertainty–misinformation curves.
CAFA-evaluator implementation was inspired by the original Matlab code used in CAFA2 assessment and available athttps://github.com/yuxjiang/CAFA2.Visit our Wiki for more information about theCAFA-evaluator algorithm.InstallationYou can use the tool simply cloning this repo and running__main__.pyPython script.
which implements a command line interface.
To avoid import errors you need to add the source root folder
to thePYTHONPATHenvironment variable. For example:export PYTHONPATH=/path/to/CAFA-evaluator/src:$PYTHONPATHAlternatively, you can install the package with Pip. No need to export any variable
in this case.From GitHub:git clone https://github.com/BioComputingUP/CAFA-evaluator.git  
pip install .From PyPI:pip install cafaevalUsageThe program can be executing the command line interface or as a library.
Both the command line and the library accept the following positional arguments:Ontology filein OBO formatPrediction foldercontain prediction files. Files can be organized into sub-folders,
sub-folders are processed recursively and the sub-folder name is used as prefix for the method nameGround truth filecontaining targets and associated ontology termsExample input files are provided inside thedata/examplefolder. If you have installed the software using pip,
the folder is located in the Pythonsite-packagesdirectory.Command lineWhen executed from the command line the script logs information about the calculation in the console (standard error) and
will create a folder namedresultscontaining the evaluation results.
A different folder can be specified using the-out_diroption.The following options are available:
When installed with pip the script is available ascafaevalcommand.cafaeval ontology_file prediction_folder ground_truth_fileIf you simply cloned the repository:python3 /path/to/CAFA-evaluator/src/cafaeval/__main__.py ontology_file prediction_folder ground_truth_fileLibraryThecafa_evalfunction is the main entry point of the package.
Below is reported an example using the example files provided in thedata/examplefolder.>>>importcafaeval>>>fromcafaeval.evaluationimportcafa_eval>>>cafa_eval("IDPO_disorder_function.obo","predictions","ground_truth.tsv")(                                       n        tp        fp        fn        pr  ...         f         s  pr_micro  rc_micro   f_microfilename   ns                tau                                                  ...pred_5.tsv disorder_function 0.01  168.0  2.928571  7.083333  0.130952  0.292532  ...  0.448380  7.084544  0.292509  0.957198  0.4480870.02  168.0  2.928571  7.083333  0.130952  0.292532  ...  0.448380  7.084544  0.292509  0.957198  0.4480870.03  168.0  2.928571  7.077381  0.130952  0.292695  ...  0.448571  7.078592  0.292683  0.957198  0.4482920.04  168.0  2.928571  7.077381  0.130952  0.292695  ...  0.448571  7.078592  0.292683  0.957198  0.4482920.05  168.0  2.928571  7.077381  0.130952  0.292695  ...  0.448571  7.078592  0.292683  0.957198  0.448292...                                  ...       ...       ...       ...       ...  ...       ...       ...       ...       ...       ...pred_1.tsv disorder_function 0.41    1.0  0.005952  0.017857  3.053571  0.250000  ...  0.003937  3.053624  0.250000  0.001946  0.0038610.42    1.0  0.005952  0.017857  3.053571  0.250000  ...  0.003937  3.053624  0.250000  0.001946  0.0038610.43    1.0  0.005952  0.017857  3.053571  0.250000  ...  0.003937  3.053624  0.250000  0.001946  0.0038610.44    1.0  0.005952  0.017857  3.053571  0.250000  ...  0.003937  3.053624  0.250000  0.001946  0.0038610.45    1.0  0.005952  0.011905  3.053571  0.333333  ...  0.003945  3.053595  0.333333  0.001946  0.003868[352 rows x 14 columns], {'f':                                        n        tp        fp        fn        pr  ...         s  pr_micro  rc_micro   f_micro  cov_maxfilename   ns                tau                                                  ...pred_1.tsv disorder_function 0.04  166.0  1.744048  2.095238  1.315476  0.466566  ...  2.473964  0.454264  0.570039  0.505608      1.0pred_2.tsv disorder_function 0.84  163.0  1.755952  1.845238  1.303571  0.504499  ...  2.259248  0.487603  0.573930  0.527256      1.0pred_3.tsv disorder_function 0.89  168.0  2.113095  1.601190  0.946429  0.638889  ...  1.859983  0.568910  0.690661  0.623902      1.0pred_4.tsv disorder_function 0.06  168.0  2.333333  0.666667  0.726190  0.777778  ...  0.985798  0.777778  0.762646  0.770138      1.0pred_5.tsv disorder_function 0.38  167.0  2.345238  1.952381  0.714286  0.596671  ...  2.078941  0.545706  0.766537  0.637540      1.0[5 rows x 15 columns], 's':                                        n        tp        fp        fn        pr  ...         s  pr_micro  rc_micro   f_micro  cov_maxfilename   ns                tau                                                  ...pred_1.tsv disorder_function 0.06  102.0  1.047619  0.297619  2.011905  0.816667  ...  2.033799  0.778761  0.342412  0.475676      1.0pred_2.tsv disorder_function 0.91  124.0  1.196429  0.839286  1.863095  0.638978  ...  2.043410  0.587719  0.391051  0.469626      1.0pred_3.tsv disorder_function 0.89  168.0  2.113095  1.601190  0.946429  0.638889  ...  1.859983  0.568910  0.690661  0.623902      1.0pred_4.tsv disorder_function 0.06  168.0  2.333333  0.666667  0.726190  0.777778  ...  0.985798  0.777778  0.762646  0.770138      1.0pred_5.tsv disorder_function 0.42  156.0  1.642857  0.714286  1.416667  0.776221  ...  1.586552  0.696970  0.536965  0.606593      1.0[5 rows x 15 columns], 'f_micro':                                        n        tp        fp        fn        pr  ...         s  pr_micro  rc_micro   f_micro  cov_maxfilename   ns                tau                                                  ...pred_1.tsv disorder_function 0.04  166.0  1.744048  2.095238  1.315476  0.466566  ...  2.473964  0.454264  0.570039  0.505608      1.0pred_2.tsv disorder_function 0.84  163.0  1.755952  1.845238  1.303571  0.504499  ...  2.259248  0.487603  0.573930  0.527256      1.0pred_3.tsv disorder_function 0.89  168.0  2.113095  1.601190  0.946429  0.638889  ...  1.859983  0.568910  0.690661  0.623902      1.0pred_4.tsv disorder_function 0.06  168.0  2.333333  0.666667  0.726190  0.777778  ...  0.985798  0.777778  0.762646  0.770138      1.0pred_5.tsv disorder_function 0.38  167.0  2.345238  1.952381  0.714286  0.596671  ...  2.078941  0.545706  0.766537  0.637540      1.0[5 rows x 15 columns]})The output ofcafa_evalis a tuple containing:A pandas DataFrame with the evaluation results, one row per prediction file, namespace and threshold.A dictionary with the best scores (max F-measure, max Weighted F-measure, min Semantic similarity). For each
score the dictionary contain a pandas DataFrame with one row per prediction file, namespace and threshold.Thewrite_resultsfunction generates the output files.>>>importcafaeval>>>fromcafaeval.evaluationimportcafa_eval,write_results>>>res=cafa_eval("IDPO_disorder_function.obo","predictions","ground_truth.tsv")>>>write_results(*res)Input filesPrediction file- Tab separated file with the target ID, term ID and score columns.T_1	IDPO:00501	0.06
T_1	IDPO:00506	0.05
T_1	IDPO:00507	0.03
T_2	IDPO:00501	0.04
T_2	IDPO:00506	0.02
...Ground truth file- Tab separated file with the target ID and term ID.
Additional columns are discarded.T_1	IDPO:00024
T_2	IDPO:00506
T_3	IDPO:00502
T_4	IDPO:00025
...Information accretion file (optional)- If not provided, the weighted and S statistics are not generated.
Information accretion (IA) can be calculated as described inWyatt and Radivojac, Bioinformatics, 2013.IDPO:00024  6.32
IDPO:00506  12.04
IDPO:00502  1.34
IDPO:00025  0.56
...Output filesOutput files are generated in theresultsfolder. The same files are gerated by both
the command line and thewrite_resultsfunction.evaluation_all.tsvcorresponds to the first object returned by thecafa_evalfunction.evaluation_best_< metric >.tsvcorresponds to the second object returned by thecafa_evalfunction.
A different file for each metric is created.Note: Weighted scores are generated only if theInformation Accretionfile is provided.Optional parametersArgumentDefault valueDescription-out_dir'results'Output directory (tsv files + log). Either relative to current path or absolute-iaInformation accretion file-no_orphansFalse (flag)Exclude orphans nodes (e.g. roots) from the calculation-norm'cafa'Normalization strategy.cafanormalize precision by the number of predicted targets and recall by the number of targets in the ground truth.prednormalize by the number of  predicted targets.gtnormalize by the number of ground truth proteins-prop'max'Ancestor propagation strategy.maxpropagate the max score of the traversed subgraph iteratively.fillpropagate with max until a different score is found-th_step0.01Step size of prediction score thresholds to consider in the range [0, 1). A smaller step, means more calculation-max_termsNumber of terms for protein and namespace to consider in the evaluation. Parsing stops when the target limit for every namespace is reached. The score is not checked, meaning that terms are not sorted before the check, and the check is performed before propagation.-threads4Parallel threads.0means use all available CPU threads. Do not use multi thread if you are short in memoryPlottingPlots are generated by running all the cells in theplot.ipynbJupyter Notebook.
In order to generate the figures you need to manually modify the first cell of the notebook which
contains a few parameters:the path to the input file generated in the evaluationevaluation_all.tsv, seeUsageabove.the output folderthe metric (F-score, weighted F-score, S measure).an optional file including information about methods aliases and groups. If provided, the results
are presented selecting only one method per group. The file should look like:filename	group	label
pred_1.tsv	BioLab	BioLab_model_1
pred_2.tsv	BioLab	BioLab_model_2
pred_3.tsv	JohnLab	JohnLab_model_1The notebook generates the following files:fig_< metric >_< name_space >.pngA figure for each namespace in the dataframe and the selected metric.
The notebook generates one metric at the time, you have to modify the input cell to generate the plots for a different metricfig_< metric >.tsvA file with the data points for the metric curves. One curve for each method.group	label	ns	tau	cov	wrc	wpr	wf
INGA	INGA_1	biological_process	0.010	0.993	0.557	0.094	0.160
INGA	INGA_1	biological_process	0.020	0.993	0.555	0.094	0.161
INGA	INGA_1	biological_process	0.030	0.993	0.552	0.095	0.162
INGA	INGA_1	biological_process	0.040	0.993	0.551	0.095	0.163