diff --git a/intact/intact.py b/intact/intact.py index 7e9c55a..5ee2932 100644 --- a/intact/intact.py +++ b/intact/intact.py @@ -143,7 +143,7 @@ def is_sorted(lst): return True -def check_scramble(seqid, blast_rows): +def is_scrambled(seqid, blast_rows): # HIV 5' region can easily map to its 3' region because they are identical. # Such a maping would not constitute a scramble, so we ignore the 5' region for this check. ignored_5_prime = [x for x in blast_rows if x.sstart > 622 and x.send > 622] @@ -173,7 +173,7 @@ def check_scramble(seqid, blast_rows): f"Sequence is {direction}-scrambled.") -def check_nonhiv(seqid, blast_rows): +def is_nonhiv(seqid, blast_rows): aligned_length = sum(abs(x.qend - x.qstart) + 1 for x in blast_rows) total_length = blast_rows[0].qlen if blast_rows else 1 ratio = aligned_length / total_length diff --git a/tests/test_nonhiv.py b/tests/test_nonhiv.py index 10d4583..4f613ca 100644 --- a/tests/test_nonhiv.py +++ b/tests/test_nonhiv.py @@ -3,7 +3,7 @@ import os import intact.intact as intact -from intact.intact import check_scramble, check_nonhiv, IntactnessError +from intact.intact import is_nonhiv, IntactnessError class BlastRow: def __init__(self, qstart, qend, qlen): @@ -12,44 +12,44 @@ def __init__(self, qstart, qend, qlen): self.qlen = qlen -def test_check_nonhiv_empty_blast_rows(): +def test_is_nonhiv_empty_blast_rows(): blast_rows = [] - result = check_nonhiv("id", blast_rows) + result = is_nonhiv("id", blast_rows) assert isinstance(result, IntactnessError) assert result.error == intact.NONHIV_ERROR -def test_check_nonhiv_low_ratio(): +def test_is_nonhiv_low_ratio(): blast_rows = [ BlastRow(0, 100, 1000), BlastRow(200, 300, 1000), BlastRow(400, 500, 1000) ] - result = check_nonhiv("id", blast_rows) + result = is_nonhiv("id", blast_rows) assert isinstance(result, IntactnessError) assert result.error == intact.NONHIV_ERROR -def test_check_nonhiv_high_ratio(): +def test_is_nonhiv_high_ratio(): blast_rows = [ BlastRow(0, 200, 1000), BlastRow(200, 400, 1000), BlastRow(400, 900, 1000) ] - assert check_nonhiv("id", blast_rows) is None + assert is_nonhiv("id", blast_rows) is None -def test_check_nonhiv_high_ratio_reversed(): +def test_is_nonhiv_high_ratio_reversed(): blast_rows = [ BlastRow(0, 200, 1000), BlastRow(200, 400, 1000), BlastRow(900, 400, 1000) ] - assert check_nonhiv("id", blast_rows) is None + assert is_nonhiv("id", blast_rows) is None -def test_check_nonhiv_single_blast_row(): +def test_is_nonhiv_single_blast_row(): blast_rows = [BlastRow(0, 200, 1000)] - result = check_nonhiv("id", blast_rows) + result = is_nonhiv("id", blast_rows) assert isinstance(result, IntactnessError) assert result.error == intact.NONHIV_ERROR diff --git a/tests/test_scramble.py b/tests/test_scramble.py index 00371d8..83b7245 100644 --- a/tests/test_scramble.py +++ b/tests/test_scramble.py @@ -3,7 +3,7 @@ import os import intact.intact as intact -from intact.intact import check_scramble, check_nonhiv, IntactnessError +from intact.intact import is_scrambled, is_nonhiv, IntactnessError @pytest.mark.parametrize("lst, expected", [ ([1, 2, 3, 4, 5], True), @@ -30,7 +30,7 @@ def test_is_sorted(lst, expected): # print("\n\n\n") # print("---------------------------") # print(v[0].qseqid) -# print(intact.check_scramble(v)) +# print(intact.is_scrambled(v)) # assert False @@ -41,39 +41,39 @@ def __init__(self, sstart, send, qstart, sstrand): self.qstart = qstart self.sstrand = sstrand -def test_check_scramble_no_alignment(): +def test_is_scrambled_no_alignment(): # Test case where there is no alignment blast_rows = [] - assert check_scramble("id", blast_rows) is None + assert is_scrambled("id", blast_rows) is None -def test_check_scramble_internal_inversion(): +def test_is_scrambled_internal_inversion(): # Test case where some parts of the sequence are aligned in forward direction # and some in reverse, indicating an internal inversion error. blast_rows = [ BlastRow(sstart=900, send=910, qstart=5, sstrand="plus"), BlastRow(sstart=930, send=940, qstart=25, sstrand="minus"), ] - result = check_scramble("id", blast_rows) + result = is_scrambled("id", blast_rows) assert isinstance(result, IntactnessError) assert result.error == intact.INTERNALINVERSION_ERROR -def test_check_scramble_plus_strand_sorted(): +def test_is_scrambled_plus_strand_sorted(): # Test case where the direction is "plus" and the sstart values are sorted. blast_rows = [ BlastRow(sstart=900, send=910, qstart=5, sstrand="plus"), BlastRow(sstart=930, send=940, qstart=25, sstrand="plus"), ] - assert check_scramble("id", blast_rows) is None + assert is_scrambled("id", blast_rows) is None -def test_check_scramble_minus_strand_sorted(): +def test_is_scrambled_minus_strand_sorted(): # Test case where the direction is "minus" and the send values are sorted in reverse order. blast_rows = [ BlastRow(sstart=910, send=900, qstart=25, sstrand="minus"), BlastRow(sstart=940, send=930, qstart=5, sstrand="minus"), ] - assert check_scramble("id", blast_rows) is None + assert is_scrambled("id", blast_rows) is None -def test_check_scramble_plus_strand_unsorted(): +def test_is_scrambled_plus_strand_unsorted(): # Test case with mixed directions and inversions blast_rows = [ BlastRow(sstart=700, send=700, qstart=99, sstrand="plus"), @@ -81,11 +81,11 @@ def test_check_scramble_plus_strand_unsorted(): BlastRow(sstart=920, send=930, qstart=45, sstrand="plus"), BlastRow(sstart=950, send=980, qstart=85, sstrand="plus"), ] - result = check_scramble("id", blast_rows) + result = is_scrambled("id", blast_rows) assert isinstance(result, IntactnessError) assert result.error == intact.SCRAMBLE_ERROR -def test_check_scramble_plus_strand_unsorted_5prime(): +def test_is_scrambled_plus_strand_unsorted_5prime(): # Test case with mixed directions and inversions blast_rows = [ BlastRow(sstart=100, send=110, qstart=99, sstrand="plus"), @@ -93,44 +93,44 @@ def test_check_scramble_plus_strand_unsorted_5prime(): BlastRow(sstart=920, send=930, qstart=45, sstrand="plus"), BlastRow(sstart=950, send=980, qstart=85, sstrand="plus"), ] - assert check_scramble("id", blast_rows) == None + assert is_scrambled("id", blast_rows) == None -def test_check_scramble_minus_strand_unsorted(): +def test_is_scrambled_minus_strand_unsorted(): # Test case where the direction is "minus" but the send values are not sorted in reverse order. blast_rows = [ BlastRow(sstart=910, send=900, qstart=5, sstrand="minus"), BlastRow(sstart=940, send=930, qstart=25, sstrand="minus"), ] - result = check_scramble("id", blast_rows) + result = is_scrambled("id", blast_rows) assert isinstance(result, IntactnessError) assert result.error == intact.SCRAMBLE_ERROR -def test_check_scramble_mixed_direction(): +def test_is_scrambled_mixed_direction(): # Test case where some rows have "plus" direction and some have "minus" direction. blast_rows = [ BlastRow(sstart=900, send=910, qstart=5, sstrand="plus"), BlastRow(sstart=930, send=940, qstart=25, sstrand="minus"), BlastRow(sstart=950, send=990, qstart=45, sstrand="minus"), ] - result = check_scramble("id", blast_rows) + result = is_scrambled("id", blast_rows) assert isinstance(result, IntactnessError) assert result.error == intact.INTERNALINVERSION_ERROR -def test_check_scramble_single_row_plus_strand(): +def test_is_scrambled_single_row_plus_strand(): # Test case with a single row aligned in the "plus" strand blast_rows = [ BlastRow(sstart=700, send=710, qstart=5, sstrand="plus"), ] - assert check_scramble("id", blast_rows) is None + assert is_scrambled("id", blast_rows) is None -def test_check_scramble_single_row_minus_strand(): +def test_is_scrambled_single_row_minus_strand(): # Test case with a single row aligned in the "minus" strand blast_rows = [ BlastRow(sstart=900, send=910, qstart=5, sstrand="minus"), ] - assert check_scramble("id", blast_rows) is None + assert is_scrambled("id", blast_rows) is None -def test_check_scramble_multiple_directions_and_inversions(): +def test_is_scrambled_multiple_directions_and_inversions(): # Test case with mixed directions and inversions blast_rows = [ BlastRow(sstart=900, send=910, qstart=5, sstrand="plus"), @@ -139,6 +139,6 @@ def test_check_scramble_multiple_directions_and_inversions(): BlastRow(sstart=850, send=880, qstart=85, sstrand="plus"), BlastRow(sstart=890, send=880, qstart=85, sstrand="minus"), ] - result = check_scramble("id", blast_rows) + result = is_scrambled("id", blast_rows) assert isinstance(result, IntactnessError) assert result.error == intact.INTERNALINVERSION_ERROR