AF3 pair_sequences函数解读

embedded/2025/3/3 18:20:55/

AlphaFold3 msa_pairing模块的pair_sequences函数的核心目标是基于 MSA(多序列比对)中的物种信息,在多条链之间建立 MSA 配对索引,从而帮助 AlphaFold3 捕捉共进化信息,提升蛋白复合物预测的准确性。函数pair_sequences 通过调用 _make_msa_df、  _create_species_dict  以及_match_rows_by_sequence_similarity实现其功能。

源代码:

def pair_sequences(examples: List[Mapping[str, np.ndarray]],
) -> Dict[int, np.ndarray]:"""Returns indices for paired MSA sequences across chains."""num_examples = len(examples)all_chain_species_dict = []common_species = set()for chain_features in examples:msa_df = _make_msa_df(chain_features)species_dict = _create_species_dict(msa_df)all_chain_species_dict.append(species_dict)common_species.update(set(species_dict))common_species = sorted(common_species)common_species.remove(b'')  # Remove target sequence species.all_paired_msa_rows = [np.zeros(len(examples), int)]all_paired_msa_rows_dict = {k: [] for k in range(num_examples)}all_paired_msa_rows_dict[num_examples] = [np.zeros(len(examples), int)]for species in common_species:if not species:continuethis_species_msa_dfs = []species_dfs_present = 0for species_dict in all_chain_species_dict:if species in species_dict:this_species_msa_dfs.append(species_dict[species])species_dfs_present += 1else:this_species_msa_dfs.append(None)# Skip species that are present in only one chain.if species_dfs_present <= 1:continueif np.any(np.array([len(species_df) for species_df inthis_species_msa_dfs ifisinstance(species_df, pd.DataFrame)]) > 600):continuepaired_msa_rows = _match_rows_by_sequence_similarity(this_species_msa_dfs)all_paired_msa_rows.extend(paired_msa_rows)all_paired_msa_rows_dict[species_dfs_present].extend(paired_msa_rows)all_paired_msa_rows_dict = {num_examples: np.array(paired_msa_rows) fornum_examples, paired_msa_rows in all_paired_msa_rows_dict.items()}return all_paired_msa_rows_dict

代码解读:

函数输入
def pair_sequences(examples: List[Mapping[str, np.ndarray]]) -> Dict[int, np.ndarray]

examples:包含多条链的 MSA 信息,每个元素是一个字典,代表一条蛋白链的 MSA 相关特征。

  • 例如,examples[0] 可能对应链 A 的 MSA 特征,examples[1] 可能对应链 B 的 MSA 特征。
代码执行过程
1️⃣ 提取所有链的 MSA 并构建物种索引
num_examples = len(examples)all_chain_species_dict = []
common_species = set()
for chain_features in examples:msa_df = _make_msa_df(chain_features)species_dict = _create_species_dict(msa_df)all_chain_species_dict.append(species_dict)common_species.update(set(species_dict))
  • 遍历 examples
    • 使用 _make_msa_df 将每条链的 MSA 信息转换为 DataFrame(包含 msa_similaritymsa_rowmsa_species_identifiers)。
    • 使用 _create_species_dict 按物种对 MSA 进行分组,得到 species_dict
    • 将 species_dict 存入 all_chain_species_dict,并收集所有物种信息,存入 common_species
2️⃣ 筛选出所有链共有的物种
common_species = sorted(common_species)
common_species.remove(b'')  # 移除目标序列所在的物种
  • 由于 MSA 可能包含多个物种的序列,该步骤确保只保留所有链都出现过的物种
  • 移除 b'',它代表目标序列自身的物种,不需要配对。
3️⃣ 初始化存储配对 MSA 结果的字典
all_paired_msa_rows = [np

http://www.ppmy.cn/embedded/169684.html

相关文章

ubuntu Linux 正确设置中文环境的方法

在安装ubuntu Linux中文环境时&#xff0c;有不少资料提到要修改一些配置文件&#xff0c;其实完全没必要&#xff0c;以下是正确安装中文环境的方法。 在新安装的ubuntu Linux的基础上&#xff0c;如下&#xff1a; 1. 安装中文语言包 # 更新软件源 sudo apt update# 安装中…

深入理解Reactor Flux的生成方法

在Reactor框架中&#xff0c;Flux 是一个非常重要的概念&#xff0c;它用于表示一个可以产生多个事件的响应式流。通过 Flux 提供的多种生成方法&#xff0c;我们可以灵活地创建各种类型的流。本文将详细介绍 Flux.generate 方法的使用&#xff0c;并通过实例帮助读者更好地理解…

前缀和算法 算法4

算法题中帮助复习的知识 vector<int > dp( n ,k); n为数组大小 ,k为初始化 哈希表unordered_map<int ,int > hash; hash.find(k)返回值是迭代器 ,找到k返回其迭代器 没找到返回hash.end() hash.count(k)返回值是数字 ,找到k返回1 ,没找到返回0. C和java中 负数…

C语言实现双向链表

1、概念 单向链表的构成使得节点的访问要按照链表的方向进行,某一单元的后继单元可以直接通过链指针(next指针)找到,但是想要找到其前驱单元,必须从链头重新开始查找。如果在节点中增加一个指针域指向其前驱节点,可以在牺牲空间代价的前提下,减少操作时间的代价。在单向…

SVN 简介

SVN 简介 引言 版本控制系统(Version Control System,VCS)是软件开发过程中不可或缺的工具之一。它能够帮助开发者管理代码的版本,追踪代码变更,协同工作,以及确保代码的稳定性和安全性。Subversion(简称SVN)是一种流行的版本控制系统,本文将为您详细介绍SVN的基本概…

LeetCode 0132.分割回文串 II:动态规划

【LetMeFly】132.分割回文串 II&#xff1a;动态规划 力扣题目链接&#xff1a;https://leetcode.cn/problems/palindrome-partitioning-ii/ 给你一个字符串 s&#xff0c;请你将 s 分割成一些子串&#xff0c;使每个子串都是回文串。 返回符合要求的 最少分割次数 。 示例 …

阿里管理三板斧课程和管理工具包(视频精讲+工具文档).zip

阿里管理三板斧课程和管理工具包&#xff08;视频精讲工具文档&#xff09;&#xff0c;共18课。 阿里管理三板斧工具包 阿里绩效考核文档 阿里人力资源实践全集文档 阿里文化构建工具包 阿里正委体系工具包 阿里三板斧.pdf 阿里三板斧-学员手册.pdf 第1集 三板斧的底层逻辑.…

版图自动化连接算法开发 00001 ------ 直接连接两个给定的坐标点

版图自动化连接算法开发 00001 ------ 直接连接两个给定的坐标点 引言正文定义坐标点的类绘图显示代码直接连接两个坐标点引言 由于人工智能的加速普及,每次手动绘制版图都会觉得特别繁琐,作者本人在想可否搞一个自动化连接器件端口的算法,后期可以根据一些设定的限制进行避…