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.pswp.cn/news/164541.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/164541.shtml
英文地址,請注明出處:http://en.pswp.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;它在管理中運用了等待效應。西南航空公司鼓勵員工在工作中…