-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaf_f1score
executable file
·30 lines (26 loc) · 992 Bytes
/
maf_f1score
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
#!/usr/bin/env python
"""
Parse out an F1 score from a mafComparator XML file.
"""
from bs4 import BeautifulSoup
from argparse import ArgumentParser
def get_f1(soup):
precision = float(soup.alignmentcomparisons.find_all("homologytests")[0].aggregateresults.all.get('average'))
recall = float(soup.alignmentcomparisons.find_all("homologytests")[1].aggregateresults.all.get('average'))
return 2 * (precision * recall) / (precision + recall)
def parse_args():
parser = ArgumentParser(description=__doc__)
parser.add_argument('xmls', help='mafComparator XML output file(s)', nargs='+')
return parser.parse_args()
def main():
opts = parse_args()
if len(opts.xmls) == 1:
# Only one file given: just print out the F1 score and nothing else.
with open(opts.xmls[0]) as f:
soup = BeautifulSoup(f, 'html.parser')
print get_f1(soup)
else:
# Multiple files given.
pass
if __name__ == '__main__':
main()