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

Introduction to the SeqRecord class. · Biopython

自动蜘蛛 biopython.org 正文约 3304 字
Python Tools for Computational Molecular Biology
This page describes the SeqRecord object used in Biopython to hold a sequence (as a Seq object) with identifiers (ID and name), description and optionally annotation and sub-features.
Most of the sequence file format parsers in BioPython can return SeqRecord objects (and may offer a format specific record object too, see for example Bio.SwissProt). The SeqIO system will only return SeqRecord objects.
In addition to the SeqRecord object’s API documentation, there is a whole chapter in the Tutorial, and the SeqIO page is also very relevant.
Lets look in detail at the well annotated SeqRecord objects Biopython creates from a GenBank file, such as ls_orchid.gbk, which we’ll load using the SeqIO module. This file contains 94 records:
And this is some of the output. Remember Python likes to count from zero, so the 94 records in this file have been labelled 0 to 93:
Lets look in a little more detail at the final record:
That should give you a hint of the sort of information held in this object:
Lets look a little more closely… and use Python’s dir() function to find out more about the SeqRecord object and what it does:
If you didn’t already know, the dir() function returns a list of all the methods and properties of an object (as strings). Those starting with underscores in their name are “special” and we’ll be ignoring them in this discussion. We’ll start with the .seq property:
This is a Seq object, another important object type in Biopython, and worth of its own page on the wiki documentation.
The following three properties are all simple strings:
Have a look at the raw GenBank file to see where these came from.
Next, we’ll check the .dxrefs property, which holds any database cross references:
An empty list? Disappointing… if we’d used a more recent GenBank file the genome sequencing project reference would show up here.
How about the .annotations property? This is a Python dictionary…
In this case, most of the values in the dictionary are simple strings, but this isn’t always the case - have a look at the references entry for this example - its a list of Reference objects:
Next is .features which is another list property, and it contains SeqFeature objects:
SeqFeature objects are complicated enough to warrant their own wiki page… for now please refer to the Tutorial.
If you are using Biopython 1.48 or later, there will be a .format() method. This lets you convert the SeqRecord into a string using one of the output formats supported by Bio.SeqIO, for example:
If you are using Biopython 1.50 or later, there will also be a .letter_annotations property. Again this is a dictionary but for per-letter-annotation such as sequence quality scores or secondary structure predictions. This kind of information isn’t found in GenBank files, so in this case the dictionary is empty:
Have a look at FASTQ or QUAL files to see how quality scores are represented. Stockholm (PFAM) alignment files also often include per-letter-annotation.
Most of the time you’ll create SeqRecord objects by parsing a sequence file with Bio.SeqIO. However, it is useful to know how to create a SeqRecord directly. For example,
This would give the following output:
You could then pass this new record to Bio.SeqIO.write(...) to save it to disk.
访问原文 返回搜索 https://biopython.org/wiki/SeqRecord
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。