def test_read_correct(self): inputstr = ( "# ranked parent-child\r\n" "# 2 1\r\n" "id\tname\tp-value\tbh_fdr|bonferroni\tattributes\r\n" "9951\tstructure-specific DNA binding\t0.032301032301\t1.0|1.0\t{'plot': [0.1, 0.2, 1.0, 0.1], 'score': 1.0}\r\n" "9916\tpolysomal ribosome\t0.025\t1.0|1.0\t\r\n" "!\tCycles found...\r\n") test_input = StringIO(inputstr) e1 = EnrichmentEntry("9951", "structure-specific DNA binding", 0.032301032301) e1.corrections = {'bh_fdr': 1.0, 'bonferroni': 1.0} e1.attrs = {'plot': [0.1, 0.2, 1.0, 0.1], 'score': 1.0} e2 = EnrichmentEntry("9916", "polysomal ribosome", 0.025) e2.corrections = {'bh_fdr': 1.0, 'bonferroni': 1.0} e2.attrs = {} expected_en = Enrichment("ranked parent-child", [e1, e2], ["Cycles found..."], ['bh_fdr', 'bonferroni']) reader = EnrichmentReader(test_input) en = reader.read() self.assertEqual(expected_en, en)
def test_write(self): result = StringIO() e1 = EnrichmentEntry("9951", "structure-specific DNA binding", 0.032301032301) e1.corrections = {'bh_fdr': 1.0, 'bonferroni': 1.0} e1.attrs = {'plot': [0.1, 0.2, 1.0, 0.1]} e2 = EnrichmentEntry("9916", "polysomal ribosome", 0.025) e2.corrections = {'bh_fdr': 1.0, 'bonferroni': 1.0} e2.attrs = {} en = Enrichment("ranked parent-child", [e1, e2], ["Cycles found..."], ['bh_fdr', 'bonferroni']) writer = EnrichmentWriter(result) writer.write(en) expected = ( "# ranked parent-child\r\n" "# 2 1\r\n" "id\tname\tp-value\tbh_fdr|bonferroni\tattributes\r\n" "9951\tstructure-specific DNA binding\t0.032301032301\t1.0|1.0\t{'plot': [0.1, 0.2, 1.0, 0.1]}\r\n" "9916\tpolysomal ribosome\t0.025\t1.0|1.0\t{}\r\n" "!\tCycles found...\r\n") self.assertEqual(expected, result.getvalue())
def _row_to_entry(row, corr_names, read_attrs): oid = row[0] name = row[1] p_val = float(row[2]) corrections = {} corrlist = row[3].split("|") for i in xrange(len(corr_names)): corrections[corr_names[i]] = float(corrlist[i]) entry = EnrichmentEntry(oid, name, p_val) entry.corrections = corrections if read_attrs and row[4]: entry.attrs = ast.literal_eval(row[4]) return entry
def test_write(self): result = StringIO() e1 = EnrichmentEntry("9951", "structure-specific DNA binding", 0.032301032301) e1.corrections = {'bh_fdr': 1.0, 'bonferroni': 1.0} e1.attrs = {'plot' : [0.1, 0.2, 1.0, 0.1]} e2 = EnrichmentEntry("9916", "polysomal ribosome", 0.025) e2.corrections = {'bh_fdr': 1.0, 'bonferroni': 1.0} e2.attrs = {} en = Enrichment("ranked parent-child", [e1, e2], ["Cycles found..."], ['bh_fdr', 'bonferroni']) writer = EnrichmentWriter(result) writer.write(en) expected = ("# ranked parent-child\r\n" "# 2 1\r\n" "id\tname\tp-value\tbh_fdr|bonferroni\tattributes\r\n" "9951\tstructure-specific DNA binding\t0.032301032301\t1.0|1.0\t{'plot': [0.1, 0.2, 1.0, 0.1]}\r\n" "9916\tpolysomal ribosome\t0.025\t1.0|1.0\t{}\r\n" "!\tCycles found...\r\n") self.assertEqual(expected, result.getvalue())
def _row_to_entry(row, corr_names, read_attrs): oid = row[0] name = row[1] p_val = float(row[2]) corrections = {} corrlist = row[3].split("|") for i in xrange(len(corr_names)): corrections[corr_names[i]] = float(corrlist[i]) entry = EnrichmentEntry(oid, name, p_val) entry.corrections = corrections if read_attrs and row[4]: entry.attrs = ast.literal_eval(row[4]) return entry
def test_read_correct(self): inputstr = ("# ranked parent-child\r\n" "# 2 1\r\n" "id\tname\tp-value\tbh_fdr|bonferroni\tattributes\r\n" "9951\tstructure-specific DNA binding\t0.032301032301\t1.0|1.0\t{'plot': [0.1, 0.2, 1.0, 0.1], 'score': 1.0}\r\n" "9916\tpolysomal ribosome\t0.025\t1.0|1.0\t\r\n" "!\tCycles found...\r\n") test_input = StringIO(inputstr) e1 = EnrichmentEntry("9951", "structure-specific DNA binding", 0.032301032301) e1.corrections = {'bh_fdr': 1.0, 'bonferroni': 1.0} e1.attrs = {'plot' : [0.1, 0.2, 1.0, 0.1], 'score' : 1.0} e2 = EnrichmentEntry("9916", "polysomal ribosome", 0.025) e2.corrections = {'bh_fdr': 1.0, 'bonferroni': 1.0} e2.attrs = {} expected_en = Enrichment("ranked parent-child", [e1, e2], ["Cycles found..."], ['bh_fdr', 'bonferroni']) reader = EnrichmentReader(test_input) en = reader.read() self.assertEqual(expected_en, en)