使用生物蟒蛇重新编号PDB文件中的残基



我有一个序列对齐方式:

RefSeq     :MXKQRSLPLXQKRTKQAISFSASHRIYLQRKFSH .....
Templatepdb:-----------------ISFSASHR------FSHAQADFAG 

我正在尝试编写一个代码,根据 PDB 文件中的这种对齐方式重新编号残留物,如下所示:

原始 pdb : RES ID=

1 1 1 1 1 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 5 ...

新 PDB : RES ID = 18 18 18 19 19 19 19 20 20 21 21 22 23 24 25 31 31 31 31 31 31 32 32 33 34 35 36 ...

如果对齐开始时只有间隙,很容易弄清楚。仅计算间隙("-"(并将间隙总和添加到 residue.id= " "间隙总和" ">

但是,如果序列中间有间隙,我找不到方法。

你有什么建议吗?

如果我理解正确,

您的输入是对齐方式:

'-----------------ISFSASHR------FSHAQADFAG'

和残余编号列表:

[1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 18, 18, 18, 18]

您的输出是残

差数偏移残差数之前间隙数:
[18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 25, 25, 25, 25, 32, 32, 32, 33, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 40, 41, 41, 41, 41]

下面是演示它的代码。有许多方法可以计算输出。

我这样做的方法是保持字典shift_dict键作为原始数字,值作为移位数字。

import itertools
import random

def random_residue_number(sequence):
    nested = [[i + 1] * random.randint(1, 10) for i in range(len(sequence))]
    merged = list(itertools.chain.from_iterable(nested))
    return merged

def aligned_residue_number(alignment, original_number):
    gap_shift = 0
    residue_count = 0
    shift_dict = {}
    for residue in alignment:
        if residue == '-':
            gap_shift += 1
        else:
            residue_count += 1
            shift_dict[residue_count] = gap_shift + residue_count
    return [shift_dict[number] for number in original_number]

sequence = 'ISFSASHRFSHAQADFAG'
alignment = '-----------------ISFSASHR------FSHAQADFAG'
original_number = random_residue_number(sequence)
print(original_number)
# [1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 18, 18, 18, 18]
new_number = aligned_residue_number(alignment, original_number)
print(new_number)
# [18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 21, 21, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 25, 25, 25, 25, 32, 32, 32, 33, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 39, 39, 39, 39, 40, 41, 41, 41, 41]

相关内容

  • 没有找到相关文章

最新更新