gpt4 book ai didi

python - 基于字符串输入Python导入变量替换矩阵

转载 作者:太空宇宙 更新时间:2023-11-03 21:31:55 24 4
gpt4 key购买 nike

我正在尝试导入一个替换矩阵,以根据给定的输入在 Python 中实现 Needleman-Wunsch 算法。如果我想选择一个矩阵,我可以这样做:

from Bio.SubsMat import MatrixInfo as matlist
scoring_mat = matlist.blosum62

如果我想导入基于输入的任何矩阵,我必须做什么?我暂时有这个:

def blosum(name):
index = str(name)
x= "blosum"+index
return x

a= blosum(62)
scoring_mat = matlist.a

不幸的是,它给了我以下错误:

AttributeError: module 'Bio.SubsMat.MatrixInfo' has no attribute 'a'

我需要做什么才能让它发挥作用?

提前致谢!

最佳答案

尝试使用 scoring_mat = getattr(matlist,a) 代替。它对我有用。

关于python - 基于字符串输入Python导入变量替换矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53469658/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com