# Path: pydigree/recombination.py
# def recombine(chr1, chr2, genetic_map):
#     """
#     Takes two chromatids and returns a simulated one by an exponential process
#     
#     :param chr1: first chrom
#     :param chr2: second chrom
#     :param genetic_map: map positions (in centiMorgans)
#     :type chr1: AlleleContainer
#     :type chr2: AlleleContainer
#     :type genetic_map: sequence of floats
# 
#     :returns: Recombined chromosome
#     :rtype: AlleleContainer
#     """
#     if not isinstance(chr1, AlleleContainer): 
#         raise ValueError(
#             'Invalid chromosome type for recombination: {}'.format(type(chr1))) 
# 
#     if type(chr1) is not type(chr2):
#         raise ValueError("Can't mix chromosome types in recombination")
# 
#     if chr1.dtype != chr2.dtype:
#         raise ValueError('Chromosomes have different data types')
# 
#     # An optimization for gene dropping procedures on IBD states.
#     # If there is only one marker, choose one at random, and return that.
#     # There's no need for searching through the map to find crossover points
#     if len(genetic_map) == 1:
#         return chr1 if np.random.randint(0, 2) else chr2
# 
#     newchrom = _recombine_haldane(chr1, chr2, genetic_map)
#     return newchrom
# 
# Path: pydigree/genotypes/alleles.py
# class Alleles(np.ndarray, AlleleContainer):
# 
#     ''' A class for holding genotypes '''
#     def __new__(cls, data, template=None, **kwargs):
#         obj = np.asarray(data, **kwargs).view(cls)
#         obj.template = template
#         return obj
# 
#     def __array__finalize__(self, obj):
#         if obj is None:
#             return
#         self.template = getattr(obj, 'template', None)
# 
#     @property
#     def missingcode(self):
#         return 0 if np.issubdtype(self.dtype, np.integer) else ''
# 
#     @property
#     def missing(self):
#         """
#         Returns a numpy array indicating which markers have missing data
#         
#         :returns: missingness array
#         :rtype: np.array
#         """
#         return np.array(self == self.missingcode)
# 
#     def nmark(self):
#         '''
#         Return the number of markers represented by the Alleles object
# 
#         :returns: number of markers
#         :rtype: int
#         '''
#         return self.shape[0]
# 
#     def copy_span(self, template, copy_start, copy_stop):
#         """
#         Copies a span of another AlleleContainer to this one
# 
#         :param template: Container to copy from
#         :type template: AlleleContainer
#         :param copy_start: start point for copy (inclusive)
#         :type copy_start: int
#         :param copy_stop: end_point for copy (exclusive)
#         :type copy_stop: int
# 
#         :rtype: void
#         """
#         self[copy_start:copy_stop] = template[copy_start:copy_stop]
# 
#     def empty_like(self):
#         ''' Returns an empty Alleles object like this one '''
#         z = np.zeros(self.nmark(), dtype=self.dtype)
# 
#         return Alleles(z, template=self.template)


from nose.tools import assert_raises
from pydigree.recombination import recombine
from pydigree.genotypes import Alleles
import numpy as np



def test_recombine():
    a = Alleles(np.zeros(10))
    b = Alleles(np.ones(10))
    m = np.arange(1, 100, 10)

    n = recombine(a, b, m)
    assert len(n) == len(m)
    assert type(n) == type(a) == type(b)

# Path: pydigree/recombination.py
# def recombine(chr1, chr2, genetic_map):
#     """
#     Takes two chromatids and returns a simulated one by an exponential process
#     
#     :param chr1: first chrom
#     :param chr2: second chrom
#     :param genetic_map: map positions (in centiMorgans)
#     :type chr1: AlleleContainer
#     :type chr2: AlleleContainer
#     :type genetic_map: sequence of floats
# 
#     :returns: Recombined chromosome
#     :rtype: AlleleContainer
#     """
#     if not isinstance(chr1, AlleleContainer): 
#         raise ValueError(
#             'Invalid chromosome type for recombination: {}'.format(type(chr1))) 
# 
#     if type(chr1) is not type(chr2):
#         raise ValueError("Can't mix chromosome types in recombination")
# 
#     if chr1.dtype != chr2.dtype:
#         raise ValueError('Chromosomes have different data types')
# 
#     # An optimization for gene dropping procedures on IBD states.
#     # If there is only one marker, choose one at random, and return that.
#     # There's no need for searching through the map to find crossover points
#     if len(genetic_map) == 1:
#         return chr1 if np.random.randint(0, 2) else chr2
# 
#     newchrom = _recombine_haldane(chr1, chr2, genetic_map)
#     return newchrom
# 
# Path: pydigree/genotypes/alleles.py
# class Alleles(np.ndarray, AlleleContainer):
# 
#     ''' A class for holding genotypes '''
#     def __new__(cls, data, template=None, **kwargs):
#         obj = np.asarray(data, **kwargs).view(cls)
#         obj.template = template
#         return obj
# 
#     def __array__finalize__(self, obj):
#         if obj is None:
#             return
#         self.template = getattr(obj, 'template', None)
# 
#     @property
#     def missingcode(self):
#         return 0 if np.issubdtype(self.dtype, np.integer) else ''
# 
#     @property
#     def missing(self):
#         """
#         Returns a numpy array indicating which markers have missing data
#         
#         :returns: missingness array
#         :rtype: np.array
#         """
#         return np.array(self == self.missingcode)
# 
#     def nmark(self):
#         '''
#         Return the number of markers represented by the Alleles object
# 
#         :returns: number of markers
#         :rtype: int
#         '''
#         return self.shape[0]
# 
#     def copy_span(self, template, copy_start, copy_stop):
#         """
#         Copies a span of another AlleleContainer to this one
# 
#         :param template: Container to copy from
#         :type template: AlleleContainer
#         :param copy_start: start point for copy (inclusive)
#         :type copy_start: int
#         :param copy_stop: end_point for copy (exclusive)
#         :type copy_stop: int
# 
#         :rtype: void
#         """
#         self[copy_start:copy_stop] = template[copy_start:copy_stop]
# 
#     def empty_like(self):
#         ''' Returns an empty Alleles object like this one '''
#         z = np.zeros(self.nmark(), dtype=self.dtype)
# 
#         return Alleles(z, template=self.template)


# Path: tests/test_recombine.py
from nose.tools import assert_raises
from pydigree.recombination import recombine
from pydigree.genotypes import Alleles
import numpy as np




def test_recombine():
    a = Alleles(np.zeros(10))
    b = Alleles(np.ones(10))
    m = np.arange(1, 100, 10)

    n = recombine(a, b, m)
    assert len(n) == len(m)
    assert type(n) == type(a) == type(b)

    assert_raises(ValueError, recombine, None, None, None)