Retain letter_annotation as None in upper and lower methods (#4966)

* gitignore .python-version
* added name & email
* fix so that _per_letter_annotations is not set by calling upper or lower methods
* added test for initiation of SeqRecord checking the __dict__ and a test for the __dict__ created by upper
This commit is contained in:
Björn Johansson
2025-03-10 14:01:25 +00:00
committed by GitHub
parent 882072e8fe
commit 67a37865e5
4 changed files with 46 additions and 2 deletions

6
.gitignore vendored
View File

@ -134,3 +134,9 @@ ENV/
# Testing # Testing
**/.coverage **/.coverage
# Ignore the .python-version file used by pyenv
# This file specifies the Python version for a project,
# but should not be committed to Git, as different developers
# may use different Python versions.
.python-version

View File

@ -1127,7 +1127,11 @@ class SeqRecord:
dbxrefs=self.dbxrefs[:], dbxrefs=self.dbxrefs[:],
features=self.features[:], features=self.features[:],
annotations=self.annotations.copy(), annotations=self.annotations.copy(),
letter_annotations=self.letter_annotations.copy(), letter_annotations=(
None
if self._per_letter_annotations is None
else self.letter_annotations.copy()
),
) )
def lower(self) -> "SeqRecord": def lower(self) -> "SeqRecord":
@ -1174,7 +1178,11 @@ class SeqRecord:
dbxrefs=self.dbxrefs[:], dbxrefs=self.dbxrefs[:],
features=self.features[:], features=self.features[:],
annotations=self.annotations.copy(), annotations=self.annotations.copy(),
letter_annotations=self.letter_annotations.copy(), letter_annotations=(
None
if self._per_letter_annotations is None
else self.letter_annotations.copy()
),
) )
def isupper(self): def isupper(self):

View File

@ -66,6 +66,7 @@ please open an issue on GitHub or mention it on the mailing list.
- Bertrand Frottier <bertrand.frottier at domain free.fr> - Bertrand Frottier <bertrand.frottier at domain free.fr>
- Bertrand Néron <https://github.com/bneron> - Bertrand Néron <https://github.com/bneron>
- Bill Barnard <bill at domain barnard-engineering.com> - Bill Barnard <bill at domain barnard-engineering.com>
- Björn Johansson <bjorn_johansson@bio.uminho.pt>
- Blaise Li <https://github.com/blaiseli> - Blaise Li <https://github.com/blaiseli>
- Bob Bussell <rgb2003 at domain med.cornell.edu> - Bob Bussell <rgb2003 at domain med.cornell.edu>
- Bogdan T. <bogdan at pearlgen dot com> - Bogdan T. <bogdan at pearlgen dot com>

View File

@ -133,6 +133,21 @@ class SeqRecordCreation(unittest.TestCase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
SeqRecord(Seq("ACGT"), features={}) SeqRecord(Seq("ACGT"), features={})
def test_default_properties(self):
seqobj = Seq("A")
default__dict__ = {
"_seq": seqobj,
"id": "<unknown id>",
"name": "<unknown name>",
"description": "<unknown description>",
"dbxrefs": [],
"annotations": {},
"_per_letter_annotations": None,
"features": [],
}
bsr = SeqRecord(seqobj)
self.assertEqual(bsr.__dict__, default__dict__)
class SeqRecordMethods(unittest.TestCase): class SeqRecordMethods(unittest.TestCase):
"""Test SeqRecord methods.""" """Test SeqRecord methods."""
@ -226,6 +241,20 @@ Seq('ABCDEFGHIJKLMNOPQRSTUVWZYX')"""
def test_upper(self): def test_upper(self):
self.assertEqual("ABCDEFGHIJKLMNOPQRSTUVWZYX", self.record.lower().upper().seq) self.assertEqual("ABCDEFGHIJKLMNOPQRSTUVWZYX", self.record.lower().upper().seq)
seqobj = Seq("A")
default__dict__ = {
"_seq": seqobj,
"id": "<unknown id>",
"name": "<unknown name>",
"description": "<unknown description>",
"dbxrefs": [],
"annotations": {},
"_per_letter_annotations": None,
"features": [],
}
bsr = SeqRecord(seqobj)
bsru = bsr.upper()
self.assertEqual(bsru.__dict__, default__dict__)
def test_lower(self): def test_lower(self):
self.assertEqual("abcdefghijklmnopqrstuvwzyx", self.record.lower().seq) self.assertEqual("abcdefghijklmnopqrstuvwzyx", self.record.lower().seq)