def test_get_best_exon_from_p_value(self): exon_list = ExonList("A1BG") exon_list.add_exon(Exon("PSR19025918.hg.1", "A1BG", p_value=0.5347865)) exon_list.add_exon(Exon("PSR19025921.hg.1", "A1BG", p_value=0.5820691)) exon_list.add_exon(Exon("PSR19025922.hg.1", "A1BG", p_value=0.7582407)) exon_list.add_exon(Exon("PSR19025925.hg.1", "A1BG", p_value=0.4111732)) exon_list.add_exon(Exon("PSR19025926.hg.1", "A1BG", p_value=0.6550312)) exon_list.add_exon(Exon("PSR19025927.hg.1", "A1BG", p_value=0.5002532)) exon_list.add_exon(Exon("PSR19025928.hg.1", "A1BG", p_value=0.3521274)) exon_list.add_exon(Exon("PSR19025929.hg.1", "A1BG", p_value=0.7716908)) exon_list.add_exon(Exon("PSR19025930.hg.1", "A1BG", p_value=0.7720515)) best_exon = exon_list.best_exon('p_value') self.assertEqual(best_exon.name, "PSR19025928.hg.1")
def test_exon_no_data(self): exon = Exon("PSR19025918.hg.1", "A1BG") self.assertEqual(exon.name, "PSR19025918.hg.1") self.assertEqual(exon.gene_symbol, "A1BG") self.assertEqual(exon.log2_fold_change, None) self.assertEqual(exon.p_value, None) self.assertEqual( str(exon), "PSR19025918.hg.1:A1BG:log2FoldChange=None;p-value=None")
def test_exon_list_sort_on_p_value(self): exon_list = ExonList("A1BG") exon_list.add_exon(Exon("PSR19025918.hg.1", "A1BG", p_value=0.5347865)) exon_list.add_exon(Exon("PSR19025921.hg.1", "A1BG", p_value=0.5820691)) exon_list.add_exon(Exon("PSR19025922.hg.1", "A1BG", p_value=0.7582407)) exon_list.add_exon(Exon("PSR19025925.hg.1", "A1BG", p_value=0.4111732)) exon_list.add_exon(Exon("PSR19025926.hg.1", "A1BG", p_value=0.6550312)) exon_list.add_exon(Exon("PSR19025927.hg.1", "A1BG", p_value=0.5002532)) exon_list.add_exon(Exon("PSR19025928.hg.1", "A1BG", p_value=0.3521274)) exon_list.add_exon(Exon("PSR19025929.hg.1", "A1BG", p_value=0.7716908)) exon_list.add_exon(Exon("PSR19025930.hg.1", "A1BG", p_value=0.7720515)) exon_list.sort('p_value') last_p_value = None for exon in exon_list.exons: if last_p_value is not None: self.assertTrue(last_p_value <= exon.p_value) last_p_value = exon.p_value
def test_exon_with_data(self): log2_fold_change = -0.056323333 p_value = 0.5347865 exon = Exon("PSR19025918.hg.1", "A1BG", log2_fold_change=log2_fold_change, p_value=p_value) self.assertEqual(exon.name, "PSR19025918.hg.1") self.assertEqual(exon.gene_symbol, "A1BG") self.assertEqual(exon.log2_fold_change, log2_fold_change) self.assertEqual(exon.p_value, p_value) self.assertEqual( str(exon), "PSR19025918.hg.1:A1BG:log2FoldChange=%s;p-value=%s" % (float(log2_fold_change), float(p_value)))
def test_get_best_exons_from_log2_fold_change(self): # First example exon_list = ExonList("A1BG") exon_list.add_exon( Exon("PSR19025918.hg.1", "A1BG", log2_fold_change=-0.056323333)) exon_list.add_exon( Exon("PSR19025921.hg.1", "A1BG", log2_fold_change=0.075113333)) exon_list.add_exon( Exon("PSR19025922.hg.1", "A1BG", log2_fold_change=0.037316667)) exon_list.add_exon( Exon("PSR19025925.hg.1", "A1BG", log2_fold_change=-0.10211)) exon_list.add_exon( Exon("PSR19025929.hg.1", "A1BG", log2_fold_change=-0.02433)) best_exons = exon_list.best_exons('log2_fold_change') self.assertEqual(len(best_exons), 3) for exon, name in zip( best_exons, ("PSR19025925.hg.1", "PSR19025918.hg.1", "PSR19025929.hg.1")): self.assertEqual(name, exon.name) # Second example exon_list = ExonList("A1BG") exon_list.add_exon( Exon("PSR19025926.hg.1", "A1BG", log2_fold_change=0.059556667)) exon_list.add_exon( Exon("PSR19025927.hg.1", "A1BG", log2_fold_change=0.119746667)) exon_list.add_exon( Exon("PSR19025928.hg.1", "A1BG", log2_fold_change=-0.090296667)) exon_list.add_exon( Exon("PSR19025929.hg.1", "A1BG", log2_fold_change=-0.02433)) exon_list.add_exon( Exon("PSR19025930.hg.1", "A1BG", log2_fold_change=0.02569)) best_exons = exon_list.best_exons('log2_fold_change') self.assertEqual(len(best_exons), 3) for exon, name in zip( best_exons, ("PSR19025927.hg.1", "PSR19025926.hg.1", "PSR19025930.hg.1")): self.assertEqual(name, exon.name)
def test_average_mixed_data(self): exon_list = ExonList("A1BG") exon_list.add_exon( Exon("PSR19025918.hg.1", "A1BG", log2_fold_change=-0.056323333, data=["PSR19025918.hg.1", "A1BG", 8.0, 8.5, 9.0])) exon_list.add_exon( Exon("PSR19025921.hg.1", "A1BG", log2_fold_change=0.075113333, data=["PSR19025921.hg.1", "A1BG", 7.0, 7.0, 7.5])) exon_list.add_exon( Exon("PSR19025922.hg.1", "A1BG", log2_fold_change=0.037316667, data=["PSR19025922.hg.1", "A1BG", 7.0, 7.5, 7.0])) exon_list.add_exon( Exon("PSR19025925.hg.1", "A1BG", log2_fold_change=-0.10211, data=["PSR19025925.hg.1", "A1BG", 7.0, 7.5, 7.5])) exon_list.add_exon( Exon("PSR19025929.hg.1", "A1BG", log2_fold_change=-0.02433, data=["PSR19025929.hg.1", "A1BG", 5.0, 6.0, 6.5])) averaged_data = exon_list.average() for average, expected in zip(averaged_data, ( None, None, 6.8, 7.3, 7.5, )): self.assertEqual(average, expected)