'''
A few of the sequences generated by running convertData.py and
makeDataUniform.py were of inappropriate length.  Since only a
small number of data points appear to be bad, this program is
run to remove them.
'''

def fix(in_file, out_file):
	data = readData(in_file)
	conditionalWrite(out_file, data)

def readData(handle):
	f = open(handle)
	data = list(f)
	f.close()
	return data

def conditionalWrite(handle, data):
	f = open(handle, 'w')
	for seq in data:
		# use LENGTH+2 to account for space 
		# and end line in txt file 
		if len(seq) == LENGTH+2: f.write(seq)
	f.close()

LENGTH = 1515

# input and label dirs
hmmTrainData_dir = '../data/training/hmm/'
manTrainData_dir = '../data/training/manual/'

# open formatted input files
fix(hmmTrainData_dir + 'input_some_bad.txt', hmmTrainData_dir + 'input.txt')
fix(hmmTrainData_dir + 'labels_some_bad.txt', hmmTrainData_dir + 'labels.txt')
fix(manTrainData_dir + 'input_some_bad.txt', manTrainData_dir + 'input.txt')
fix(manTrainData_dir + 'labels_some_bad.txt', manTrainData_dir + 'labels.txt')

