#searches for primer list by number, sequence, and description

#read in csv file 
def make_primer_dictionaries():
	import csv
	cr = csv.reader(open("compiled_info_primer.txt", "rb"))

	#make dictionaries to store csv file
	description = {}
	sequence = {}
	for row in cr:
		str_id = str(row[0])
		description[str_id] = row[1].lower()
		sequence[str_id] = row[2].lower()
    #print description
    #print sequence
	return [description, sequence]

#search based on id only
def id_search(input, dict1, dict2):
	if input in dict1:
		if dict2[input] != "":
			return [dict1[input], dict2[input]]
		else:
			return [dict1[input], "no sequence"]
	else:
		return False

#search based on sequence substring only
def substr_search(input, dict1, dict2):
	new = []
	for key in dict2:
		if input in dict2[key]:
			if dict1[key] != "":
				temporary = [key, dict1[key], dict2[key]]
				new.append(temporary)
			else:
				temporary = [key, "no description", dict2[key]]
				new.append(temporary)
	if not new:
		return False
	else:
		return new

#search based on description substring only
def desc_search(input, dict1, dict2): #want to return all the searches
	new = []
	for key in dict1:
		#note that input must be lower case, input is a string
		#print key
		#print input
		#print dict1[key]
		if input in dict1[key]:
			#print dict1[key]
			if dict2[key] != "":
				temporary = [key, dict1[key], dict2[key]]
				new.append(temporary)
			else:
				temporary = [key, dict1[key], "no sequence"]
				new.append(temporary)
	if not new:
		return False
	else:
		return new

#combination searches. id is unique so not combo search there. desc + seq substrings is a combo search
def combo(input1, input2, dict1,dict2):
	desc = desc_search(input1, dict1, dict2) 
	seq = substr_search(input2, dict1, dict2)

	if desc== False and seq == False:
		return False
	if desc == False: #if one of the lists (query) is empty
		return [seq, "seq"]
	if seq == False: #if one of the lists (query) is empty
		return [desc, "desc"] # this is a marker for later, know which one the information came from
	new = [] #compare the two lists for overlap
	for item in desc:
		for value in seq:
			if value[0] == item[0]:
				temporary = value
				new.append(temporary)
	if not new: #if there is no overlap
		return False
	else:	#if there is some overlap
		return new

if __name__ == '__main__':
    temp = combo("pspomi", "tttcct", description, sequence)     #note that the input must have ".0"
    print temp