-
Notifications
You must be signed in to change notification settings - Fork 53
/
BLEvaluator.py
162 lines (122 loc) · 5.54 KB
/
BLEvaluator.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python
# coding: utf-8
import os
import yaml
import argparse
import itertools
import numpy as np
import pandas as pd
import networkx as nx
from tqdm import tqdm
import multiprocessing
from pathlib import Path
import concurrent.futures
from itertools import permutations
from collections import defaultdict
from multiprocessing import Pool, cpu_count
from networkx.convert_matrix import from_pandas_adjacency
# local imports
import BLEval as ev
def get_parser() -> argparse.ArgumentParser:
'''
:return: an argparse ArgumentParser object for parsing command
line parameters
'''
parser = argparse.ArgumentParser(
description='Run pathway reconstruction pipeline.')
parser.add_argument('-c','--config', default='config.yaml',
help="Configuration file containing list of datasets "
"algorithms and output specifications.\n")
parser.add_argument('-a', '--auc', action="store_true", default=False,
help="Compute median of areas under Precision-Recall and ROC curves.\n")
parser.add_argument('-j', '--jaccard', action="store_true", default=False,
help="Compute median Jaccard index of predicted top-k networks "
"for each algorithm for a given set of datasets generated "
"from the same ground truth network.\n")
parser.add_argument('-r', '--spearman', action="store_true", default=False,
help="Compute median Spearman Corr. of predicted edges "
"for each algorithm for a given set of datasets generated "
" from the same ground truth network.\n")
parser.add_argument('-t', '--time', action="store_true", default=False,
help="Analyze time taken by each algorithm for a.\n")
parser.add_argument('-e', '--epr', action="store_true", default=False,
help="Compute median early precision.")
parser.add_argument('-s','--sepr', action="store_true", default=False,
help="Analyze median (signed) early precision for activation and inhibitory edges.")
parser.add_argument('-m','--motifs', action="store_true", default=False,
help="Compute network motifs in the predicted top-k networks.")
parser.add_argument('-p','--paths', action="store_true", default=False,
help="Compute path length statistics on the predicted top-k networks.")
parser.add_argument('-b','--borda', action="store_true", default=False,
help="Compute edge ranked list using the various Borda aggregatio methods.")
return parser
def parse_arguments():
'''
Initialize a parser and use it to parse the command line arguments
:return: parsed dictionary of command line arguments
'''
parser = get_parser()
opts = parser.parse_args()
return opts
def main():
opts = parse_arguments()
config_file = opts.config
evalConfig = None
with open(config_file, 'r') as conf:
evalConfig = ev.ConfigParser.parse(conf)
print('\nPost-run evaluation started...')
evalSummarizer = ev.BLEval(evalConfig.input_settings, evalConfig.output_settings)
outDir = str(evalSummarizer.output_settings.base_dir) + \
str(evalSummarizer.input_settings.datadir).split("inputs")[1] + "/"+\
str(evalSummarizer.output_settings.output_prefix) + "-"
# Compute and plot ROC, PRC and report median AUROC, AUPRC
if (opts.auc):
print('\n\nComputing areas under ROC and PR curves...')
AUPRC, AUROC = evalSummarizer.computeAUC()
AUPRC.to_csv(outDir+'AUPRC.csv')
AUROC.to_csv(outDir+'AUROC.csv')
# Compute Jaccard index
if (opts.jaccard):
print('\n\nComputing Jaccard index...')
jaccDict = evalSummarizer.computeJaccard()
jaccDict.to_csv(outDir + "Jaccard.csv")
# Compute Spearman correlation scores
if (opts.spearman):
print('\n\nComputing Spearman\'s correlation...')
corrDict = evalSummarizer.computeSpearman()
corrDict.to_csv(outDir + "Spearman.csv")
# Compute median time taken
if (opts.time):
print('\n\nComputing time taken...')
TimeDict = evalSummarizer.parseTime()
pd.DataFrame(TimeDict).to_csv(outDir+'Times.csv')
# Compute early precision
if (opts.epr):
print('\n\nComputing early precision values...')
ePRDF = evalSummarizer.computeEarlyPrec()
ePRDF.to_csv(outDir + "EPr.csv")
# Compute early precision for activation and inhibitory edges
if (opts.sepr):
print('\n\nComputing early precision values for activation and inhibitory edges...')
actDF, inhDF = evalSummarizer.computeSignedEPrec()
actDF.to_csv(outDir + "EPr-Activation.csv")
inhDF.to_csv(outDir + "EPr-Inhibitory.csv")
# Compute median time taken
if (opts.motifs):
print('\n\nComputing network motifs...')
FBL, FFL, MI = evalSummarizer.computeNetMotifs()
FBL.to_csv(outDir+'NetworkMotifs-FBL.csv')
FFL.to_csv(outDir+'NetworkMotifs-FFL.csv')
MI.to_csv(outDir+'NetworkMotifs-MI.csv')
# Compute path statistics such as number of TP, FP,
# and path lengths among TP in the top-k networks.
if (opts.paths):
print('\n\nComputing path length statistics on predicted networks...')
evalSummarizer.computePaths()
# Compute edge ranked list using the borda method
if (opts.borda):
print('\n\nComputing edge ranked list using the borda method')
evalSummarizer.computeBorda()
print('\n\nEvaluation complete...\n')
if __name__ == '__main__':
main()