# Path: genda/formats/snp_array.py
# class SNP_array(Genotype.Genotype):
#     __doc__ = """
#     Class that specifically deals with genotyping from microarrays.
# 
#     %(param)s
#     zipfile : location of output
# 
#     %(extra_param)s
#     fileformat : {'one column', 'two column', 'illumina'} 
#     delim : Data delimiter
#     sample_col : The columns in which 
#     encoding : Encoding data for the SNPs.
#     header_lines : Number of lines to be read in as the header.
#     startatline : The line to start reading data at.
# 
#     Attributes
#     ----------
#     df : original dataframe loaded
#     geno : converted genotype matrix
#     file_format : file format
#     apply_encoder :  
# 
# 
#     Related
#     -------
#     Genotype.Genotype
#     """
#     def __init__(self, zipfile, file_format = 'one column', 
#             delim = ',', samp_col = None, encoding = None, header_lines = 0,
#             startatline = 0, readnrows = None):
#         
#         try:
#             self.df = pd.read_csv(gzip.GzipFile(zipfile), 
#                     delimiter = delim, header = header_lines,
#                     skiprows = startatline-1, nrows = readnrows)
#         # :TODO change exception
#         except:
#             self.df = pd.read_csv(zipfile, delimiter = delim, header = header_lines, skiprows = startatline-1, nrows = readnrows)
# 
# 
#         if file_format == 'two_column':
#             if samp_col == None:
#                 samp_col = 4
#             self.samp_col = samp_col
#             try:
#                 self.df.index = self.df.ix[:,'Snp.ID']
#             except KeyError:
#                 self.df.index = self.df.ix[:,1]
#             if isinstance(encoding, (int, long)):
#                 encoding = self.df.ix[:,encoding]
#             self.encoder = encoding
#             if type(self.encoder) == type(None):
#                 self.geno = None
#             else:
#                 self.geno = self.df.ix[:,self.samp_col:].apply(
#                         _two_columns_per_individual_conversion, 
#                         encoder = self.encoder, axis=1)
# 
#         elif file_format == 'one column':
#             if samp_col == None:
#                 samp_col = 3
#             self.samp_col = samp_col
#             self.df.index = self.df.ix[:,0]
#             if isinstance(encoding, (int, long)):
#                 encoding = self.df.ix[:,encoding]
#             self.encoder = encoding
#             if type(self.encoder) == type(None):
#                 self.geno = None
#             else:
#                 self.geno = self.df.ix[:,self.samp_col:].apply(
#                         _single_column_allele, 
#                         encoder = self.encoder, axis = 1)
# 
#         elif file_format == 'illumina':
#             pass
# 
#         else:
#             raise NotImplementedError("Only 'one_column', 'two_column' and\
#                     'illumina' formats are currently supported")
# 
#         self.filetype = file_format
# 
# 
#     def apply_encoder(self, encoder):
#         """
#         To apply the encoder to the SNP_array object after the fact if one was sot 
#         supplied with creation
#         """
#         if self.filetype == 'one column':
#             return self.df.ix[:,self.samp_col:].apply(_single_column_allele, 
#                     encoder = encoder, axis = 1)
#         elif self.filetype == 'two column':
#             return self.df.ix[:,self.samp_col:].apply(_two_columns_per_individual_coversion, 
#                     encoder = encoder, axis = 1)
#         else:
#             return None


import unittest, os
from genda.formats.snp_array import SNP_array


class TestLoadingSingleColumnData(unittest.TestCase):
    """ Testing loading one column SNP array files into pandas
    """

    def setUp(self):
        path = os.path.dirname(os.path.abspath(__file__))
        self.filename = path + '/data/one-column-test-data'

# Path: genda/formats/snp_array.py
# class SNP_array(Genotype.Genotype):
#     __doc__ = """
#     Class that specifically deals with genotyping from microarrays.
# 
#     %(param)s
#     zipfile : location of output
# 
#     %(extra_param)s
#     fileformat : {'one column', 'two column', 'illumina'} 
#     delim : Data delimiter
#     sample_col : The columns in which 
#     encoding : Encoding data for the SNPs.
#     header_lines : Number of lines to be read in as the header.
#     startatline : The line to start reading data at.
# 
#     Attributes
#     ----------
#     df : original dataframe loaded
#     geno : converted genotype matrix
#     file_format : file format
#     apply_encoder :  
# 
# 
#     Related
#     -------
#     Genotype.Genotype
#     """
#     def __init__(self, zipfile, file_format = 'one column', 
#             delim = ',', samp_col = None, encoding = None, header_lines = 0,
#             startatline = 0, readnrows = None):
#         
#         try:
#             self.df = pd.read_csv(gzip.GzipFile(zipfile), 
#                     delimiter = delim, header = header_lines,
#                     skiprows = startatline-1, nrows = readnrows)
#         # :TODO change exception
#         except:
#             self.df = pd.read_csv(zipfile, delimiter = delim, header = header_lines, skiprows = startatline-1, nrows = readnrows)
# 
# 
#         if file_format == 'two_column':
#             if samp_col == None:
#                 samp_col = 4
#             self.samp_col = samp_col
#             try:
#                 self.df.index = self.df.ix[:,'Snp.ID']
#             except KeyError:
#                 self.df.index = self.df.ix[:,1]
#             if isinstance(encoding, (int, long)):
#                 encoding = self.df.ix[:,encoding]
#             self.encoder = encoding
#             if type(self.encoder) == type(None):
#                 self.geno = None
#             else:
#                 self.geno = self.df.ix[:,self.samp_col:].apply(
#                         _two_columns_per_individual_conversion, 
#                         encoder = self.encoder, axis=1)
# 
#         elif file_format == 'one column':
#             if samp_col == None:
#                 samp_col = 3
#             self.samp_col = samp_col
#             self.df.index = self.df.ix[:,0]
#             if isinstance(encoding, (int, long)):
#                 encoding = self.df.ix[:,encoding]
#             self.encoder = encoding
#             if type(self.encoder) == type(None):
#                 self.geno = None
#             else:
#                 self.geno = self.df.ix[:,self.samp_col:].apply(
#                         _single_column_allele, 
#                         encoder = self.encoder, axis = 1)
# 
#         elif file_format == 'illumina':
#             pass
# 
#         else:
#             raise NotImplementedError("Only 'one_column', 'two_column' and\
#                     'illumina' formats are currently supported")
# 
#         self.filetype = file_format
# 
# 
#     def apply_encoder(self, encoder):
#         """
#         To apply the encoder to the SNP_array object after the fact if one was sot 
#         supplied with creation
#         """
#         if self.filetype == 'one column':
#             return self.df.ix[:,self.samp_col:].apply(_single_column_allele, 
#                     encoder = encoder, axis = 1)
#         elif self.filetype == 'two column':
#             return self.df.ix[:,self.samp_col:].apply(_two_columns_per_individual_coversion, 
#                     encoder = encoder, axis = 1)
#         else:
#             return None


# Path: tests/snp_array_tests.py
import unittest, os
from genda.formats.snp_array import SNP_array



class TestLoadingSingleColumnData(unittest.TestCase):
    """ Testing loading one column SNP array files into pandas
    """

    def setUp(self):
        path = os.path.dirname(os.path.abspath(__file__))
        self.filename = path + '/data/one-column-test-data'

        self.array = SNP_array(self.filename, file_format = 'one column', 