In bioinformatics analysis, a series of operations are often performed on DNA sequences, including sub-sequence interception, complementary sequence acquisition, reverse sequence acquisition, and reverse complementary sequence acquisition. In the Python language, you can write the following functions to accomplish these simple functions.
Sub-sequence interception
Using the string slicing feature in Python for sequence interception can be done, for example:
>>> seq="atgatatagtatatatgcaagagg">>> subseq = seq[1:6]> >> subseq"tgata"
Note that the slice operation is "0-base", and the package left does not wrap to the right.
Complementary sequence Acquisition
A more common practice is to define a base substitution dictionary, as follows:
defcomplement (s): Basecomplemt= { "A":"T", "T":"A", "G":"C", "C": G", "a":"T", "T":"a", "g":"C", "C":"g",} letters=list (s) Letters= [Basecomplement[base] forBaseinchLetters]return "'. Join (Letters)
The Translate method used with the python3 string
def complement (seq): return seq.translate (Str.maketrans ('acgtacgtrymkrymkvbhdvbhd ') TGCATGCAYRKMYRKMBVDHBVDH'))
or Python2 Maketrans method in a string package
from Import Maketrans def complement (seq): return seq.translate (Maketrans ('acgtacgtrymkrymkvbhdvbhd ') TGCATGCAYRKMYRKMBVDHBVDH'))
Reverse Complementary sequence acquisition
def Revcomp (seq): return complement (seq) [::-1]
Resources
DNA reverse complementary sequence acquisition
Python implements DNA sequence string conversion, complementary chain, reverse chain, reverse complementary chain