Skip to content

Commit

Permalink
MultipleSeqAlignment del method for removing sequences by index or sl…
Browse files Browse the repository at this point in the history
…ice (biopython#4293)

* MultipleSeqAlignment del method added, closes issue 4137
* Changed the test to include the del method of MultipleSeqAlignment
* Added my name to the alphabetical listing
  • Loading branch information
siddhartasr10 committed May 2, 2023
1 parent 024a441 commit 207f843
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Bio/Align/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,13 @@ def __getitem__(self, index):
new.column_annotations[k] = v[col_index]
return new

def __delitem__(self, index):
"""Delete SeqRecord by index or multiple SeqRecords by slice."""
if not isinstance(index, int) and not isinstance(index, slice):
raise TypeError("Invalid index type.")

del self._records[index]

def sort(self, key=None, reverse=False):
"""Sort the rows (SeqRecord objects) of the alignment in place.
Expand Down
1 change: 1 addition & 0 deletions CONTRIB.rst
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ please open an issue on GitHub or mention it on the mailing list.
- Shoichiro Kawauchi <https://github.com/lacrosse91>
- Shuichiro MAKIGAKI <https://github.com/shuichiro-makigaki>
- Shyam Saladi <https://github.com/smsaladi>
- Siddharta Morion <https://github.com/siddhartasr10>
- Siong Kong <https://github.com/siongkong>
- Sjoerd de Vries <https://github.com/sjdv1982>
- Soroush Saffari <https://github.com/sorsaffari>
Expand Down
2 changes: 2 additions & 0 deletions Tests/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def test_basic_alignment(self):
alignment.append(SeqRecord(Seq(letters), id="mixed"))
alignment.append(SeqRecord(Seq(letters.lower()), id="lower"))
alignment.append(SeqRecord(Seq(letters.upper()), id="upper"))
alignment.append(SeqRecord(Seq(letters), id="duplicate"))
del alignment[3]
self.assertEqual(alignment.get_alignment_length(), 26)
self.assertEqual(len(alignment), 3)
self.assertEqual(alignment[0].seq, letters)
Expand Down

0 comments on commit 207f843

Please sign in to comment.