Exemplo n.º 1
0
 def test_apply_operation_to_column(self):
     """Divide values in a column by 10
     """
     tabfile = TabFile('test',self.fp,first_line_is_header=True)
     # Check number of columns and header items
     self.assertEqual(tabfile.nColumns(),4)
     self.assertEqual(tabfile.header(),['chr','start','end','data'])
     # Divide data column by 10
     tabfile.transformColumn('data',lambda x: x/10)
     results = [0.46,0.57,0.68]
     for i in range(len(tabfile)):
         self.assertEqual(tabfile[i]['data'],results[i])
Exemplo n.º 2
0
 def test_apply_operation_to_column(self):
     """Divide values in a column by 10
     """
     tabfile = TabFile('test', self.fp, first_line_is_header=True)
     # Check number of columns and header items
     self.assertEqual(tabfile.nColumns(), 4)
     self.assertEqual(tabfile.header(), ['chr', 'start', 'end', 'data'])
     # Divide data column by 10
     tabfile.transformColumn('data', lambda x: x / 10)
     results = [0.46, 0.57, 0.68]
     for i in range(len(tabfile)):
         self.assertEqual(tabfile[i]['data'], results[i])
Exemplo n.º 3
0
 def test_set_column_to_constant_value(self):
     """Set a column to a constant value using transformColumn
     """
     tabfile = TabFile('test',self.fp,first_line_is_header=True)
     # Check number of columns and header items
     self.assertEqual(tabfile.nColumns(),4)
     self.assertEqual(tabfile.header(),['chr','start','end','data'])
     # Add a strand column
     tabfile.appendColumn('strand')
     self.assertEqual(tabfile.nColumns(),5)
     self.assertEqual(tabfile.header(),['chr','start','end','data','strand'])
     # Set all values to '+'
     tabfile.transformColumn('strand',lambda x: '+')
     for line in tabfile:
         self.assertEqual(line['strand'],'+')
Exemplo n.º 4
0
 def test_set_column_to_constant_value(self):
     """Set a column to a constant value using transformColumn
     """
     tabfile = TabFile('test', self.fp, first_line_is_header=True)
     # Check number of columns and header items
     self.assertEqual(tabfile.nColumns(), 4)
     self.assertEqual(tabfile.header(), ['chr', 'start', 'end', 'data'])
     # Add a strand column
     tabfile.appendColumn('strand')
     self.assertEqual(tabfile.nColumns(), 5)
     self.assertEqual(tabfile.header(),
                      ['chr', 'start', 'end', 'data', 'strand'])
     # Set all values to '+'
     tabfile.transformColumn('strand', lambda x: '+')
     for line in tabfile:
         self.assertEqual(line['strand'], '+')
Exemplo n.º 5
0
 def test_apply_operation_to_column(self):
     """Divide values in a column by 10
     """
     tabfile = TabFile('test', self.fp, first_line_is_header=True)
     # Check number of columns and header items
     self.assertEqual(tabfile.nColumns(), 4)
     self.assertEqual(tabfile.header(), ['chr', 'start', 'end', 'data'])
     # Divide data column by 10
     tabfile.transformColumn('data', lambda x: x / 10.0)
     results = [0.46, 0.57, 0.68]
     for i in range(len(tabfile)):
         # When checking the transformed column, coerce
         # the values to two decimal places to avoid tests
         # failing because of rounding errors (e.g.
         # 0.45999999999999996 != 0.46)
         self.assertEqual(float("%.2f" % tabfile[i]['data']), results[i])