Skip to content

Commit

Permalink
add test_get_cds_with_domains test
Browse files Browse the repository at this point in the history
fix tests no longer using sortedlist
  • Loading branch information
adraismawur committed Aug 22, 2023
1 parent e0d5366 commit 4da45b9
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 41 deletions.
32 changes: 16 additions & 16 deletions test/comparison/test_comparable_region.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,24 @@ def test_get_dom_list_lcs(self):
for a_domain in a_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
cds_a.hsps.add(HSP(cds_a, a_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, a_domain, 100, 0, 30))

gbk_b = GBK("", "")
gbk_b.region = Region(gbk_b, 0, 0, 100, False, "")

for b_domain in b_domains:
cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
cds_b.hsps.add(HSP(cds_b, b_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, b_domain, 100, 0, 30))

for shared_domain in shared_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
cds_a.hsps.add(HSP(cds_a, shared_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, shared_domain, 100, 0, 30))

cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
cds_b.hsps.add(HSP(cds_b, shared_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, shared_domain, 100, 0, 30))

pair = BGCPair(gbk_a.region, gbk_b.region)

Expand Down Expand Up @@ -83,24 +83,24 @@ def test_get_dom_list_lcs_reverse(self):
for a_domain in a_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
cds_a.hsps.add(HSP(cds_a, a_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, a_domain, 100, 0, 30))

gbk_b = GBK("", "")
gbk_b.region = Region(gbk_b, 0, 0, 100, False, "")

for b_domain in b_domains:
cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
cds_b.hsps.add(HSP(cds_b, b_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, b_domain, 100, 0, 30))

for shared_domain in shared_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
cds_a.hsps.add(HSP(cds_a, shared_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, shared_domain, 100, 0, 30))

cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
cds_b.hsps.add(HSP(cds_b, shared_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, shared_domain, 100, 0, 30))

# reverse the b genes
gbk_b.genes = gbk_b.genes[::-1]
Expand Down Expand Up @@ -149,22 +149,22 @@ def test_cds_range_contains_biosyntetic_true(self):
record = Region(gbk, 0, 0, 0, False, "")

non_bio_cds_1 = CDS(0, 25)
non_bio_cds_1.hsps.add(HSP(non_bio_cds_1, "test", 100.0, 0, 25))
non_bio_cds_1.hsps.append(HSP(non_bio_cds_1, "test", 100.0, 0, 25))
non_bio_cds_1.gene_kind = ""
gbk.genes.append(non_bio_cds_1)

non_bio_cds_2 = CDS(25, 50)
non_bio_cds_2.hsps.add(HSP(non_bio_cds_2, "test", 100.0, 0, 25))
non_bio_cds_2.hsps.append(HSP(non_bio_cds_2, "test", 100.0, 0, 25))
non_bio_cds_2.gene_kind = ""
gbk.genes.append(non_bio_cds_2)

non_bio_cds_3 = CDS(50, 75)
non_bio_cds_3.hsps.add(HSP(non_bio_cds_3, "test", 100.0, 0, 25))
non_bio_cds_3.hsps.append(HSP(non_bio_cds_3, "test", 100.0, 0, 25))
non_bio_cds_3.gene_kind = ""
gbk.genes.append(non_bio_cds_3)

bio_cds_1 = CDS(75, 100)
bio_cds_1.hsps.add(HSP(bio_cds_1, "test", 100.0, 0, 25))
bio_cds_1.hsps.append(HSP(bio_cds_1, "test", 100.0, 0, 25))
bio_cds_1.gene_kind = "biosynthetic"
gbk.genes.append(bio_cds_1)

Expand Down Expand Up @@ -233,7 +233,7 @@ def test_get_domain_dicts(self):
gbk_a.genes.append(cds_a)
env_start = len(gbk_a.genes) * 10
env_stop = env_start + 10
cds_a.hsps.add(HSP(cds_a, a_domain, 100, env_start, env_stop))
cds_a.hsps.append(HSP(cds_a, a_domain, 100, env_start, env_stop))

gbk_b = GBK("", "")
gbk_b.region = Region(gbk_b, 0, 0, 100, False, "")
Expand All @@ -243,20 +243,20 @@ def test_get_domain_dicts(self):
gbk_b.genes.append(cds_b)
env_start = len(gbk_b.genes) * 10
env_stop = env_start + 10
cds_b.hsps.add(HSP(cds_b, b_domain, 100, env_start, env_stop))
cds_b.hsps.append(HSP(cds_b, b_domain, 100, env_start, env_stop))

