def get_samples_by_pop(d, admix, p1, p2):
	"""
	Finds samples associated with each of the three user-specified populations:
	Input:
		d: popmap dictionary {indids: popids}.
		admix: admixed population string specified by user at command-line.
		p1: p1 population string specified by user at command-line.
		p2: p2 population string specified by user at command-line.
	Returns:
		popdict: dictionary {'Admixed': [inds], 'P1': [inds], 'P2': [inds]}
	"""
	popdict = dict()
	admix_inds = list()
	p1_inds = list()
	p2_inds = list()
	for k,v in d.items():
		if str(v) == str(admix):
			admix_inds.append(k)
		elif str(v) == str(p1):
			p1_inds.append(k)
		elif str(v) == str(p2):
			p2_inds.append(k)
		else:
			raise ValueError("\n\nPopulation {} is different than P1, P2 and Admixed! Aborting.")

	# Error handling if wrong population specified.
	if not admix_inds:
		raise ValueError("\n\nPopulation {} was not found in the popmap file! Aborting\n\n".format(admix))
	if not p1_inds:
		raise ValueError("\n\nPopulation {} was not found in the popmap file! Aborting\n\n".format(p1))
	if not p2_inds:
		raise ValueError("\n\nPopulation {} was not found in the popmap file! Aborting\n\n".format(p2))

	popdict["Admixed"] = admix_inds
	popdict["P1"] = p1_inds
	popdict["P2"] = p2_inds

	# Sanity checks. Print number of individuals in each population.
	print("\n\nP1 population has {} individuals...\n".format(len(popdict["P1"])))

	print("P2 population has {} individuals...\n".format(len(popdict["P2"])))

	print("Admixed populalation has {} individuals...\n\n".format(len(popdict["Admixed"])))

	return popdict