def test_translate_to(): exons = [] for i, pair in enumerate([(5, 10), (20, 30), (50, 80)]): exons.append(Exon(f"e{i}", "chr1", pair[0], pair[1], 0, 0, '-', None)) t = dict() t["muid"] = Transcript("muid", "source", "mRNA", "chr1", 5, 80, '-', 0, exons, exons, None, None, dict()) g = Gene("guid", "source", "chr1", t["muid"].start, t["muid"].end, t["muid"].strand, t["muid"].score, t, [], dict()) new_start = 1000 assert g.chrom == "chr1" assert t["muid"].chrom == "chr1" assert t["muid"].exons[0].chrom == "chr1" g.translate_to(new_start) assert g.chrom == "chr1" assert t["muid"].chrom == "chr1" assert t["muid"].exons[0].chrom == "chr1" g.translate_to(new_start, "other") assert g.chrom == "other" assert g.start == new_start assert g.end == 1075 assert t["muid"].start == new_start assert t["muid"].end == 1075 assert t["muid"].chrom == "other" assert t["muid"].exons[0].start == 1045 assert t["muid"].exons[0].end == 1075 assert t["muid"].exons[0].chrom == "other" assert t["muid"].css == 1075 assert t["muid"].ces == 1000 exons = [] for i, pair in enumerate([(5, 10), (20, 30), (50, 80)]): exons.append(Exon(f"e{i}", "chr1", pair[0], pair[1], 0, 0, '+', None)) t = dict() t["muid"] = Transcript("muid", "source", "mRNA", "chr1", 5, 80, '+', 0, exons, exons, None, None, dict()) g = Gene("guid", "source", "chr1", t["muid"].start, t["muid"].end, t["muid"].strand, t["muid"].score, t, [], dict()) new_start = 1000 g.translate_to(new_start, "other2") assert g.chrom == "other2" assert g.start == new_start assert g.end == 1075 assert t["muid"].start == new_start assert t["muid"].end == 1075 assert t["muid"].chrom == "other2" assert t["muid"].exons[0].start == 1000 assert t["muid"].exons[0].end == 1005 assert t["muid"].exons[0].chrom == "other2" assert t["muid"].css == 1000 assert t["muid"].ces == 1075
def test_merge_exons(): exons = [] for i, pair in enumerate([(5, 10), (12, 30), (50, 80)]): exons.append(Exon(f"e{i}", "chr1", pair[0], pair[1], 0, 0, '-', None)) t = dict() t["muid"] = Transcript("muid", "source", "mRNA", "chr1", 5, 80, '-', 0, exons, exons, None, None, dict()) g = Gene("guid", "source", "chr1", t["muid"].start, t["muid"].end, t["muid"].strand, t["muid"].score, t, [], dict()) for e, p in zip(t['muid'].exons, reversed([(5, 10), (12, 30), (50, 80)])): assert (e.start, e.end) == p assert len(g.mrnas["muid"].exons) == 3 g.mrnas["muid"].merge_exons() for e, p in zip(g.mrnas['muid'].exons, reversed([(5, 30), (50, 80)])): assert (e.start, e.end) == p assert len(g.mrnas["muid"].exons) == 2 exons = [] for i, pair in enumerate([(5, 10), (20, 48), (50, 80)]): exons.append(Exon(f"e{i}", "chr1", pair[0], pair[1], 0, 0, '+', None)) t = dict() t["muid"] = Transcript("muid", "source", "mRNA", "chr1", 5, 80, '+', 0, exons, exons, None, None, dict()) g = Gene("guid", "source", "chr1", t["muid"].start, t["muid"].end, t["muid"].strand, t["muid"].score, t, [], dict()) assert len(g.mrnas["muid"].exons) == 3 g.mrnas["muid"].merge_exons() merged_exons = [(5, 10), (20, 80)] for e, p in zip(g.mrnas['muid'].exons, merged_exons): assert (e.start, e.end) == p assert len(g.mrnas["muid"].exons) == 2 exons = [] for i, pair in enumerate([(5, 15), (16, 48), (50, 80), (83, 95)]): exons.append(Exon(f"e{i}", "chr1", pair[0], pair[1], 0, 0, '+', None)) t = dict() t["muid"] = Transcript("muid", "source", "mRNA", "chr1", 5, 80, '+', 0, exons, exons, None, None, dict()) g = Gene("guid", "source", "chr1", t["muid"].start, t["muid"].end, t["muid"].strand, t["muid"].score, t, [], dict()) assert len(t['muid'].exons) == 4 t['muid'].merge_exons() assert len(t['muid'].exons) == 1 assert t['muid'].exons[0].start, t['muid'].exons[0].end == (5, 95)
def test_change_id(): exons = [] for i, pair in enumerate([(5, 10), (20, 30), (50, 80)]): exons.append(Exon(f"e{i}", "chr1", pair[0], pair[1], 0, 0, '-', None)) t = dict() t["muid"] = Transcript("muid", "source", "mRNA", "chr1", 5, 80, '-', 0, exons, exons, None, None, {"Parent": ["guid"]}) g = Gene("guid", "source", "chr1", t["muid"].start, t["muid"].end, t["muid"].strand, t["muid"].score, t, [], dict()) assert g.uid == "guid" assert g.mrnas["muid"].uid == "muid" assert len(g.mrnas["muid"].attr["Parent"]) == 1 assert "guid" in g.mrnas["muid"].attr["Parent"] g.change_id("guid2") assert g.uid == "guid2" assert g.mrnas["muid"].uid == "muid" assert len(g.mrnas["muid"].attr["Parent"]) == 1 assert "guid2" in g.mrnas["muid"].attr["Parent"]
def test_gene_equality(): g = Gene("uid", "source", "chr1", 0, 10, '+', 0, dict(), dict(), dict()) assert g == Gene("uid", "source", "chr1", 0, 10, '+', 0, dict(), dict(), dict()) assert g != Gene("uid", "source", "chr1", 2, 10, '+', 0, dict(), dict(), dict()) exons = [] for i, pair in enumerate([(5, 10), (20, 30), (50, 80)]): exons.append(Exon(f"e{i}", "chr1", pair[0], pair[1], 0, 0, '-', None)) t = dict() t["muid"] = Transcript("muid", "source", "mRNA", "chr1", 5, 80, '-', 0, exons, exons, None, None, dict()) assert g != Gene("uid", "source", "chr1", 0, 10, '+', 0, t, dict(), dict()) exons = [] for i, pair in enumerate([(5, 10), (20, 30), (50, 82)]): exons.append(Exon(f"e{i}", "chr1", pair[0], pair[1], 0, 0, '-', None)) t2 = dict() t2["muid2"] = Transcript("muid2", "source", "mRNA", "chr1", 5, 82, '-', 0, exons, exons, None, None, dict()) assert Gene("uid", "source", "chr1", 0, 10, '+', 0, t, dict(), dict()) != Gene("uid", "source", "chr1", 0, 10, '+', 0, t2, dict(), dict())
def test_extending_five_prime_end(): exons = [] for i, pair in enumerate([(5, 10), (20, 30), (50, 80)]): exons.append(Exon(f"e{i}", "chr1", pair[0], pair[1], 0, 0, '-', None)) t = dict() t["muid"] = Transcript("muid", "source", "mRNA", "chr1", 5, 80, '-', 0, exons, exons, None, None, dict()) g = Gene("guid", "source", "chr1", t["muid"].start, t["muid"].end, t["muid"].strand, t["muid"].score, t, [], dict()) assert g.end == 80 assert t["muid"].end == 80 assert exons[0].end == 80 assert t["muid"].css == 80 g.extend_five_prime_end_cds("muid", 3) assert g.end == 83 assert t["muid"].end == 83 assert exons[0].end == 83 assert t["muid"].css == 83 exons = [] for i, pair in enumerate([(5, 10), (20, 30), (50, 80)]): exons.append(Exon(f"e{i}", "chr1", pair[0], pair[1], 0, 0, '+', None)) t = dict() t["muid"] = Transcript("muid", "source", "mRNA", "chr1", 5, 80, '+', 0, exons, exons, None, None, dict()) g = Gene("guid", "source", "chr1", t["muid"].start, t["muid"].end, t["muid"].strand, t["muid"].score, t, [], dict()) assert g.start == 5 assert t["muid"].start == 5 assert exons[0].start == 5 assert t["muid"].css == 5 g.extend_five_prime_end_cds("muid", 3) assert g.start == 2 assert t["muid"].start == 2 assert exons[0].start == 2 assert t["muid"].css == 2
def test_gene_lt(): g = Gene("uid", "source", "chr1", 0, 10, '+', 0, dict(), dict(), dict()) assert g < Gene("uid", "source", "chr1", 10, 20, '+', 0, dict(), dict(), dict())
def test_gene_hashable(): g = Gene("uid", "source", "chr1", 0, 10, '+', 0, dict(), dict(), dict()) d = dict() d[g] = "test" assert d[g] == "test"