def test_get_matrix_value(self): """The matrix value is translated correctly""" self.assertEqual(get_matrix_value(None, self.trans_values), 0) self.assertEqual(get_matrix_value(0.15, self.trans_values), 1) self.assertEqual(get_matrix_value(0.35, self.trans_values), 2) self.assertEqual(get_matrix_value(0.65, self.trans_values), 3) self.assertEqual(get_matrix_value(0.85, self.trans_values), 4) self.assertEqual(get_matrix_value(0.0, self.trans_values), None) self.assertEqual(get_matrix_value(0.25, self.trans_values), 1) self.assertEqual(get_matrix_value(0.5, self.trans_values), 2) self.assertEqual(get_matrix_value(0.75, self.trans_values), 3) self.assertEqual(get_matrix_value(1.0, self.trans_values), 4)
def get_html_table(d_data, title, index): """Get the HTML table with the p values colored by significance Inputs: d_data: dict of: {sample: (p value, p value corrected)} title: string which contains the table title index: 0 indicates p value and 1 indicates p value corrected Returns a string which contains the html code of a table where the p values are colored by significance. """ # Check the index is in the expected range if index != 0 and index != 1: raise ValueError, "Index must be 0 or 1!" # Sort the sample names sorted_samples = d_data.keys() sorted_samples.sort() # Generate the HTML string with the rows code rows = '' for sample in sorted_samples: v = d_data[sample][index] c = get_matrix_value(v, DICT_TRANS_VALUES) rows += ROW_TABLE_HTML % (sample, c, v) # Generate the HTML string with the table code return TABLE_HTML % (title, rows)