python运行hhblits二进制命令的包装器类

hhblits 是 HMM-HMM(Hidden Markov Model to Hidden Markov Model)比对方法的一部分,也是 HMMER 软件套件中的工具之一。与 hhsearch 类似,hhblits 也用于进行高效的蛋白质序列比对,特别擅长于检测远缘同源性。

hh-suite 源码 https://github.com/soedinglab/hh-suite

以下是 hhblits 的一些主要特点和用途:

  1. HMM-HMM比对: hhblits 使用隐藏马尔可夫模型(HMM)来表示蛋白质家族的模型,从而能够更全面地考虑多序列信息。这使得它相对于传统的序列-序列比对方法更能捕捉蛋白质家族的模式和结构。

  2. 迭代比对: hhblits 支持迭代比对的策略,通过在每一轮中更新模型,逐渐提高比对的灵敏度。这种策略对于发现相对远缘同源蛋白质非常有用。

  3. 远缘同源性检测: 与其他 HMM-HMM比对方法类似,hhblits 被设计用于检测远缘同源蛋白质,即那些在序列上相对较远但在结构和功能上相似的蛋白质。

  4. 数据库搜索: 用户可以使用 hhblits 在大型蛋白质数据库中搜索与给定蛋白质序列相似的蛋白质。

  5. 灵敏度和特异性: hhblits 的设计目标是在保持高灵敏度的同时,降低假阳性的比对,以提高比对的特异性。

import glob
import os
import subprocess
from typing import Any, List, Mapping, Optional, Sequencefrom absl import logging
import contextlib
import shutil
import tempfile
import time_HHBLITS_DEFAULT_P = 20
_HHBLITS_DEFAULT_Z = 500@contextlib.contextmanager
def tmpdir_manager(base_dir: Optional[str] = None):"""Context manager that deletes a temporary directory on exit."""tmpdir = tempfile.mkdtemp(dir=base_dir)try:yield tmpdirfinally:shutil.rmtree(tmpdir, ignore_errors=True)@contextlib.contextmanager
def timing(msg: str):logging.info('Started %s', msg)tic = time.time()yieldtoc = time.time()logging.info('Finished %s in %.3f seconds', msg, toc - tic)class HHBlits:"""Python wrapper of the HHblits binary."""def __init__(self,*,binary_path: str,databases: Sequence[str],n_cpu: int = 4,n_iter: int = 3,e_value: float = 0.001,maxseq: int = 1_000_000,realign_max: int = 100_000,maxfilt: int = 100_000,min_prefilter_hits: int = 1000,all_seqs: bool = False,alt: Optional[int] = None,p: int = _HHBLITS_DEFAULT_P,z: int = _HHBLITS_DEFAULT_Z):"""Initializes the Python HHblits wrapper.Args:binary_path: The path to the HHblits executable.databases: A sequence of HHblits database paths. This should be thecommon prefix for the database files (i.e. up to but not including_hhm.ffindex etc.)n_cpu: The number of CPUs to give HHblits.n_iter: The number of HHblits iterations.e_value: The E-value, see HHblits docs for more details.maxseq: The maximum number of rows in an input alignment. Note that thisparameter is only supported in HHBlits version 3.1 and higher.realign_max: Max number of HMM-HMM hits to realign. HHblits default: 500.maxfilt: Max number of hits allowed to pass the 2nd prefilter.HHblits default: 20000.min_prefilter_hits: Min number of hits to pass prefilter.HHblits default: 100.all_seqs: Return all sequences in the MSA / Do not filter the result MSA.HHblits default: False.alt: Show up to this many alternative alignments.p: Minimum Prob for a hit to be included in the output hhr file.HHblits default: 20.z: Hard cap on number of hits reported in the hhr file.HHblits default: 500. NB: The relevant HHblits flag is -Z not -z.Raises:RuntimeError: If HHblits binary not found within the path."""self.binary_path = binary_pathself.databases = databasesself.n_cpu = n_cpuself.n_iter = n_iterself.e_value = e_valueself.maxseq = maxseqself.realign_max = realign_maxself.maxfilt = maxfiltself.min_prefilter_hits = min_prefilter_hitsself.all_seqs = all_seqsself.alt = altself.p = pself.z = zdef query(self, input_fasta_path: str) -> List[Mapping[str, Any]]:"""Queries the database using HHblits."""with tmpdir_manager() as query_tmp_dir:a3m_path = os.path.join(query_tmp_dir, 'output.a3m')db_cmd = []for db_path in self.databases:db_cmd.append('-d')db_cmd.append(db_path)cmd = [self.binary_path,'-i', input_fasta_path,'-cpu', str(self.n_cpu),'-oa3m', a3m_path,'-o', '/dev/null','-n', str(self.n_iter),'-e', str(self.e_value),'-maxseq', str(self.maxseq),'-realign_max', str(self.realign_max),'-maxfilt', str(self.maxfilt),'-min_prefilter_hits', str(self.min_prefilter_hits)]if self.all_seqs:cmd += ['-all']if self.alt:cmd += ['-alt', str(self.alt)]if self.p != _HHBLITS_DEFAULT_P:cmd += ['-p', str(self.p)]if self.z != _HHBLITS_DEFAULT_Z:cmd += ['-Z', str(self.z)]cmd += db_cmdprint("cmd:",' '.join(cmd))logging.info('Launching subprocess "%s"', ' '.join(cmd))process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)with timing('HHblits query'):stdout, stderr = process.communicate()retcode = process.wait()if retcode:# Logs have a 15k character limit, so log HHblits error line by line.logging.error('HHblits failed. HHblits stderr begin:')for error_line in stderr.decode('utf-8').splitlines():if error_line.strip():logging.error(error_line.strip())logging.error('HHblits stderr end')raise RuntimeError('HHblits failed\nstdout:\n%s\n\nstderr:\n%s\n' % (stdout.decode('utf-8'), stderr[:500_000].decode('utf-8')))with open(a3m_path) as f:a3m = f.read()raw_output = dict(a3m=a3m,output=stdout,stderr=stderr,n_iter=self.n_iter,e_value=self.e_value)return [raw_output]if __name__ == "__main__":hhblits_binary_path = "/home/zheng/software/hhsuite-3.3.0-SSE2-Linux/bin/hhblits"input_fasta_path = "/home/zheng/test/Q94K49.fasta"#hhsuite数据库下载地址:https://wwwuser.gwdg.de/~compbiol/data/hhsuite/databases/hhsuite_dbs/  scop70_database_path = "/home/zheng/database/scop70_1.75_hhsuite3/scop70_1.75"pdb70_database_path = "/home/zheng/database/pdb70_from_mmcif_latest/pdb70"## 单一数据库#hhblits_runner = HHBlits(binary_path = hhblits_binary_path,  #                         databases = [scop70_database_path])## 多个数据库database_lst = [scop70_database_path, pdb70_database_path]hhblits_runner = HHBlits(binary_path = hhblits_binary_path,databases = database_lst) result = hhblits_runner.query(input_fasta_path)print(len(result))print(result[0]['a3m'])#print(result)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/164541.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

