# Path: genda/formats/PED.py
# class PED(Genotype.Genotype):
# 
#     def __init__(self, PED, MAP, encoder = None):
#         self.PED = pd.read_table(PED, 
#                 delim_whitespace = True, header = None)
#         self.MAP = pd.read_table(MAP, 
#                 delim_whitespace = True, header = None)
#         if encoder != None:
#             self.geno = self.genotype(self.PED, self.MAP, encoder)
#         else:
#             self.geno = None
# 
# 
#     def genotype(self, PED, MAP, encoder):
#         geno = PED.ix[:, 6:]
#         snps = []
#         for s in MAP.ix[:,1]:
#             snps.extend([s]*2)
#         geno.columns = snps
#         geno = geno.apply(self.apply_encoder, encoder = encoder)
#         geno = pd.DataFrame([[geno.ix[r,c*2] +\
#             geno.ix[r,(c*2)+1]\
#             for c in range(geno.shape[1]/2)] for r\
#             in range(geno.shape[0])])
# 
#         geno = geno.transpose()
#         geno.index = MAP.ix[:,1]
#         geno.columns = PED.ix[:,1]
#         return geno
#         
# 
#     def apply_encoder(self, PED, encoder):
#         snp = encoder[PED.name]
#         encoding_dict = {snp[0] : 0, snp[2] : 1, '0': np.nan}
#         return PED.map(encoding_dict)


import unittest, os
import numpy as np
from genda.formats.PED import PED



class TestLoadingSingleColumnData(unittest.TestCase):
    """ Testing loading VCF files into pandas
    """

    def setUp(self):
        path = os.path.dirname(os.path.abspath(__file__))
        self.pedfile = path + '/data/test.ped'
        self.mapfile = path + '/data/test.map'
        self.encoder = {'snp1':'A/C','snp2':'A/C','snp3':'C/A','snp4':'T/G','snp5':'C/A'}

# Path: genda/formats/PED.py
# class PED(Genotype.Genotype):
# 
#     def __init__(self, PED, MAP, encoder = None):
#         self.PED = pd.read_table(PED, 
#                 delim_whitespace = True, header = None)
#         self.MAP = pd.read_table(MAP, 
#                 delim_whitespace = True, header = None)
#         if encoder != None:
#             self.geno = self.genotype(self.PED, self.MAP, encoder)
#         else:
#             self.geno = None
# 
# 
#     def genotype(self, PED, MAP, encoder):
#         geno = PED.ix[:, 6:]
#         snps = []
#         for s in MAP.ix[:,1]:
#             snps.extend([s]*2)
#         geno.columns = snps
#         geno = geno.apply(self.apply_encoder, encoder = encoder)
#         geno = pd.DataFrame([[geno.ix[r,c*2] +\
#             geno.ix[r,(c*2)+1]\
#             for c in range(geno.shape[1]/2)] for r\
#             in range(geno.shape[0])])
# 
#         geno = geno.transpose()
#         geno.index = MAP.ix[:,1]
#         geno.columns = PED.ix[:,1]
#         return geno
#         
# 
#     def apply_encoder(self, PED, encoder):
#         snp = encoder[PED.name]
#         encoding_dict = {snp[0] : 0, snp[2] : 1, '0': np.nan}
#         return PED.map(encoding_dict)


# Path: tests/ped_tests.py
import unittest, os
import numpy as np
from genda.formats.PED import PED




class TestLoadingSingleColumnData(unittest.TestCase):
    """ Testing loading VCF files into pandas
    """

    def setUp(self):
        path = os.path.dirname(os.path.abspath(__file__))
        self.pedfile = path + '/data/test.ped'
        self.mapfile = path + '/data/test.map'
        self.encoder = {'snp1':'A/C','snp2':'A/C','snp3':'C/A','snp4':'T/G','snp5':'C/A'}

        self.PED = PED(self.pedfile, self.mapfile, encoder = self.encoder)