# Author Qi Li (qli8@nd.edu) #
## main program ##
import pandas as pd 
import numpy as np 
import random
from collections import defaultdict
from collections import Counter
from scipy.stats import hypergeom
import json
import sys
import math
import argparse 
import os

## IMPORT PIECE PY CODE ##
import NetProperty as NetP
import ClusterValidation as cv 

## COMMAND LINE ARGS 
parser = argparse.ArgumentParser()

## input data filenames 
parser.add_argument("-in", "--input network filename", dest = 'fn1', type = str)

parser.add_argument("-o", "--output filename names", dest = 'outName', type = str)

parser.add_argument("-ic", "--input clustering filename", dest = 'fn2', type = str)

parser.add_argument("-ig", "--input GO term filename", dest = 'fn3', type = str)

parser.add_argument("-m", "--input Minimum Cluster/GO Size", dest = 'm', type = int)

parser.add_argument("-a", "--input alpha value", dest = 'a', type = float)

parser.add_argument("-d", "--output directory path", dest = 'd', type = str)
#parsethearguments
args=parser.parse_args()

## output all files into one folder ##
dir_path = os.getcwd()
out = dir_path + '/' + args.d
if not os.path.exists(out):
	os.makedirs(out)

#### Part 1 ####

## Network Properties and degrees ##
NetP.NetPro(args.fn1, args.outName, out)

NetP.NetDeg(args.fn1, args.outName, out)

### Part 2 ###
## Read in Cluster, GO and nodelist file ###
clu_dic, gene_list, dic1_go, dic2_go, GO_term, GeneID_common, clu_dic1, gene_go_dic, gene_clu_dic = cv.CluGO(args.fn1, args.fn2, args.outName, out, args.fn3, args.m)

pval = cv.Pval(clu_dic1, dic2_go, len(GeneID_common), GO_term, args.a)

cv.Print(pval, args.a, args.m, out, args.outName, clu_dic, clu_dic1, GO_term, dic2_go, gene_list)

### Part 3 LOO prediction ###
cv.LOO(out, args.outName, args.a, gene_list, GeneID_common, gene_clu_dic, dic2_go, clu_dic1)

print ("---------------> Finished one process here <---------------")
