Biopython:在中间序列中添加一个具有对齐特征的部分

2024-06-12 00:52:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在前一个序列的中间添加序列的一部分(在gb文件中),并使所有特性仍然由旧序列索引

例如:

上一个序列:ATAGCCATTGTGTGTGTGTGTCCTAGAGGCCTAAAA

fetaure:misc_功能补充(20..27) /gene=“Py_ori+A”

我在第10位加上TTTTTT

新序列:ATAGCCATTGTTTTTTAAGTGTGTGTGTCCTAGAGGCCTAAAA

fetaure:misc_特征补码(2633) /gene=“Py_ori+A”

功能的索引已更改,因为功能必须仍然与段TGTCCTA有关。我想将新序列保存在一个新的gb文件中

是否有任何biopython函数或方法可以在旧序列的中间添加序列段,并将添加段的长度添加到添加段之后的特征索引中


Tags: 文件py功能序列特征特性miscgene
1条回答
网友
1楼 · 发布于 2024-06-12 00:52:13

TL;DR

对切片段调用+(例如a + b)。只要你没有切分到一个特性,你就应该可以了


长版本:

BioPython支持功能连接。只需在相应的SeqRecord类上调用a + b即可完成(功能是SeqRecord对象的一部分,而不是Seq类)

关于具有特征的切片序列,有一个需要注意的怪癖。如果您碰巧在功能中执行了切片,则该功能将不会出现在结果SeqRecord

我试图在下面的代码中说明这种行为

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


# THIS IS OK

a = SeqRecord(
    Seq('ACGTA'),
    id='a',
    features=[
        SeqFeature(FeatureLocation(2,4,1), id='f1')
    ]
)

b = SeqRecord(
    Seq('ACGTA'),
    id='b',
    features=[
        SeqFeature(FeatureLocation(2,4,1), id='f2')
    ]
)

c = a + b

print('seq a')
print(a.seq)
print(a.features)

print('\nseq b')
print(b.seq)
print(b.features)

print("\n two distinct features joined in seq c")
print(c.seq)
print(c.features)
print("notice how the second feature has now indices (7,9), instead of 2,4\n")


# BEWARE
# slicing into the feature will remove the feature !

print("\nsliced feature removed")
d = a[:3]
print(d.seq)
print(d.features)
# Seq('ACG')
# []

# However slicing around the feature will preserve it
print("\nslicing out of the feature will preserve it")
e = c[1:6]
print(e.seq)
print(e.features)

输出

seq a
ACGTA
[SeqFeature(FeatureLocation(ExactPosition(2), ExactPosition(4), strand=1), id='f1')]

seq b
ACGTA
[SeqFeature(FeatureLocation(ExactPosition(2), ExactPosition(4), strand=1), id='f2')]

 two distinct features joined in seq c
ACGTAACGTA
[SeqFeature(FeatureLocation(ExactPosition(2), ExactPosition(4), strand=1), id='f1'), SeqFeature(FeatureLocation(ExactPosition(7), ExactPosition(9), strand=1), id='f2')]
notice how the second feature has now indices (7,9), instead of 2,4


sliced feature removed
ACG
[]

slicing out of the feature will preserve it
CGTAA
[SeqFeature(FeatureLocation(ExactPosition(1), ExactPosition(3), strand=1), id='f1')]

相关问题 更多 >