SeqFeature

SeqFeatureクラスのメソッドは次のようなものがあります。

メソッド対応するlocationタイプ
ExactPosition32..330
BeforePosition<23
AfterPosition>223
WithinPosition32..124
BetweenPosition42^43

location情報の作成

FeatureLocation メソッドを利用して location 情報を作成し、該当部分の塩基配列を切り出すサンプルです。

from Bio import SeqIO
from Bio.Seq import Seq
from Bio.SeqFeature import SeqFeature, FeatureLocation

#location作成
start = SeqFeature.AfterPosition(5)
end = SeqFeature.BetweenPosition(9, left=8, right=9)
location = SeqFeature.FeatureLocation(start, end)

location
#FeatureLocation(AfterPosition(5), BetweenPosition(9, left=8, right=9))
print location
#[>5:(8^9)]

#location情報に基づく塩基配列の切り出し
seq = Seq("ACCGAGACGGCAAAGGCTAGCATAGGTATGAGACTTCCTTCCTGCCAGTGCTGAGGAACTGGGAGCCTAC")
feature = SeqFeature(FeatureLocation(5, 18), type="gene", strand=-1)
feature_seq = seq[feature.location.start:feature.location.end].reverse_complement()
print feature_seq
#AGCCTTTGCCGTC

GenBankフォーマットのFeature

GenBank フォーマットファイルに記載された Features 情報の利用するサンプルです。

from Bio import SeqIO
from Bio.Seq import Seq
from Bio.SeqFeature import SeqFeature, FeatureLocation

gb_record = SeqIO.read("NC_005816.gb", "genbank")

len(gb_record)
#9609

print gb_record.features[0]
#type: source
#location: [0:9609](+)
#qualifiers: 
#    Key: biovar, Value: ['Microtus']
#    Key: db_xref, Value: ['taxon:229193']
#    Key: mol_type, Value: ['genomic DNA']
#    Key: organism, Value: ['Yersinia pestis biovar Microtus str. 91001']
#    Key: plasmid, Value: ['pPCP1']
#    Key: strain, Value: ['91001']

sub_gb_record = gb_record[4300:4800]
sub_gb_record
#SeqRecord(seq=Seq('ATAAATAGATTATTCCAAATAATTTATTTATGTAAGAACAGGATGGGAGGGGGA...TTA', IUPACAmbiguousDNA()), id='NC_005816.1', name='NC_005816', description='Yersinia pestis biovar Microtus str. 91001 plasmid pPCP1, complete sequence.', dbxrefs=[])

len(sub_gb_record.features)
#2