Skip to content

Commit

Permalink
rename check_nonhiv to is_nonhiv and check_scramble to is_scrambled
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Jun 5, 2023
1 parent 5f82fcc commit 11a6003
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions intact/intact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions tests/test_nonhiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
48 changes: 24 additions & 24 deletions tests/test_scramble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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

Expand All @@ -41,96 +41,96 @@ 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"),
BlastRow(sstart=880, send=890, qstart=25, sstrand="plus"),
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"),
BlastRow(sstart=880, send=890, qstart=25, sstrand="plus"),
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"),
Expand All @@ -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

0 comments on commit 11a6003

Please sign in to comment.