Subsetting and manipulating sequences

Introduction to Sequence Manipulation: Sequence manipulation involves performing operations on biological sequences...

Introduction to Sequence Manipulation:

  • Sequence manipulation involves performing operations on biological sequences to extract useful information or transform the sequence data.
  • Biopython provides a range of functionalities to manipulate DNA, RNA, and protein sequences.

The Seq Object:

  • Biopython’s Seq object represents a biological sequence.
  • It encapsulates the sequence data and provides various methods for sequence manipulation.

Sequence Extraction:

  • Biopython allows extracting subsequences from larger sequences based on specified start and end positions.
  • The extracted subsequence retains the same type (DNA, RNA, or protein) as the original sequence.
from Bio.Seq import Seq

sequence = Seq("ATCGATCGATCG")
subsequence = sequence[2:6]

print("Original Sequence:", sequence)
print("Subsequence:", subsequence)
  • Create a Seq object from a DNA sequence.
  • Extract a subsequence from position 2 to 5 (inclusive).
  • Print both the original sequence and the extracted subsequence.

Reverse Complementation:

  • Biopython provides a method to obtain the reverse complement of a DNA sequence.
  • The reverse complement is useful for studying the complementary strand or designing primers.
from Bio.Seq import Seq

sequence = Seq("ATCGATCGATCG")
reverse_complement = sequence.reverse_complement()

print("Original Sequence:", sequence)
print("Reverse Complement:", reverse_complement)
  • Create a Seq object from a DNA sequence.
  • Use the reverse_complement() method to obtain the reverse complement.
  • Print both the original sequence and the reverse complement.


Join the conversation