Skip to content

Commit

Permalink
Fix #72 : Merge remote-tracking branch 'godotgildor/feature/add_locat…
Browse files Browse the repository at this point in the history
…ion_comparisons' into dev
  • Loading branch information
veghp committed Jun 3, 2023
2 parents a060a9e + 42bcee5 commit ef71dfd
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 7 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ python:
- "3.9"
# command to install dependencies
install:
- pip install coveralls pytest-cov pytest
- pip install matplotlib primer3-py genome_collector geneblocks
- sudo apt-get install ncbi-blast+ bowtie
- pip install -e .[reports]
- pip install -e .[reports,tests]
# command to run tests
script:
- python -m pytest -v --cov dnachisel --cov-report term-missing
Expand Down
10 changes: 6 additions & 4 deletions dnachisel/Location.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
The class has useful methods for finding overlaps between locations, extract
a subsequence from a sequence, etc.
"""
from functools import total_ordering

from .biotools import reverse_complement
from Bio.SeqFeature import SeqFeature, FeatureLocation


@total_ordering
class Location:
"""Represent a segment of a sequence, with a start, end, and strand.
Expand Down Expand Up @@ -93,10 +95,10 @@ def indices(self):
result = list(range(self.start, self.end))
return result if (self.strand != -1) else result[::-1]

def __geq__(self, other):
"""Greater than."""
return self.to_tuple() >= other.to_tuple()

def __eq__(self, other):
"""Equal to."""
return self.to_tuple() == other.to_tuple()
def __lt__(self, other):
"""Lower than."""
return self.to_tuple() < other.to_tuple()
Expand Down
9 changes: 9 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@
"matplotlib",
"dna_features_viewer",
"pandas",
],
"tests": [
"coveralls",
"geneblocks",
"genome_collector",
"matplotlib",
"primer3-py",
"pytest",
"pytest-cov",
]
},
)
51 changes: 51 additions & 0 deletions tests/test_Location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from dnachisel.Location import Location

import pytest

@pytest.mark.parametrize("location_1,location_2,expected_result", [
(Location(0, 1), Location(0, 1), True),
(Location(0, 1), Location(1, 1), False),
(Location(0, 1), Location(0, 1, 1), False),
(Location(0, 1, 1), Location(0, 1, 1), True),
(Location(0, 1, 0), Location(0, 1, 0), True),
(Location(0, 1), Location(1, 0), False),
(Location(0, 1), Location(1, 0, 1), False),
(Location(0, 1), Location(1, 0, 0), False),
]
)
def test___eq__(location_1: Location, location_2: Location, expected_result: bool):
assert (location_1 == location_2) == expected_result

@pytest.mark.parametrize("location_1,location_2,expected_result", [
(Location(0, 1), Location(0, 1), True),
(Location(0, 1), Location(1, 1), False),
(Location(1, 0), Location(0, 1), True),
(Location(1, 0, 1), Location(1, 0), True),
(Location(0, 1), Location(0, 1, 1), False),
(Location(0, 1, 1), Location(0, 1), True),
(Location(0, 1, 1), Location(0, 1, 1), True),
(Location(0, 1, 0), Location(0, 1, 0), True),
(Location(0, 1), Location(1, 0), False),
(Location(0, 1), Location(1, 0, 1), False),
(Location(0, 1), Location(1, 0, 0), False),
]
)
def test___ge__(location_1: Location, location_2: Location, expected_result: bool):
assert (location_1 >= location_2) == expected_result

@pytest.mark.parametrize("location_1,location_2,expected_result", [
(Location(0, 1), Location(0, 1), False),
(Location(0, 1), Location(1, 1), True),
(Location(1, 0), Location(0, 1), False),
(Location(1, 0, 1), Location(1, 0), False),
(Location(0, 1), Location(0, 1, 1), True),
(Location(0, 1, 1), Location(0, 1), False),
(Location(0, 1, 1), Location(0, 1, 1), False),
(Location(0, 1, 0), Location(0, 1, 0), False),
(Location(0, 1), Location(1, 0), True),
(Location(0, 1), Location(1, 0, 1), True),
(Location(0, 1), Location(1, 0, 0), True),
]
)
def test___lt__(location_1: Location, location_2: Location, expected_result: bool):
assert (location_1 < location_2) == expected_result

0 comments on commit ef71dfd

Please sign in to comment.