Skip to content

Commit

Permalink
closes #161
Browse files Browse the repository at this point in the history
  • Loading branch information
manulera committed Jan 30, 2024
1 parent bc13e92 commit 28da1d8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/pydna/dseqrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,9 @@ def __getitem__(self, sl):
answer.features = [f for f in answer.features if (
_location_boundaries(f.location)[1] <= answer.seq.length and
_location_boundaries(f.location)[0] <= _location_boundaries(f.location)[1])]
elif self.circular and sl_start == sl_stop:
cut = ((sl_start, 0), None)
return self.apply_cut(cut, cut)
else:
answer = Dseqrecord("")
identifier = "part_{id}".format(id=self.id)
Expand Down
17 changes: 15 additions & 2 deletions tests/test_module_dseq.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,12 @@ def test_Dseq___getitem__():
assert s[9:1] == Dseq("")
assert t[9:1] == Dseq("")

# Indexing of full circular molecule (https://github.com/BjornFJohansson/pydna/issues/161)
s = Dseq("GGATCC", circular=True)
str_seq = str(s)
for shift in range(len(s)):
assert str(s[shift : shift]) == str_seq[shift:] + str_seq[:shift]


def test_cut_circular():
from pydna.dseq import Dseq
Expand Down Expand Up @@ -890,16 +896,23 @@ def test_apply_cut():
if start < 0:
start += len(seq)
# Cut with negative ovhg
new_cut = (( start, -3), None)
new_cut = ((start, -3), None)
out = seq_shifted.apply_cut(new_cut, new_cut)
assert str(out) == 'ATGaattacgtATG'

# Cut with positive ovhg
start = (start + 3) % len(seq)
new_cut = (( start, 3), None)
new_cut = ((start, 3), None)
out = seq_shifted.apply_cut(new_cut, new_cut)
assert str(out) == 'ATGaattacgtATG'

# A blunt cut
start = 4 - shift
new_cut = ((start, 0), None)
out = seq_shifted.apply_cut(new_cut, new_cut)
assert str(out) == 'ATGaattacgt'


def test_cutsite_is_valid():

from pydna.dseq import Dseq
Expand Down
12 changes: 9 additions & 3 deletions tests/test_module_dseqrecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -1867,7 +1867,7 @@ def test___getitem__():
assert s[1:5].seq == Dseqrecord("GATC", circular=False).seq
assert s[5:1:-1].seq == Dseqrecord("CCTA", circular=False).seq

assert t[1:1].seq == Dseqrecord("").seq
assert t[1:1].seq == Dseqrecord("GATCCG").seq
assert t[5:1].seq == Dseqrecord("CG", circular=False).seq
assert t[9:1].seq == Dseqrecord("").seq
assert t[1:9].seq == Dseqrecord("").seq
Expand All @@ -1876,8 +1876,8 @@ def test___getitem__():

# 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)
f1 = SeqFeature(SimpleLocation(4, 17, 1), type="misc_feature")
f2 = SeqFeature(SimpleLocation(17, 21, 1) + SimpleLocation(0, 4, 1), type="misc_feature")
seqRecord.features = [f1, f2]

# Exact feature sliced for normal and origin-spanning features
Expand All @@ -1888,6 +1888,12 @@ def test___getitem__():
assert len(seqRecord[2:20].features) == 1
assert len(seqRecord[13:8].features) == 1

# Indexing of full circular molecule (https://github.com/BjornFJohansson/pydna/issues/161)
s = Dseqrecord("GGATCC", circular=True)
str_seq = str(s.seq)
for shift in range(len(s)):
assert str(s[shift : shift].seq) == str_seq[shift:] + str_seq[:shift]

def test___eq__():
from pydna.dseqrecord import Dseqrecord

Expand Down

0 comments on commit 28da1d8

Please sign in to comment.