本文整理汇总了Python中pyomo.environ.ConcreteModel.EpitopeConsConst方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.EpitopeConsConst方法的具体用法?Python ConcreteModel.EpitopeConsConst怎么用?Python ConcreteModel.EpitopeConsConst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.EpitopeConsConst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import EpitopeConsConst [as 别名]
#.........这里部分代码省略.........
res_df = results.xs(results.index.values[0][1], level="Method")
res_df = res_df[res_df.apply(lambda x: any(x[a] > self.__thresh.get(a.name, -float("inf"))
for a in res_df.columns), axis=1)]
for tup in res_df.itertuples():
p = tup[0]
seq = str(p)
peps[seq] = p
for a, s in itr.izip(res_df.columns, tup[1:]):
if method in ["smm", "smmpmbec", "arb", "comblibsidney"]:
try:
thr = min(1., max(0.0, 1.0 - math.log(self.__thresh.get(a.name),
50000))) if a.name in self.__thresh else -float("inf")
except:
thr = 0
if s >= thr:
alleles_I.setdefault(a.name, set()).add(seq)
imm[seq, a.name] = min(1., max(0.0, 1.0 - math.log(s, 50000)))
else:
if s > self.__thresh.get(a.name, -float("inf")):
alleles_I.setdefault(a.name, set()).add(seq)
imm[seq, a.name] = s
prots = set(pr for pr in p.get_all_proteins())
cons[seq] = len(prots)
for prot in prots:
variations.append(prot.gene_id)
epi_var.setdefault(prot.gene_id, set()).add(seq)
self.__peptideSet = peps
#calculate conservation
variations = set(variations)
total = len(variations)
for e, v in cons.iteritems():
try:
cons[e] = v / total
except ZeroDivisionError:
cons[e] = 1
model = ConcreteModel()
#set definition
model.Q = Set(initialize=variations)
model.E = Set(initialize=set(peps.keys()))
model.A = Set(initialize=alleles_I.keys())
model.E_var = Set(model.Q, initialize=lambda mode, v: epi_var[v])
model.A_I = Set(model.A, initialize=lambda model, a: alleles_I[a])
#parameter definition
model.k = Param(initialize=self.__k, within=PositiveIntegers, mutable=True)
model.p = Param(model.A, initialize=lambda model, a: probs[a])
model.c = Param(model.E, initialize=lambda model, e: cons[e],mutable=True)
#threshold parameters
model.i = Param(model.E, model.A, initialize=lambda model, e, a: imm[e, a])
model.t_allele = Param(initialize=0, within=NonNegativeIntegers, mutable=True)
model.t_var = Param(initialize=0, within=NonNegativeIntegers, mutable=True)
model.t_c = Param(initialize=0.0, within=NonNegativeReals, mutable=True)
# Variable Definition
model.x = Var(model.E, within=Binary)
model.y = Var(model.A, within=Binary)
model.z = Var(model.Q, within=Binary)
# Objective definition
model.Obj = Objective(
rule=lambda model: sum(model.x[e] * sum(model.p[a] * model.i[e, a] for a in model.A) for e in model.E),
sense=maximize)
#Obligatory Constraint (number of selected epitopes)
model.NofSelectedEpitopesCov = Constraint(rule=lambda model: sum(model.x[e] for e in model.E) <= model.k)
#optional constraints (in basic model they are disabled)
model.IsAlleleCovConst = Constraint(model.A,
rule=lambda model, a: sum(model.x[e] for e in model.A_I[a]) >= model.y[a])
model.MinAlleleCovConst = Constraint(rule=lambda model: sum(model.y[a] for a in model.A) >= model.t_allele)
model.IsAntigenCovConst = Constraint(model.Q,
rule=lambda model, q: sum(model.x[e] for e in model.E_var[q]) >= model.z[q])
model.MinAntigenCovConst = Constraint(rule=lambda model: sum(model.z[q] for q in model.Q) >= model.t_var)
model.EpitopeConsConst = Constraint(model.E,
rule=lambda model, e: (1 - model.c[e]) * model.x[e] <= 1 - model.t_c)
#generate instance
self.instance = model
if self.__verbosity > 0:
print "MODEL INSTANCE"
self.instance.pprint()
#constraints
self.instance.IsAlleleCovConst.deactivate()
self.instance.MinAlleleCovConst.deactivate()
self.instance.IsAntigenCovConst.deactivate()
self.instance.MinAntigenCovConst.deactivate()
self.instance.EpitopeConsConst.deactivate()
示例2: __init__
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import EpitopeConsConst [as 别名]
#.........这里部分代码省略.........
result = []
for s1,s2 in itr.combinations(model.E,2):
if s1 != s2:
if s1 in s2 or s2 in s1:
result.append((s1,s2))
m = [[0] * (1 + len(s2)) for i in xrange(1 + len(s1))]
longest, x_longest = 0, 0
for x in xrange(1, 1 + len(s1)):
for y in xrange(1, 1 + len(s2)):
if s1[x - 1] == s2[y - 1]:
m[x][y] = m[x - 1][y - 1] + 1
if m[x][y] > longest:
longest = m[x][y]
x_longest = x
else:
m[x][y] = 0
if len(s1[x_longest - longest: x_longest]) >= overlap:
result.append((s1,s2))
return set(result)
model.O = Set(dimen=2, initialize=longest_common_substring)
# parameter definition
model.k = Param(initialize=self.__k, within=PositiveIntegers, mutable=True)
model.k_taa = Param(initialize=self.__k_taa, within=NonNegativeIntegers, mutable=True)
model.p = Param(model.A, initialize=lambda model, a: max(0, math.log(probs[a]+0.001,2)))
model.c = Param(model.E, initialize=lambda model, e: cons[e],mutable=True)
model.sigma = Param (model. E, model.A, initialize=lambda model, e, a: uncertainty.get((e,a), 0))
model.i = Param(model.E, model.A, initialize=lambda model, e, a: imm[e, a])
model.t_allele = Param(initialize=0, within=NonNegativeIntegers, mutable=True)
model.t_var = Param(initialize=0, within=NonNegativeIntegers, mutable=True)
model.t_c = Param(initialize=0.0, within=NonNegativeReals, mutable=True)
model.abd = Param(model.Q, initialize=lambda model, g: max(0, math.log(expression.get(g, 2)+0.001, 2)))
model.eps1 = Param(initialize=1e6, mutable=True)
model.eps2 = Param(initialize=1e6, mutable=True)
# variable Definition
model.x = Var(model.E, within=Binary)
model.y = Var(model.A, within=Binary)
model.z = Var(model.Q, within=Binary)
# objective definition
model.Obj1 = Objective(
rule=lambda model: -sum(model.x[e] * sum(model.abd[g] for g in model.G[e])
* sum(model.p[a] * model.i[e, a] for a in model.A) for e in model.E),
sense=minimize)
model.Obj2 = Objective(
rule=lambda model: sum(model.x[e]*sum(model.sigma[e,a] for a in model.A) for e in model.E),
sense=minimize)
# constraints
# obligatory Constraint (number of selected epitopes)
model.NofSelectedEpitopesCov1 = Constraint(rule=lambda model: sum(model.x[e] for e in model.E) >= model.k)
model.NofSelectedEpitopesCov2 = Constraint(rule=lambda model: sum(model.x[e] for e in model.E) <= model.k)
model.NofSelectedTAACov = Constraint(rule=lambda model: sum(model.x[e] for e in model.TAA) <= model.k_taa)
# optional constraints (in basic model they are disabled)
model.IsAlleleCovConst = Constraint(model.A,
rule=lambda model, a: sum(model.x[e] for e in model.A_I[a]) >= model.y[a])
model.MinAlleleCovConst = Constraint(rule=lambda model: sum(model.y[a] for a in model.A) >= model.t_allele)
model.IsAntigenCovConst = Constraint(model.Q,
rule=lambda model, q: sum(model.x[e] for e in model.E_var[q]) >= model.z[q])
model.MinAntigenCovConst = Constraint(rule=lambda model: sum(model.z[q] for q in model.Q) >= model.t_var)
model.EpitopeConsConst = Constraint(model.E,
rule=lambda model, e: (1 - model.c[e]) * model.x[e] <= 1 - model.t_c)
if overlap > 0:
model.OverlappingConstraint = Constraint(model.O, rule=lambda model, e1, e2: model.x[e1]+model.x[e2] <= 1)
# constraints for Pareto optimization
model.ImmConst = Constraint(rule=lambda model: sum(model.x[e] * sum(model.abd[g] for g in model.G[e])
* sum(model.p[a] * model.i[e, a]
for a in model.A) for e in model.E) <= model.eps1)
model.UncertaintyConst = Constraint(rule=lambda model:sum(model.x[e]*sum(model.sigma[e,a]
for a in model.A)
for e in model.E) <= model.eps2)
self.__objectives = [model.Obj1, model.Obj2]
self.__constraints = [model.UncertaintyConst, model.ImmConst]
self.__epsilons = [model.eps2, model.eps1]
# include constraint
model.IncludeEpitopeConstraint = Constraint(model.Include, rule=lambda model, e: model.x[e] >= 1)
# generate instance
self.instance = model
if self.__verbosity > 0:
print "MODEL INSTANCE"
self.instance.pprint()
# constraints
self.instance.Obj2.deactivate()
self.instance.ImmConst.deactivate()
self.instance.UncertaintyConst.deactivate()
self.instance.IsAlleleCovConst.deactivate()
self.instance.MinAlleleCovConst.deactivate()
self.instance.IsAntigenCovConst.deactivate()
self.instance.MinAntigenCovConst.deactivate()
self.instance.EpitopeConsConst.deactivate()