import sys
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from Bio.Alphabet import generic_dna
from Bio import SeqIO
import numpy
import math
import itertools as it

MATERNALFASTAFILENAMELISTFILENAME = sys.argv[1]
PATERNALFASTAFILENAMELISTFILENAME = sys.argv[2]
PEAKHEIGHTFILENAME = sys.argv[3]
VALUEFILENAME = sys.argv[4]
OUTPUTFILENAME = sys.argv[5]
K = int(sys.argv[6])
WINDOWSIZE = int(sys.argv[7])
WINDOWSTRIDE = int(sys.argv[8])


def makeSequenceList():
	# Make a list of groups of 4 bases
	sequenceDict = {}
	baseList = ["A", "C", "G", "T"]
	sequenceList = []
	allSameList = []

	for baseOne in baseList:
		# Iterate through the first base options
		for baseTwo in baseList:
			# Iterate through the second base options
			for baseThree in baseList:
				# Iterate through the third base options
				for baseFour in baseList:
					# Iterate through the fourth base options
					currentSequence = baseOne + baseTwo + baseThree + baseFour
					sequenceList.append(currentSequence)
					if ((baseOne + baseTwo == baseThree + baseFour) or (baseOne + baseTwo == baseFour + baseThree)) or ((baseTwo + baseOne == baseThree + baseFour) or (baseTwo + baseOne == baseFour + baseThree)):
						# The individuals are the same at the current base
						allSameList.append(1)
					else:
						# The individuals are not the same at the current base
						allSameList.append(0)
	return [sequenceList, allSameList]


def makeSequenceDict():
	# Make a dictionary that maps groups of 4 bases to numbers
	sequenceDict = {}
	baseList = ["A", "C", "G", "T"]
	count = 0

	for baseOne in baseList:
		# Iterate through the first base options
		for baseTwo in baseList:
			# Iterate through the second base options
			for baseThree in baseList:
				# Iterate through the third base options
				for baseFour in baseList:
					# Iterate through the fourth base options
					currentSequence = baseOne + baseTwo + baseThree + baseFour
					sequenceDict[currentSequence] = count
					count = count + 1
	return sequenceDict


def makeKMerList(k):
	# Make a list of all k-mers, where each base is a group of 4 bases signifying different allele combinations
	# IF k > 1, do not include groups for which both individuals are the same
	# For example, CCCG and CCGG would be included, but CCCC and CGCG would not
	if k == 1:
		# There is only one base, so returen the sequence list for 1-mers
		return makeSequenceList()
	baseList = ["A", "C", "G", "T"]
	kMerList = []
	allSameList = []
	[kMinusOneMerList, allSameMinusOneList] = makeKMerList(k- 1)

	for baseOne in baseList:
		# Iterate through the first base options
		for baseTwo in baseList: