<commit_before># Open Drosophila Lab
# Copyright (C) 2010  <NAME>
#	http://possibilistic.org
#	mailto:[echelon,<EMAIL>]<EMAIL>
#
# (potentially) For Southern Polytechnic State University
#	http://www.spsu.edu
#
# Open Drosophila Lab is an open source reimplementation of Virtual FlyLab,
# a for-pay resource by the California State University and <NAME>.
#
#	This program is free software: you can redistribute it and/or modify
#	it under the terms of the GNU Affero General Public License as
#	published by the Free Software Foundation, either version 3 of the
#	License, or (at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU Affero General Public License for more details.
#
#	You should have received a copy of the GNU Affero General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>.

import random
from allele import Allele
from trait import Trait
from defs import defs

from chromoset import HaploSet, DiploSet
from gamete import Gamete

class Individual(object):

	def __init__(self, chromos = None, sex = None):
		"""Constructor. 
		If sex is specified, it will force the sex of the individual and REMOVE
		any sex chromosomes, resetting them to WILDTYPE."""

		if type(sex) == str:
			sex = sex.lower()

		if sex and (sex != 'm' and sex != 'f'):
			raise Exception, "Invalid sex specified."

		if chromos and type(chromos) != DiploSet:
			raise Exception, "Invalid DiploSet provided for individual"

		if sex and chromos:
			raise Exception, "Cannot supply both DiploSet and sex parameter."

		self.chromos = chromos
		self.sex = None

		if not sex:
			sex = 'f'

		# Set up the object based on input
		if chromos:
			self.__calcSex()
		else:
			self.chromos = DiploSet()
			self.__setSex(sex)


	# =============== Gender-related methods ================= #

	def __setSex(self, sex):
		"""Used by the constructor to set the sex of the individual.
		Removes any genes set for Chromosome I, resetting any traits present to 
		wild type."""

		if type(sex) != str:
			raise Exception, "Sex parameter must be a string."

		sex = sex.lower()

		if sex != 'm' and sex != 'f':
			raise Exception, "Invalid sex specified."

		self.sex = sex

		# Remove all genes from both pairs of Chromosome I
		# This *must* be done to ensure no errors in sex-linkage crop up
		self.chromos[0][0] = []
		self.chromos[1][0] = []

		# For consistency, First Chromo I is always X, Second is either X or Y
		self.chromos[0][0].append('xch')
		if sex == 'm':
			self.chromos[1][0].append('ych')
		else:
			self.chromos[1][0].append('xch')

	def __calcSex(self):
		"""Calculate sex based on X-balance system and cache the result.
		This is used for the drosophila the user does not manually create (the 
		progeny).
		"""

		# Implementation of X-balance system of sex determinancy
		cnt = 0
		if 'xch' in self.chromos[0][0]:
			cnt += 1
		if 'xch' in self.chromos[1][0]:
			cnt += 1

		if cnt >= 2:
			self.sex = 'f'
		else:
			self.sex = 'm'
		
	def isFemale(self):
		"""Test if individual is female."""
		if not self.sex:
			self.__calcSex()
		return (self.sex == 'f')

	def getSex(self):
		"""Return sex string"""		
		if not self.sex:
			self.__calcSex()
		return self.sex


	# =============== Representation, etc. methods =========== #

	def __repr__(self):
		ret = "<individual %s\n" % self.getSex()
		ret += str(self.chromos)
		return ret


	# =============== Mating of individuals ================== #






	# =============== TODO / FIXME / UPDATE ================== #

	def mateMany(self, o, numOffspring = 1000):

		# Vary the number of offspring slightly 
		diff = int(random.gauss(0, 12))
		numOffspring += diff

		progeny = []
		for i in range(numOffspring):
			progeny.append(self.mate(other))

		return progeny

	def getGamete(self):

		# XXX: Males do not cross over.
		# XXX: Produce 4, but only return 1. 

		nsex = 'f'
		hap = HaploSet()
<commit_msg>Update documentation, license block<commit_after># Open Drosophila Lab
# Copyright (C) 2010  <NAME>
#	http://possibilistic.org
#	mailto:[echelon|<EMAIL>]<EMAIL>
#
# (potentially) For Southern Polytechnic State University
#	http://www.spsu.edu
#
# Open Drosophila Lab promotes the learning of basic non-Mendelian inheritance
# and gene mapping by engaging students in designing genetic crosses. It is an 
# open source reimplementation of Virtual FlyLab, a for-pay resource created by 
# California State University and publisher <NAME>. 
#
#	This program is free software: you can redistribute it and/or modify
#	it under the terms of the GNU Affero General Public License as
#	published by the Free Software Foundation, either version 3 of the
#	License, or (at your option) any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU Affero General Public License for more details.
#
#	You should have received a copy of the GNU Affero General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>.

import random
from allele import Allele
from trait import Trait
from defs import defs

from chromoset import HaploSet, DiploSet
from gamete import Gamete

class Individual(object):

	def __init__(self, chromos = None, sex = None):
		"""Individual CTOR. 

		* If a diploset of chromosomes is specified, the individual will use
		  these as its genes. 
		* If sex is specified, it will force the sex of the individual and 
		  REMOVE any sex chromosomes, resetting them to WILDTYPE.

		For now, these parameters are mutually exclusive.
		"""

		if type(sex) == str:
			sex = sex.lower()

		if sex and (sex != 'm' and sex != 'f'):
			raise Exception, "Invalid sex specified."

		if chromos and type(chromos) != DiploSet:
			raise Exception, "Invalid DiploSet provided for individual"

		if sex and chromos:
			raise Exception, "Cannot supply both DiploSet and sex parameter."

		self.chromos = chromos
		self.sex = None

		if not sex:
			sex = 'f'

		# Set up the object based on input
		if chromos:
			self.__calcSex()
		else:
			self.chromos = DiploSet()
			self.__setSex(sex)


	# ======================================================== #
	#                Gender-related methods                    #
	# ======================================================== #

	def __setSex(self, sex):
		"""Used by the constructor to set the sex of the individual.
		Removes any genes set for Chromosome I, resetting any traits present to 
		wild type."""

		if type(sex) != str:
			raise Exception, "Sex parameter must be a string."

		sex = sex.lower()

		if sex != 'm' and sex != 'f':
			raise Exception, "Invalid sex specified."

		self.sex = sex

		# Remove all genes from both pairs of Chromosome I
		# This *must* be done to ensure no errors in sex-linkage crop up
		self.chromos[0][0] = []
		self.chromos[1][0] = []

		# For consistency, First Chromo I is always X, Second is either X or Y
		self.chromos[0][0].append('xch')
		if sex == 'm':
			self.chromos[1][0].append('ych')
		else:
			self.chromos[1][0].append('xch')

	def __calcSex(self):
		"""Calculate sex based on X-balance system and cache the result.
		This is used for the drosophila the user does not manually create (the 
		progeny).
		"""

		# Implementation of X-balance system of sex determinancy
		cnt = 0
		if 'xch' in self.chromos[0][0]:
			cnt += 1
		if 'xch' in self.chromos[1][0]:
			cnt += 1

		if cnt >= 2:
			self.sex = 'f'
		else:
			self.sex = 'm'
		
	def isFemale(self):
		"""Test if individual is female."""
		if not self.sex:
			self.__calcSex()
		return (self.sex == 'f')

	def getSex(self):
		"""Return sex string"""		
		if not self.sex:
			self.__calcSex()
		return self.sex


	# ======================================================== #
	#              Representation, etc. methods                #
	# ======================================================== #

	def __repr__(self):
		ret = "<individual %s\n" % self.getSex()
		ret += str(self.chromos)
		return ret


	# ======================================================== #
	#                  Mating of individuals                   #
	# ======================================================== #






	# =============== TODO / FIXME / UPDATE ================== #

	def mateMany(self, o, numOffspring = 1000):

		# Vary the number of offspring slightly 
		diff = int(random.gauss(0, 12))
		numOffspring += diff

		progeny = []
		for i in range(numOffspring):
			progeny.append(self.mate(other))

		return progeny

	def getGamete(self):

		# XXX: Males do not cross over.
		# XXX: Produce 4, but only return 1. 

		nsex = 'f'
		hap = HaploSet()

{'fraction_non_alphanumeric': 0.1526476233487637, 'fraction_numerical': 0.007225922998758044, 'mean_word_length': 3.4579768495218923, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5779969', 'n_tokens_mistral': 3123, 'n_tokens_neox': 2653, 'n_words': 1049}