# Path: denovoFilter/standardise.py
# def standardise_columns(de_novos):
#     """ subset down to specific columns
#     
#     Args:
#         de_novos dataframe of de novo variants
#     
#      Returns:
#         data frame with only the pertinent columns included
#     """
#     
#     columns = ["person_stable_id", "chrom", "pos", "ref", "alt",
#         "symbol", "consequence", "max_af", "pp_dnm"]
#     
#     if 'pass' in de_novos.columns:
#         columns.append('pass')
#     
#     return de_novos[columns].copy()
# 
# Path: tests/compare_dataframes.py
# class CompareTables(unittest.TestCase):
#     def compare_tables(self, first, second):
#         """ check if two Dataframes contain the same information.
#         
#         Note that the dataframes don't have to have the same column order.
#         
#         Args:
#             first: pandas DataFrame
#             second: pandas DataFrame
#         """
#         
#         # make sure the two tables have the same columns, and number of rows
#         self.assertEqual(set(first.columns), set(second.columns))
#         self.assertEqual(len(first), len(second))
#         
#         # make sure the values in the columns are identical between tables.
#         # We have to run through all the values one by one, to make sure that
#         # NaN values compare correctly.
#         for column in first:
#             for pos in range(len(first)):
#                 first_val = first[column][pos]
#                 second_val = second[column][pos]
#                 
#                 # prepare a suitable diagnostic error message if the values are
#                 #  not equal
#                 if type(first_val) == str or first_val is None or type(first_val) == numpy.bool_:
#                     msg = "{} != {} at position {} in {}".format(first_val,
#                         second_val, pos, column)
#                 else:
#                     msg = "{:.20f} != {:.20f} at position {} in {}".format( \
#                         first_val, second_val, pos, column)
#                 
#                 if type(first_val) in [float, numpy.float64] and math.isnan(first_val):
#                     # if one is nan, check that the other is also nan, since
#                     # nan entries cannot be chacked for eqaulity.
#                     self.assertTrue(math.isnan(second_val), msg)
#                 elif type(first_val) in [float, numpy.float64]:
#                     # Only check if floats are nearly equal to get around float
#                     # precision issues.
#                     self.assertAlmostEqual(first_val, second_val, msg=msg)
#                 else:
#                     self.assertEqual(first_val, second_val, msg)


import unittest
from pandas import DataFrame
from denovoFilter.standardise import standardise_columns
from tests.compare_dataframes import CompareTables
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''




class TestStandardise(CompareTables):
    
    def setUp(self):
        self.initial = DataFrame({
            'person_stable_id': ['sample_01', 'sample_02'],
            'chrom': ['6', '6'],
            'pos': [1, 2],
            'ref': ['A', 'G'],
            'alt': ['C', 'T'],
            'symbol': ['TEST1', 'TEST2'],
            'consequence': ['missense_variant', 'stop_gained'],
            'max_af': [0.0001, 0],
            'pp_dnm': [1, 0.95],
            })
        
        self.expected = self.initial.copy()
    
    def test_standardise_columns(self):
        ''' test that standardising the columns works
        '''
        
        self.initial['child_ref_F'] = [23, 35]

# Path: denovoFilter/standardise.py
# def standardise_columns(de_novos):
#     """ subset down to specific columns
#     
#     Args:
#         de_novos dataframe of de novo variants
#     
#      Returns:
#         data frame with only the pertinent columns included
#     """
#     
#     columns = ["person_stable_id", "chrom", "pos", "ref", "alt",
#         "symbol", "consequence", "max_af", "pp_dnm"]
#     
#     if 'pass' in de_novos.columns:
#         columns.append('pass')
#     
#     return de_novos[columns].copy()
# 
# Path: tests/compare_dataframes.py
# class CompareTables(unittest.TestCase):
#     def compare_tables(self, first, second):
#         """ check if two Dataframes contain the same information.
#         
#         Note that the dataframes don't have to have the same column order.
#         
#         Args:
#             first: pandas DataFrame
#             second: pandas DataFrame
#         """
#         
#         # make sure the two tables have the same columns, and number of rows
#         self.assertEqual(set(first.columns), set(second.columns))
#         self.assertEqual(len(first), len(second))
#         
#         # make sure the values in the columns are identical between tables.
#         # We have to run through all the values one by one, to make sure that
#         # NaN values compare correctly.
#         for column in first:
#             for pos in range(len(first)):
#                 first_val = first[column][pos]
#                 second_val = second[column][pos]
#                 
#                 # prepare a suitable diagnostic error message if the values are
#                 #  not equal
#                 if type(first_val) == str or first_val is None or type(first_val) == numpy.bool_:
#                     msg = "{} != {} at position {} in {}".format(first_val,
#                         second_val, pos, column)
#                 else:
#                     msg = "{:.20f} != {:.20f} at position {} in {}".format( \
#                         first_val, second_val, pos, column)
#                 
#                 if type(first_val) in [float, numpy.float64] and math.isnan(first_val):
#                     # if one is nan, check that the other is also nan, since
#                     # nan entries cannot be chacked for eqaulity.
#                     self.assertTrue(math.isnan(second_val), msg)
#                 elif type(first_val) in [float, numpy.float64]:
#                     # Only check if floats are nearly equal to get around float
#                     # precision issues.
#                     self.assertAlmostEqual(first_val, second_val, msg=msg)
#                 else:
#                     self.assertEqual(first_val, second_val, msg)


# Path: tests/test_standardise.py
import unittest
from pandas import DataFrame
from denovoFilter.standardise import standardise_columns
from tests.compare_dataframes import CompareTables

COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'''




class TestStandardise(CompareTables):
    
    def setUp(self):
        self.initial = DataFrame({
            'person_stable_id': ['sample_01', 'sample_02'],
            'chrom': ['6', '6'],
            'pos': [1, 2],
            'ref': ['A', 'G'],
            'alt': ['C', 'T'],
            'symbol': ['TEST1', 'TEST2'],
            'consequence': ['missense_variant', 'stop_gained'],
            'max_af': [0.0001, 0],
            'pp_dnm': [1, 0.95],
            })
        
        self.expected = self.initial.copy()
    
    def test_standardise_columns(self):
        ''' test that standardising the columns works
        '''
        
        self.initial['child_ref_F'] = [23, 35]

        self.compare_tables(standardise_columns(self.initial), self.expected)