筑牢思想防线——建行驻江门市分行纪检组举办2023年清廉合规大讲堂

为推动廉洁教育打通“最后一公里”,近日,建行驻江门市分行纪检组举办江门市分行2023年清廉合规大讲堂。 本次大讲堂检察官结合一线办案经历,从防范化解金融风险、预防金融从业人员犯罪等方面对全辖员工进行了深入浅出地的讲解,引导…

代码随想录算法训练营第五十二天|1143.最长公共子序列 1035.不相交的线 53. 最大子序和

文档讲解:代码随想录 视频讲解:代码随想录B站账号 状态:看了视频题解和文章解析后做出来了 1143.最长公共子序列 class Solution:def longestCommonSubsequence(self, text1: str, text2: str) -> int:dp [[0] * (len(text2) 1) for _ i…

C++——stack和queue

目录 stack的介绍和使用 stack的使用 queue的介绍和使用 queue的使用 容器适配器 deque的介绍 deque的缺陷 priority_queue的介绍和使用 priority_queue的使用 仿函数 反向迭代器 stack的介绍和使用 在原来的数据结构中已经介绍过什么是栈了,再来回顾一下…

视频监控平台EasyCVR+智能分析网关+物联网,联合打造智能环卫监控系统

一、背景介绍 城市作为人们生活的载体,有着有无数楼宇和四通八达的街道,这些建筑的整洁与卫生的背后,是无数环卫工作人员的努力。环卫工人通过清理垃圾、打扫街道、清洗公共设施等工作,保持城市的整洁和卫生,防止垃圾…

【机器学习 | 白噪声检验】检验模型学习成果 检验平稳性最佳实践,确定不来看看?

🤵‍♂️ 个人主页: AI_magician 📡主页地址: 作者简介:CSDN内容合伙人,全栈领域优质创作者。 👨‍💻景愿:旨在于能和更多的热爱计算机的伙伴一起成长!!&…

C++ Day09 容器

C-STL01- 容器 引入 我们想存储多个学员的信息 , 现在学员数量不定 通过以前学习的知识 , 我们可以创建一个数组存储学员的信息 但是这个数组大小是多少呢 ? 过大会导致空间浪费 , 小了又需要扩容 对其中的数据进行操作也较为复杂 每次删除数据后还要对其进行回收等操作…

cookie的跨站策略 跨站和跨域

借鉴:Cookie Samesite简析 - 知乎 (zhihu.com) 1、跨站指 协议、域名、端口号都必须一致 2、跨站 顶级域名二级域名 相同就行。cookie遵循的是跨站策略

PowerDesigner异构数据库转换

主要流程:sql->pdm->cdm->other pdm->sql 1.根据sql生成pdm 2.根据pdm生成cdm 3.生成其他类型数据库pdm

【Java】认识String类

文章目录 一、String类的重要性二、String类中的常用方法1.字符串构造2.String对象的比较3.字符串查找4.转换5.字符串替换6.字符串拆分7.字符串截取8.其他操作方法9.字符串的不可变性10.字符串修改 三、StringBuilder和StringBuffer 一、String类的重要性 在C语言中已经涉及到…

C语言第二十五弹--打印菱形

C语言打印菱形 思路&#xff1a;想要打印一个菱形&#xff0c;可以分为上下两部分&#xff0c;通过观察可以发现上半部分星号的规律是 1 3 5 7故理解为 2对应行数 1 &#xff0c;空格是4 3 2 1故理解为 行数-对应行数-1。 上半部分代码如下 for (int i 0;i < line;i){//上…

Vivado Modelsim联合进行UVM仿真指南

打开Vivado&#xff0c;打开对应工程&#xff0c;点击左侧Flow Navigator-->PROJECT MANAGER-->Settings&#xff0c;打开设置面板。点击Project Settings-->Simulation选项卡&#xff0c;如下图所示。 将Target simulator设为Modelsim Simulator。 在下方的Compil…

OpenGL 绘制圆形平面(Qt)

文章目录 一、简介二、代码实现三、实现效果一、简介 这里使用一种简单的思路来生成一个圆形平面: 首先,我们需要生成一个单位圆,半径为1,法向量为(0, 0, 1),这一步我们可以使用一些函数生成圆形点集。之后,指定面片的索引生成一个圆形平面。当然这里为了后续管理起来方便…

Py之PyMuPDF:PyMuPDF的简介、安装、使用方法之详细攻略

Py之PyMuPDF&#xff1a;PyMuPDF的简介、安装、使用方法之详细攻略 目录 PyMuPDF的简介 PyMuPDF的安装 PyMuPDF的使用方法 1、基础用法 PyMuPDF的简介 PyMuPDF是一个高性能的Python库&#xff0c;用于PDF(和其他)文档的数据提取&#xff0c;分析&#xff0c;转换和操作。 …

Matrix

Matrix 如下是四种变换对应的控制参数&#xff1a; Rect 常用的一个“绘画相关的工具类”&#xff0c;常用来描述长方形/正方形&#xff0c;他只有4个属性&#xff1a; public int left; public int top; public int right; public int bottom; 这4个属性描述着这一个“方块…

基于JavaWeb+SSM+Vue校园水电费管理小程序系统的设计和实现

基于JavaWebSSMVue校园水电费管理小程序系统的设计和实现 源码获取入口Lun文目录前言主要技术系统设计功能截图订阅经典源码专栏Java项目精品实战案例《500套》 源码获取 源码获取入口 Lun文目录 摘 要 III Abstract 1 1 系统概述 2 1.1 概述 2 1.2课题意义 3 1.3 主要内容 3…

使用【画图】软件修改图片像素、比例和大小

打开电脑画图软件&#xff0c;点击开始 windows附件 画图 在画图软件里选择需要调整的照片&#xff0c;点击文件 打开 在弹出窗口中选择照片后点击打开 照片在画图软件中打开后&#xff0c;对照片进行调整。按图中顺序进行 确定后照片会根据设定的值自动调整 保存…

Codeforces Round 745 (Div. 2)(C:前缀和+滑动窗口,E:位运算加分块)

Dashboard - Codeforces Round 745 (Div. 2) - Codeforces A&#xff1a; 答案就是2n!/2, 对于当前满足有k个合法下标的排列&#xff0c;就是一个n-k个不合法的下标的排列&#xff0c; 所以每一个合法排列都相反的存在一个 对称性 #include<bits/stdc.h> using nam…

【Redisson】基于自定义注解的Redisson分布式锁实现

前言 在项目中&#xff0c;经常需要使用Redisson分布式锁来保证并发操作的安全性。在未引入基于注解的分布式锁之前&#xff0c;我们需要手动编写获取锁、判断锁、释放锁的逻辑&#xff0c;导致代码重复且冗长。为了简化这一过程&#xff0c;我们引入了基于注解的分布式锁&…

JS获取时间戳的五种方法

一、JavasCRIPT时间转时间戳 JavaScript获得时间戳的方法有五种&#xff0c;后四种都是通过实例化时间对象new Date() 来进一步获取当前的时间戳&#xff0c;JavaScript处理时间主要使用时间对象Date。 方法一&#xff1a;Date.now() Date.now()可以获得当前的时间戳&#x…

思维模型 等待效应

本系列文章 主要是 分享 思维模型 &#xff0c;涉及各个领域&#xff0c;重在提升认知。越是等待&#xff0c;越是焦虑。 1 等待效应的应用 1.1 等待效应在管理中的应用 西南航空公司是一家美国的航空公司&#xff0c;它在管理中运用了等待效应。西南航空公司鼓励员工在工作中…