for shared_domain in shared_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
env_start = len(gbk_a.genes) * 10
env_stop = env_start + 10
cds_a.hsps.add(HSP(cds_a, shared_domain, 100, env_start, env_stop))
cds_a.hsps.append(HSP(cds_a, shared_domain, 100, env_start, env_stop))

cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
env_start = len(gbk_b.genes) * 10
env_stop = env_start + 10
cds_b.hsps.add(HSP(cds_b, shared_domain, 100, env_start, env_stop))
cds_b.hsps.append(HSP(cds_b, shared_domain, 100, env_start, env_stop))

pair = BGCPair(gbk_a.region, gbk_b.region)

Expand Down
4 changes: 2 additions & 2 deletions test/comparison/test_legacy_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ def test_legacy_expand(self):
target_cds_list = []
for target_domain in target_domains:
target_cds = CDS(0, 10)
target_cds.hsps.add(HSP(target_cds, target_domain, 100, 0, 10))
target_cds.hsps.append(HSP(target_cds, target_domain, 100, 0, 10))
target_cds_list.append(target_cds)

query_cds_list = []
for query_domain in query_domains:
query_cds = CDS(0, 10)
query_cds.hsps.add(HSP(query_cds, query_domain, 100, 0, 10))
query_cds.hsps.append(HSP(query_cds, query_domain, 100, 0, 10))
query_cds_list.append(query_cds)

