Skip to content

Commit

Permalink
closes #160
Browse files Browse the repository at this point in the history
  • Loading branch information
manulera committed Nov 24, 2023
1 parent 3385265 commit 7ce1881
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/pydna/dseqrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,12 @@ def __getitem__(self, sl):
answer.features = super().__getitem__(sl).features
elif self.circular and sl_start > sl_stop:
answer.features = self.shifted(sl_start).features
answer.features = [f for f in answer.features if f.location.parts[-1].end <= answer.seq.length]
# origin-spanning features should only be included after shifting
# in cases where the slice comprises the entire sequence, but then
# sl_start == sl_stop and the second condition is not met
answer.features = [f for f in answer.features if (
f.location.parts[-1].end <= answer.seq.length and
f.location.parts[0].start <= f.location.parts[-1].end)]
else:
answer = Dseqrecord("")
identifier = "part_{id}".format(id=self.id)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_module_dseqrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,7 @@ def test__repr_pretty_():

def test___getitem__():
from pydna.dseqrecord import Dseqrecord
from Bio.SeqFeature import SeqFeature, SimpleLocation

s = Dseqrecord("GGATCC", circular=False)
assert s[1:-1].seq == Dseqrecord("GATC", circular=False).seq
Expand All @@ -1868,6 +1869,19 @@ def test___getitem__():
assert t[9:10].seq == Dseqrecord("").seq
assert t[10:9].seq == Dseqrecord("").seq

# Test how slicing works with features (using sequence as in test_features_change_ori)
seqRecord = Dseqrecord("aaagGTACCTTTGGATCcggg", circular=True)
f1 = SeqFeature(SimpleLocation(4, 17), type="misc_feature", strand=1)
f2 = SeqFeature(SimpleLocation(17, 21, 1) + SimpleLocation(0, 4), type="misc_feature", strand=1)
seqRecord.features = [f1, f2]

# Exact feature sliced for normal and origin-spanning features
assert len(seqRecord[4:17].features) == 1
assert len(seqRecord[17:4].features) == 1

# Partial feature sliced for normal and origin-spanning features
assert len(seqRecord[2:20].features) == 1
assert len(seqRecord[13:8].features) == 1

def test___eq__():
from pydna.dseqrecord import Dseqrecord
Expand Down

0 comments on commit 7ce1881

Please sign in to comment.