from __future__ import division
import pandas as pd
import sys, argparse, os


# input arguments
parser = argparse.ArgumentParser(description="this script is to calculate reproducibility between Quartet_D5 and Quartet_D6s")

parser.add_argument('-sister', '--sister', type=str, help='sister.txt',  required=True)
parser.add_argument('-project', '--project', type=str, help='project name',  required=True)


args = parser.parse_args()
sister_file = args.sister
project_name = args.project

# output file
output_name = project_name + '.sister.reproducibility.txt'

output_file = open(output_name,'w')

# input files
sister_dat = pd.read_table(sister_file)

sister_same = 0
sister_diff = 0

for row in sister_dat.itertuples():
	# sister
	if row[5] == row[6]:
		if row[5] == './.':
			mendelian = 'noInfo'
			sister_count = "no"
		elif row[5] == '0/0':
			mendelian = 'Ref'
			sister_count = "no"
		else:
			mendelian = '1'
			sister_count = "yes_same"
	else:
		mendelian = '0'
		if (row[5] == './.' or row[5] == '0/0') and (row[6] == './.' or row[6] == '0/0'):
			sister_count = "no"
		else:
			sister_count = "yes_diff"
	if sister_count == 'yes_same':
		sister_same += 1
	elif sister_count == 'yes_diff':
		sister_diff += 1
	else:
		pass

sister = sister_same/(sister_same + sister_diff)
outcolumn =  'Project\tReproducibility_D5_D6\n'
outResult = project_name + '\t' + str(sister)  + '\n'
output_file.write(outcolumn)
output_file.write(outResult)



