import argparse
import os
import numpy as np
import pandas as pd 
from sklearn.metrics import precision_score, \
							recall_score, classification_report,\
							confusion_matrix,\
							precision_recall_fscore_support,\
							mean_squared_error

def precrecall(ref, pred):
	uniq_label = np.unique(ref).astype(int)	
	p, r, f1, s = precision_recall_fscore_support(ref, pred, labels=uniq_label)
	print('precision=%.6f'%(np.average(p, weights=s)*100))
	print('recall=%.6f'%(np.average(r, weights=s)*100))

parser = argparse.ArgumentParser()
parser.add_argument('-d', nargs=1)
parser.add_argument('--test_dir', nargs=1)
parser.add_argument('--pred_dir', nargs=1)
args = parser.parse_args()
DB = args.d[0]
pred_dir = args.pred_dir[0]
test_dir = args.test_dir[0]

predfile = os.path.join(pred_dir, "test.fragments.%s-db.preds.taxid"%(DB))
reffile = os.path.join(test_dir, "%s.test.taxid"%(DB))
with open(predfile, "r") as fin:
	pred = fin.read().splitlines()
with open(reffile, "r") as fin:
	ref = fin.read().splitlines()

pred = list(map(int, pred))
ref = list(map(int, ref)) 

precrecall(ref, pred)