Tanggal :October 22, 2020

bpy3. Generic alphabet and strings

Spread the love

In case you do not put an alphabet, the generic Alphabet() is used.

If you print a sequence it coverts the sequence to string by implicitly using str(), regardless of the alphabet used. You can also use the str() function to explicitly convert a sequence into string. Whenever you perform an operation with Seq, it returns a new object, since Seq is an immutable Python object. This is unlike Python Lists which are mutable. We also have a MutableSeq object.

However, in many cases it will convert it to string, such as when looping or when doing comparisons.


# bpy3.py
from __future__ import print_function
from Bio.Seq import Seq
dna_str = "CTGAATCG"
dna = Seq(dna_str)
print("dna =", dna)
print("type(dna) = ", type(dna))
for i in dna:
print('type(i) =', type(i), end = ' with value of ')
print('i =',i)
print("comp:",dna_str==dna)

#dna = CTGAATCG
#type(dna) =
#type(i) = <type 'str'> with value of i = C
#type(i) = <type 'str'> with value of i = T
#type(i) = <type 'str'> with value of i = G
#type(i) = <type 'str'> with value of i = A
#type(i) = <type 'str'> with value of i = A
#type(i) = <type 'str'> with value of i = T
#type(i) = <type 'str'> with value of i = C
#type(i) = <type 'str'> with value of i = G
#comp: True
Share

Leave a Reply

Your email address will not be published. Required fields are marked *