Biopython序列比对

从InterPro网站(https://www.ebi.ac.uk/interpro/download/Pfam/)下载多序列比对文件Pfam-A.seed.gz(含多个多序列比对)

​wget https://ftp.ebi.ac.uk/pub/databases/Pfam/current_release/Pfam-A.seed.gz

解压,取第一个多多序列比对文件

cat Pfam-A.seed | while read line; do if [[ ${line} != "//" ]]; then echo ${line}; else; echo ${line}; break; fi; done > Pfam-A-1.seed

InterPro 通过将蛋白质分类为家族并预测结构域和重要位点,对蛋白质进行功能分析。为了以这种方式对蛋白质进行分类,InterPro 使用了由组成 InterPro 联盟的几个不同数据库(称为成员数据库)提供的预测模型(称为特征)。我们将这些成员数据库中的蛋白质特征整合到一个单一的可搜索资源中,利用它们各自的优势来生成一个强大的集成数据库和诊断工具。

from Bio import AlignIO
align_file = "/path_to_file/Pfam-A-1.seed"
### 1. 读取序列比对文件
## read方法用于读取给定文件中可用的单个比对数据。
# 文件格式为 Stockholm
align = AlignIO.read(open(align_file), "stockholm")
# 常见的多序列比对格式还有 "clustal" "phylip"等
print("Alignment length %i" % align.get_alignment_length())
for record in align:
    print(record.seq + " " + record.id)

## parse方法返回可迭代的对齐对象,可以对其进行迭代以获得实际的对齐方式
alignments = AlignIO.parse(open(align_file), "stockholm") 
print(alignments) 

for alignment in alignments: 
    print(alignment)

### 2. 双序列比对
from Bio import pairwise2
from Bio.Seq import Seq 
seq1 = Seq("ACCGGT") 
seq2 = Seq("ACGT")

alignments = pairwise2.align.globalxx(seq1, seq2)
print(alignments)

for alignment in alignments: 
    print(alignment)

## 格式化输出
from Bio.pairwise2 import format_alignment 
alignments = pairwise2.align.globalxx(seq1, seq2) 
for alignment in alignments: 
    print(format_alignment(*alignment)) 

### 3. Biopython通过Bio.Align.Applications模块为许多序列比对工具提供接口。
from Bio.Align.Applications import ClustalwCommandline

参考
https://www.yiibai.com/biopython/biopython_sequence_alignments.html
https://biopython.org/wiki/AlignIO

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Biopython提供了许多可视化序列和结构的工具,包括PDB文件解析器、蛋白质结构可视化、序列比对、序列Logo图等。下面介绍如何使用Biopython可视化PDB文件中的蛋白质序列和结构。 1. 安装Biopython Biopython可以通过pip安装,在命令行中输入以下命令: ``` pip install biopython ``` 2. 下载PDB文件 可以从PDB数据库中下载PDB文件,也可以使用Biopython中的PDB模块下载。这里以下载PDB ID为1TIM的文件为例: ```python from Bio.PDB import PDBList pdbl = PDBList() pdbl.retrieve_pdb_file('1TIM') ``` 3. 解析PDB文件 使用Biopython中的PDB模块解析PDB文件,并提取蛋白质序列和结构信息: ```python from Bio.PDB import PDBParser parser = PDBParser() structure = parser.get_structure('1TIM', '1tim.pdb') # 提取第一个模型的第一个链的序列 chain_id = 'A' chain = structure[0][chain_id] sequence = '' for residue in chain: if residue.get_resname() == 'HOH': # 去除水分子 continue sequence += residue.get_resname() print(f'{chain_id} sequence: {sequence}') # 提取第一个模型的结构信息 model = structure[0] atoms = [] for chain in model: for residue in chain: if residue.get_resname() == 'HOH': # 去除水分子 continue for atom in residue: atoms.append(atom) print(f'{len(atoms)} atoms in the structure') ``` 4. 可视化蛋白质结构 使用Biopython中的PDB模块和Matplotlib模块可视化蛋白质结构: ```python from Bio.PDB import PDBIO, Select from matplotlib import pyplot as plt class ChainSelector(Select): def __init__(self, chain_id): self.chain_id = chain_id def accept_chain(self, chain): if chain.get_id() == self.chain_id: return 1 else: return 0 # 提取第一个模型的第一个链的结构信息 chain_id = 'A' chain = structure[0][chain_id] atoms = [] for residue in chain: if residue.get_resname() == 'HOH': # 去除水分子 continue for atom in residue: atoms.append(atom) # 可视化结构 fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(111, projection='3d') ax.set_title(f'Chain {chain_id}') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') io = PDBIO() io.set_structure(chain) io.save(f'chain_{chain_id}.pdb') pdb_file = f'chain_{chain_id}.pdb' io = PDBIO() io.set_structure(chain) io.save(pdb_file, ChainSelector(chain_id)) from Bio.PDB.PDBIO import Select from Bio.PDB.PDBParser import PDBParser from Bio.PDB.Structure import Structure from Bio.PDB.Residue import Residue from Bio.PDB.Atom import Atom class ChainSelector(Select): def __init__(self, chain_id): self.chain_id = chain_id def accept_chain(self, chain): if chain.get_id() == self.chain_id: return 1 else: return 0 parser = PDBParser() structure = parser.get_structure('1TIM', pdb_file) # 提取第一个模型的第一个链的结构信息 chain_id = 'A' chain = structure[0][chain_id] atoms = [] for residue in chain: if residue.get_resname() == 'HOH': # 去除水分子 continue for atom in residue: atoms.append(atom) # 可视化结构 fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(111, projection='3d') ax.set_title(f'Chain {chain_id}') ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') for atom in atoms: ax.scatter(atom.get_coord()[0], atom.get_coord()[1], atom.get_coord()[2]) plt.show() ``` 运行以上代码,即可生成一个3D图形,显示蛋白质的结构。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值