网页 综合 更新时间 2026-11-14 10:00:28

Handling sequences with the Seq class. · Biopython

自动蜘蛛 biopython.org 正文约 2806 字
Python Tools for Computational Molecular Biology
In Biopython, sequences are usually held as ` Seq` objects, which add various biological methods on top of string like behaviour.
This page describes the Biopython Seq object, defined in the Bio.Seq module (together with related objects like the MutableSeq, plus some general purpose sequence functions). In addition to this wiki page, there is a whole chapter in the Tutorial on the Seq object - plus its API documentation (which you can read online, or from within Python with the help command).
If you need to store additional information like a sequence identifier or name, or even more details like a description or annotation, then we use a SeqRecord object instead. These are the sequence records used by the SeqIO module for reading and writing sequence files.
The Seq object essentially combines a Python string with biological methods. For example:
Biopython doesn’t know if this is a nucleotide sequence or a protein rich in alanines, glycines, cysteines and threonines. If you know, keep this mind when you call methods like (reverse)complement - see below.
The Seq object has a number of methods which act just like those of a Python string, for example the find method:
There is a count method too:
However, watch out because just like the Python string’s count, this is a non-overlapping count!
In some biological situations, you might prefer an overlapping count using count_overlap which would give three for this example.
If you have a nucleotide sequence you may want to do things like take the reverse complement, or do a translation. Note some of these methods described here are only available in Biopython 1.49 onwards.
These are very simple - the methods return a new Seq object with the appropriate sequence:
If you have a DNA sequence, you may want to turn it into RNA. In bioinformatics we normally assume the DNA is the coding strand (not the template strand) so this is a simple matter of replacing all the thymines with uracil:
Naturally, given some RNA, you might want the associated DNA - and again Biopython does a simple U/T substitution:
If you actually do want the template strand, you’d have to do a reverse complement on top:
The chapter in the Tutorial (PDF) goes into more detail on this strand issue.
You can translate RNA:
Or DNA - which is assumed to be the coding strand:
In either case there are several useful options - by default as you will notice the in example above translation continues through any stop codons, but this is optional:
Then there is the translation table, for which you can give an NCBI genetic code number or name:
You can of course combine these options:
Consult the tutorial for more examples and arguments (e.g. specifying a different symbol for a stop codon), or see the built in help:
访问原文 返回搜索 https://biopython.org/wiki/Seq
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。