actual_results = expand_score(
Expand Down
36 changes: 18 additions & 18 deletions test/comparison/test_scores.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ def test_full_overlap_pair(self):
for a_domain in a_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
cds_a.hsps.add(HSP(cds_a, a_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, a_domain, 100, 0, 30))

gbk_b = GBK("", "")
gbk_b.region = Region(gbk_b, 0, 0, 100, False, "")

for b_domain in b_domains:
cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
cds_b.hsps.add(HSP(cds_b, b_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, b_domain, 100, 0, 30))

for shared_domain in shared_domains:
cds_a = CDS(10, 90)
Expand All @@ -85,8 +85,8 @@ def test_full_overlap_pair(self):
gbk_a.genes.append(cds_a)
gbk_b.genes.append(cds_b)

cds_a.hsps.add(HSP(cds_a, shared_domain, 100, 0, 30))
cds_b.hsps.add(HSP(cds_b, shared_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, shared_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, shared_domain, 100, 0, 30))

pair = BGCPair(gbk_a.region, gbk_b.region)

Expand Down Expand Up @@ -118,15 +118,15 @@ def test_partial_overlap_pair(self):
for a_domain in a_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
cds_a.hsps.add(HSP(cds_a, a_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, a_domain, 100, 0, 30))

gbk_b = GBK("", "")
gbk_b.region = Region(gbk_b, 0, 0, 100, False, "")

for b_domain in b_domains:
cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
cds_b.hsps.add(HSP(cds_b, b_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, b_domain, 100, 0, 30))

for shared_domain in shared_domains:
cds_a = CDS(10, 90)
Expand All @@ -135,8 +135,8 @@ def test_partial_overlap_pair(self):
gbk_a.genes.append(cds_a)
gbk_b.genes.append(cds_b)

cds_a.hsps.add(HSP(cds_a, shared_domain, 100, 0, 30))
cds_b.hsps.add(HSP(cds_b, shared_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, shared_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, shared_domain, 100, 0, 30))

pair = BGCPair(gbk_a.region, gbk_b.region)

Expand Down Expand Up @@ -167,7 +167,7 @@ def test_no_overlap_pair(self):
for a_domain in a_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
cds_a.hsps.add(HSP(cds_a, a_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, a_domain, 100, 0, 30))

gbk_b = GBK("", "")
gbk_b.region = Region(gbk_b, 0, 0, 100, False, "")
Expand All @@ -176,7 +176,7 @@ def test_no_overlap_pair(self):
for b_domain in b_domains:
cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
cds_b.hsps.add(HSP(cds_b, b_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, b_domain, 100, 0, 30))

pair = BGCPair(gbk_a.region, gbk_b.region)

Expand Down Expand Up @@ -279,8 +279,8 @@ def test_all_adjacent_pair(self):
gbk_a.genes.append(cds_a)
gbk_b.genes.append(cds_b)

cds_a.hsps.add(HSP(cds_a, shared_domain, 100, 0, 30))
cds_b.hsps.add(HSP(cds_b, shared_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, shared_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, shared_domain, 100, 0, 30))

pair = BGCPair(gbk_a.region, gbk_b.region)

Expand Down Expand Up @@ -310,12 +310,12 @@ def test_get_distance_from_unshared_none(self):
for a_domain in a_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
cds_a.hsps.add(HSP(cds_a, a_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, a_domain, 100, 0, 30))

for b_domain in b_domains:
cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
cds_b.hsps.add(HSP(cds_b, b_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, b_domain, 100, 0, 30))

pair = BGCPair(gbk_a.region, gbk_b.region)

Expand All @@ -342,12 +342,12 @@ def test_get_distance_from_unshared_no_anchor(self):
for a_domain in a_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
cds_a.hsps.add(HSP(cds_a, a_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, a_domain, 100, 0, 30))

for b_domain in b_domains:
cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
cds_b.hsps.add(HSP(cds_b, b_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, b_domain, 100, 0, 30))

pair = BGCPair(gbk_a.region, gbk_b.region)

Expand Down Expand Up @@ -375,12 +375,12 @@ def test_get_distance_from_unshared_full(self):
for a_domain in a_domains:
cds_a = CDS(10, 90)
gbk_a.genes.append(cds_a)
cds_a.hsps.add(HSP(cds_a, a_domain, 100, 0, 30))
cds_a.hsps.append(HSP(cds_a, a_domain, 100, 0, 30))

for b_domain in b_domains:
cds_b = CDS(10, 90)
gbk_b.genes.append(cds_b)
cds_b.hsps.add(HSP(cds_b, b_domain, 100, 0, 30))
cds_b.hsps.append(HSP(cds_b, b_domain, 100, 0, 30))

pair = BGCPair(gbk_a.region, gbk_b.region)

Expand Down
31 changes: 30 additions & 1 deletion test/genbank/test_bgc_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def test_get_hsps(self):
gbk.genes.append(cds)

for domain in domains:
cds.hsps.add(HSP(cds, domain, 100, 0, 30))
cds.hsps.append(HSP(cds, domain, 100, 0, 30))

expected_domains = domains

Expand All @@ -96,3 +96,32 @@ def test_get_hsps(self):
actual_domains = [hsp.domain for hsp in hsps]

self.assertEqual(expected_domains, actual_domains)

def test_get_cds_with_domains(self):
"""Tests whether the test_get_cds_with_domains method correctly retrieves a
subset of CDS containing only domains
"""
cds_list = [
CDS(0, 100),
CDS(0, 100),
CDS(0, 100),
CDS(0, 100),
CDS(0, 100),
CDS(0, 100),
CDS(0, 100),
]

cds_list[0].hsps = [HSP(cds_list[0], "test", 1.0, 0, 100)]
cds_list[2].hsps = [HSP(cds_list[0], "test", 1.0, 0, 100)]
cds_list[4].hsps = [HSP(cds_list[0], "test", 1.0, 0, 100)]
cds_list[6].hsps = [HSP(cds_list[0], "test", 1.0, 0, 100)]

gbk = GBK("", "test")
gbk.genes = cds_list
region = BGCRecord(gbk, 0, 0, 100, False, "")


expected_cds_count = 4
actual_cds_count = len(region.get_cds_with_domains())

self.assertEqual(expected_cds_count, actual_cds_count)
8 changes: 4 additions & 4 deletions test/genbank/test_cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def test_add_hsp_overlap_filter(self):

cds.add_hsp_overlap_filter(new_hsp)

expected_result = SortedSet([new_hsp])
expected_result = [new_hsp]

actual_result = cds.hsps

Expand All @@ -186,7 +186,7 @@ def test_add_hsp_overlap_filter_keep_old(self):

cds.add_hsp_overlap_filter(new_hsp)

expected_result = SortedSet([old_hsp])
expected_result = [old_hsp]

actual_result = cds.hsps

Expand All @@ -208,7 +208,7 @@ def test_add_hsp_overlap_filter_keep_new(self):

cds.add_hsp_overlap_filter(new_hsp)

expected_result = SortedSet([new_hsp])
expected_result = [new_hsp]

actual_result = cds.hsps

Expand All @@ -230,7 +230,7 @@ def test_add_hsp_overlap_filter_keep_new_same_bitscore(self):

cds.add_hsp_overlap_filter(new_hsp)

expected_result = SortedSet([new_hsp])
expected_result = [new_hsp]

actual_result = cds.hsps

Expand Down

0 comments on commit 4da45b9

Please sign in to comment.