本文整理汇总了Python中cobra.DictList.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python DictList.get_by_id方法的具体用法?Python DictList.get_by_id怎么用?Python DictList.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cobra.DictList
的用法示例。
在下文中一共展示了DictList.get_by_id方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestDictList
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import get_by_id [as 别名]
class TestDictList(TestCase):
def setUp(self):
self.obj = Object("test1")
self.list = DictList()
self.list.append(self.obj)
def testAppend(self):
obj2 = Object("test2")
self.list.append(obj2)
self.assertRaises(ValueError, self.list.append,
Object("test1"))
self.assertEqual(self.list.index(obj2), 1)
self.assertEqual(self.list[1], obj2)
self.assertEqual(self.list.get_by_id("test2"), obj2)
self.assertEqual(len(self.list), 2)
def testExtend(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list.extend(obj_list)
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testIadd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list += obj_list
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testAdd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
sum = self.list + obj_list
self.assertEqual(self.list[0].id, "test1")
self.assertEqual(sum[1].id, "test2")
self.assertEqual(sum.get_by_id("test2"), obj_list[0])
self.assertEqual(sum[8].id, "test9")
self.assertEqual(len(self.list), 1)
self.assertEqual(len(sum), 9)
def testDeepcopy(self):
from copy import deepcopy
copied = deepcopy(self.list)
for i, v in enumerate(self.list):
assert self.list[i].id == copied[i].id
assert self.list[i] is not copied[i]
def testQuery(self):
obj2 = Object("test2")
self.list.append(obj2)
result = self.list.query("test1") # matches only test1
self.assertEqual(len(result), 1)
self.assertEqual(result[0], self.obj)
result = self.list.query("test") # matches test1 and test2
self.assertEqual(len(result), 2)
示例2: TestDictList
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import get_by_id [as 别名]
class TestDictList(TestCase):
def setUp(self):
self.obj = Object("test1")
self.list = DictList()
self.list.append(self.obj)
def testAppend(self):
obj2 = Object("test2")
self.list.append(obj2)
self.assertRaises(ValueError, self.list.append,
Object("test1"))
self.assertEqual(self.list.index(obj2), 1)
self.assertEqual(self.list[1], obj2)
self.assertEqual(self.list.get_by_id("test2"), obj2)
self.assertEqual(len(self.list), 2)
def testExtend(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list.extend(obj_list)
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testIadd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list += obj_list
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testAdd(self):
from os import name as __name
if __name == 'java':
warn('\t\n**cobra.test.unit_tests.testAdd does not yet work with %s'%__name)
return
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
sum = self.list + obj_list
self.assertEqual(self.list[0].id, "test1")
self.assertEqual(sum[1].id, "test2")
self.assertEqual(sum.get_by_id("test2"), obj_list[0])
self.assertEqual(sum[8].id, "test9")
self.assertEqual(len(self.list), 1)
self.assertEqual(len(sum), 9)
def testDeepcopy(self):
from copy import deepcopy
copied = deepcopy(self.list)
for i, v in enumerate(self.list):
assert self.list[i].id == copied[i].id
assert self.list[i] is not copied[i]
示例3: testInitCopy
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import get_by_id [as 别名]
def testInitCopy(self):
self.list.append(Object("test2"))
copied = DictList(self.list)
self.assertIsNot(self.list, copied)
self.assertIsInstance(copied, self.list.__class__)
self.assertEqual(len(self.list), len(copied))
for i, v in enumerate(self.list):
self.assertEqual(self.list[i].id, copied[i].id)
self.assertEqual(i, copied.index(v.id))
self.assertIs(self.list[i], copied[i])
self.assertIs(v, copied.get_by_id(v.id))
示例4: test_init_copy
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import get_by_id [as 别名]
def test_init_copy(self, dict_list):
obj, test_list = dict_list
test_list.append(Object("test2"))
copied = DictList(test_list)
assert test_list is not copied
assert isinstance(copied, test_list.__class__)
assert len(test_list) == len(copied)
for i, v in enumerate(test_list):
assert test_list[i].id == copied[i].id
assert i == copied.index(v.id)
assert test_list[i] is copied[i]
assert v is copied.get_by_id(v.id)
示例5: TestDictList
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import get_by_id [as 别名]
class TestDictList(TestCase):
def setUp(self):
self.obj = Object("test1")
self.list = DictList()
self.list.append(self.obj)
def testAppend(self):
obj2 = Object("test2")
self.list.append(obj2)
self.assertRaises(ValueError, self.list.append, Object("test1"))
self.assertEqual(self.list.index(obj2), 1)
self.assertEqual(self.list[1], obj2)
self.assertEqual(self.list.get_by_id("test2"), obj2)
self.assertEqual(len(self.list), 2)
def testExtend(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list.extend(obj_list)
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testIadd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list += obj_list
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testAdd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
sum = self.list + obj_list
self.assertEqual(self.list[0].id, "test1")
self.assertEqual(sum[1].id, "test2")
self.assertEqual(sum.get_by_id("test2"), obj_list[0])
self.assertEqual(sum[8].id, "test9")
self.assertEqual(len(self.list), 1)
self.assertEqual(len(sum), 9)
示例6: TestDictList
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import get_by_id [as 别名]
class TestDictList(TestCase):
def setUp(self):
self.obj = Object("test1")
self.list = DictList()
self.list.append(self.obj)
def testContains(self):
self.assertIn(self.obj, self.list)
self.assertIn(self.obj.id, self.list)
self.assertNotIn(Object("not_in"), self.list)
self.assertNotIn('not_in', self.list)
def testIndex(self):
self.assertEqual(self.list.index("test1"), 0)
self.assertEqual(self.list.index(self.obj), 0)
self.assertRaises(ValueError, self.list.index, "f")
self.assertRaises(ValueError, self.list.index, Object("f"))
# ensure trying to index with an object that is a different object
# also raises an error
self.assertRaises(ValueError, self.list.index, Object("test1"))
def testIndependent(self):
a = DictList([Object("o1"), Object("o2")])
b = DictList()
self.assertIn("o1", a)
self.assertNotIn("o1", b)
b.append(Object("o3"))
self.assertNotIn("o3", a)
self.assertIn("o3", b)
def testAppend(self):
obj2 = Object("test2")
self.list.append(obj2)
self.assertRaises(ValueError, self.list.append, Object("test1"))
self.assertEqual(self.list.index(obj2), 1)
self.assertEqual(self.list[1], obj2)
self.assertIs(self.list.get_by_id("test2"), obj2)
self.assertEqual(len(self.list), 2)
def testInsert(self):
obj2 = Object("a")
self.list.insert(0, obj2)
self.assertEqual(self.list.index(obj2), 0)
self.assertEqual(self.list.index("test1"), 1)
self.assertIs(self.list.get_by_id("a"), obj2)
self.assertEqual(len(self.list), 2)
self.assertRaises(ValueError, self.list.append, obj2)
def testExtend(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list.extend(obj_list)
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
self.assertRaises(ValueError, self.list.extend, [Object("test1")])
# Even if the object is unique, if it is present twice in the new
# list, it should still raise an exception
self.assertRaises(ValueError, self.list.extend,
[Object("testd"), Object("testd")])
def testIadd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list += obj_list
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testAdd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
sum = self.list + obj_list
self.assertIsNot(sum, self.list)
self.assertIsNot(sum, obj_list)
self.assertEqual(self.list[0].id, "test1")
self.assertEqual(sum[1].id, "test2")
self.assertEqual(sum.get_by_id("test2"), obj_list[0])
self.assertEqual(sum[8].id, "test9")
self.assertEqual(len(self.list), 1)
self.assertEqual(len(sum), 9)
def testInitCopy(self):
self.list.append(Object("test2"))
copied = DictList(self.list)
self.assertIsNot(self.list, copied)
self.assertIsInstance(copied, self.list.__class__)
self.assertEqual(len(self.list), len(copied))
for i, v in enumerate(self.list):
self.assertEqual(self.list[i].id, copied[i].id)
self.assertEqual(i, copied.index(v.id))
self.assertIs(self.list[i], copied[i])
self.assertIs(v, copied.get_by_id(v.id))
def testSlice(self):
self.list.append(Object("test2"))
self.list.append(Object("test3"))
sliced = self.list[:-1]
self.assertIsNot(self.list, sliced)
self.assertIsInstance(sliced, self.list.__class__)
self.assertEqual(len(self.list), len(sliced) + 1)
#.........这里部分代码省略.........
示例7: TestDictList
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import get_by_id [as 别名]
class TestDictList(TestCase):
def setUp(self):
self.obj = Object("test1")
self.list = DictList()
self.list.append(self.obj)
def testContains(self):
self.assertIn(self.obj, self.list)
self.assertIn(self.obj.id, self.list)
self.assertNotIn(Object("not_in"), self.list)
self.assertNotIn('not_in', self.list)
def testIndex(self):
self.assertEqual(self.list.index("test1"), 0)
self.assertEqual(self.list.index(self.obj), 0)
self.assertRaises(ValueError, self.list.index, "f")
self.assertRaises(ValueError, self.list.index, Object("f"))
def testIndependent(self):
a = DictList([Object("o1"), Object("o2")])
b = DictList()
self.assertIn("o1", a)
self.assertNotIn("o1", b)
b.append(Object("o3"))
self.assertNotIn("o3", a)
self.assertIn("o3", b)
def testAppend(self):
obj2 = Object("test2")
self.list.append(obj2)
self.assertRaises(ValueError, self.list.append, Object("test1"))
self.assertEqual(self.list.index(obj2), 1)
self.assertEqual(self.list[1], obj2)
self.assertEqual(self.list.get_by_id("test2"), obj2)
self.assertEqual(len(self.list), 2)
def testExtend(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list.extend(obj_list)
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
self.assertRaises(ValueError, self.list.extend, [Object("test1")])
# Even if the object is unique, if it is present twice in the new
# list, it should still raise an exception
self.assertRaises(ValueError, self.list.extend,
[Object("testd"), Object("testd")])
def testIadd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list += obj_list
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testAdd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
sum = self.list + obj_list
self.assertIsNot(sum, self.list)
self.assertIsNot(sum, obj_list)
self.assertEqual(self.list[0].id, "test1")
self.assertEqual(sum[1].id, "test2")
self.assertEqual(sum.get_by_id("test2"), obj_list[0])
self.assertEqual(sum[8].id, "test9")
self.assertEqual(len(self.list), 1)
self.assertEqual(len(sum), 9)
def testInitCopy(self):
self.list.append(Object("test2"))
copied = DictList(self.list)
self.assertIsNot(self.list, copied)
self.assertIsInstance(copied, self.list.__class__)
self.assertEqual(len(self.list), len(copied))
for i, v in enumerate(self.list):
self.assertEqual(self.list[i].id, copied[i].id)
self.assertEqual(i, copied.index(v.id))
self.assertIs(self.list[i], copied[i])
self.assertIs(v, copied.get_by_id(v.id))
def testSlice(self):
self.list.append(Object("test2"))
self.list.append(Object("test3"))
sliced = self.list[:-1]
self.assertIsNot(self.list, sliced)
self.assertIsInstance(sliced, self.list.__class__)
self.assertEqual(len(self.list), len(sliced) + 1)
for i, v in enumerate(sliced):
self.assertEqual(self.list[i].id, sliced[i].id)
self.assertEqual(i, sliced.index(v.id))
self.assertIs(self.list[i], sliced[i])
self.assertIs(self.list[i], sliced.get_by_id(v.id))
def testCopy(self):
self.list.append(Object("test2"))
copied = copy(self.list)
self.assertIsNot(self.list, copied)
self.assertIsInstance(copied, self.list.__class__)
self.assertEqual(len(self.list), len(copied))
#.........这里部分代码省略.........
示例8: TestDictList
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import get_by_id [as 别名]
class TestDictList(TestCase):
def setUp(self):
self.obj = Object("test1")
self.list = DictList()
self.list.append(self.obj)
def testIndependent(self):
a = DictList([Object("o1"), Object("o2")])
b = DictList()
self.assertIn("o1", a)
self.assertNotIn("o1", b)
b.append(Object("o3"))
self.assertNotIn("o3", a)
self.assertIn("o3", b)
def testAppend(self):
obj2 = Object("test2")
self.list.append(obj2)
self.assertRaises(ValueError, self.list.append,
Object("test1"))
self.assertEqual(self.list.index(obj2), 1)
self.assertEqual(self.list[1], obj2)
self.assertEqual(self.list.get_by_id("test2"), obj2)
self.assertEqual(len(self.list), 2)
def testExtend(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list.extend(obj_list)
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testIadd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
self.list += obj_list
self.assertEqual(self.list[1].id, "test2")
self.assertEqual(self.list.get_by_id("test2"), obj_list[0])
self.assertEqual(self.list[8].id, "test9")
self.assertEqual(len(self.list), 9)
def testAdd(self):
obj_list = [Object("test%d" % (i)) for i in range(2, 10)]
sum = self.list + obj_list
self.assertEqual(self.list[0].id, "test1")
self.assertEqual(sum[1].id, "test2")
self.assertEqual(sum.get_by_id("test2"), obj_list[0])
self.assertEqual(sum[8].id, "test9")
self.assertEqual(len(self.list), 1)
self.assertEqual(len(sum), 9)
def testDeepcopy(self):
from copy import deepcopy
copied = deepcopy(self.list)
for i, v in enumerate(self.list):
self.assertEqual(self.list[i].id, copied[i].id)
self.assertIsNot(self.list[i], copied[i])
def testQuery(self):
obj2 = Object("test2")
self.list.append(obj2)
result = self.list.query("test1") # matches only test1
self.assertEqual(len(result), 1)
self.assertEqual(result[0], self.obj)
result = self.list.query("test") # matches test1 and test2
self.assertEqual(len(result), 2)
def testRemoval(self):
obj_list = DictList(Object("test%d" % (i)) for i in range(2, 10))
del obj_list[3]
self.assertNotIn("test5", obj_list)
self.assertEqual(obj_list.index(obj_list[-1]), len(obj_list) - 1)
del obj_list[3:5]
self.assertNotIn("test6", obj_list)
self.assertNotIn("test7", obj_list)
self.assertEqual(obj_list.index(obj_list[-1]), len(obj_list) - 1)
removed = obj_list.pop(1)
self.assertEqual(obj_list.index(obj_list[-1]), len(obj_list) - 1)
self.assertEqual(removed.id, "test3")
self.assertNotIn("test3", obj_list)
def testSet(self):
obj_list = DictList(Object("test%d" % (i)) for i in range(10))
obj_list[4] = Object("testa")
self.assertEqual(obj_list.index("testa"), 4)
self.assertEqual(obj_list[4].id, "testa")
obj_list[5:7] = [Object("testb"), Object("testc")]
self.assertEqual(obj_list.index("testb"), 5)
self.assertEqual(obj_list[5].id, "testb")
self.assertEqual(obj_list.index("testc"), 6)
self.assertEqual(obj_list[6].id, "testc")
示例9: MEmodel
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import get_by_id [as 别名]
class MEmodel(Model):
def __init__(self, *args):
Model.__init__(self, *args)
self.global_info = {}
self.stoichiometric_data = DictList()
self.complex_data = DictList()
self.modification_data = DictList()
self.translation_data = DictList()
self.transcription_data = DictList()
self.generic_data = DictList()
self.tRNA_data = DictList()
self.translocation_data = DictList()
self.posttranslation_data = DictList()
self.subreaction_data = DictList()
self.process_data = DictList()
# create the biomass/dilution constraint
self._biomass = Constraint("biomass")
self._biomass_dilution = SummaryVariable("biomass_dilution")
self._biomass_dilution.add_metabolites({self._biomass: -1})
self.add_reaction(self._biomass_dilution)
self._biomass_dilution.upper_bound = mu
self._biomass_dilution.lower_bound = mu
# Unmodeled protein is handled by converting protein_biomass to
# biomass, and requiring production of the appropriate amount of dummy
# protein
self._unmodeled_protein_fraction = None
self._protein_biomass = Constraint("protein_biomass")
self._protein_biomass_dilution = SummaryVariable("protein_biomass_dilution")
self._protein_biomass_dilution.add_metabolites({
self._protein_biomass: -1,
self._biomass: 1,
})
self._mRNA_biomass = Constraint("mRNA_biomass")
self._mRNA_biomass_dilution = SummaryVariable("mRNA_biomass_dilution")
self._mRNA_biomass_dilution.add_metabolites({
self._mRNA_biomass: -1,
self._biomass: 1,
})
self._tRNA_biomass = Constraint("tRNA_biomass")
self._tRNA_biomass_dilution = SummaryVariable("tRNA_biomass_dilution")
self._tRNA_biomass_dilution.add_metabolites({
self._tRNA_biomass: -1,
self._biomass: 1,
})
self._rRNA_biomass = Constraint("rRNA_biomass")
self._rRNA_biomass_dilution = SummaryVariable("rRNA_biomass_dilution")
self._rRNA_biomass_dilution.add_metabolites({
self._rRNA_biomass: -1,
self._biomass: 1,
})
self._ncRNA_biomass = Constraint("ncRNA_biomass")
self._ncRNA_biomass_dilution = SummaryVariable("ncRNA_biomass_dilution")
self._ncRNA_biomass_dilution.add_metabolites({
self._ncRNA_biomass: -1,
self._biomass: 1,
})
self.add_reactions((self._protein_biomass_dilution,
self._mRNA_biomass_dilution,
self._tRNA_biomass_dilution,
self._rRNA_biomass_dilution,
self._ncRNA_biomass_dilution))
self._DNA_biomass = Constraint("DNA_biomass")
self._DNA_biomass_dilution = SummaryVariable("DNA_biomass_dilution")
self._DNA_biomass_dilution.add_metabolites({
self._DNA_biomass: -1e-3,
self._biomass: 1e-3,
})
self._DNA_biomass_dilution.lower_bound = mu
self._DNA_biomass_dilution.upper_bound = mu
@property
def unmodeled_protein(self):
return self.metabolites.get_by_id("protein_dummy")
@property
def unmodeled_protein_fraction(self):
return self._unmodeled_protein_fraction
@unmodeled_protein_fraction.setter
def unmodeled_protein_fraction(self, value):
# proportion = value / (1 - value)
# see the Biomass_formulations for an explanation
amount = value / self.unmodeled_protein.mass
self._protein_biomass_dilution.add_metabolites(
{self.unmodeled_protein: -amount}, combine=False)
self._protein_biomass_dilution.add_metabolites(
{self._biomass: 1+value}, combine=False)
self._unmodeled_protein_fraction = value
def get_metabolic_flux(self, solution=None):
"""extract the flux state for metabolic reactions"""
if solution is None:
solution = self.solution
if solution.status != "optimal":
raise ValueError("solution status '%s' is not 'optimal'" %
solution.status)
flux_dict = {r.id: 0 for r in self.stoichiometric_data}
for reaction in self.reactions:
#.........这里部分代码省略.........
示例10: StrainDesign
# 需要导入模块: from cobra import DictList [as 别名]
# 或者: from cobra.DictList import get_by_id [as 别名]
class StrainDesign(object):
"""
A StrainDesign is a collection of targets in a COBRA model. The targets, identified by a StrainDesignMethod,
map elements in the model that need to be modified to achieve the objective of the design method.
"""
def __init__(self, targets):
self.targets = DictList(targets)
def __str__(self):
return ", ".join(str(t) for t in self.targets)
def __repr__(self):
return "<StrainDesign [" + ";".join(repr(t) for t in self.targets) + "]>"
def __iter__(self):
return iter(self.targets)
def __len__(self):
return len(self.targets)
def __contains__(self, item):
if isinstance(item, Target):
if item in self.targets:
return item == self.targets.get_by_id(item.id)
else:
return False
elif isinstance(item, six.string_types):
return item in self.targets
else:
return False
def __eq__(self, other):
if isinstance(other, StrainDesign):
if len(self) != len(other):
return False
else:
return all(t in other for t in self.targets) and all(t in self for t in other.targets)
else:
return False
def apply(self, model):
for target in self.targets:
target.apply(model)
def __add__(self, other):
if not isinstance(other, StrainDesign):
raise AssertionError("Only instances of StrainDesign can be added together")
targets = {}
for target in self.targets:
if target.id not in targets:
targets[target.id] = set()
targets[target.id].add(target)
for target in other.targets:
if target.id not in targets:
targets[target.id] = set()
targets[target.id].add(target)
targets = [next(iter(t)) if len(t) == 1 else EnsembleTarget(id, t) for id, t in six.iteritems(targets)]
return StrainDesign(targets)
def __iadd__(self, other):
if not isinstance(other, StrainDesign):
raise AssertionError("Only instances of StrainDesign can be added together")
targets = {}
for target in self.targets:
if target.id not in targets:
targets[target.id] = set()
targets[target.id].add(target)
for target in other.targets:
if target.id not in targets:
targets[target.id] = set()
targets[target.id].add(target)
targets = [next(iter(t)) if len(t) == 1 else EnsembleTarget(id, t) for id, t in six.iteritems(targets)]
self.targets = DictList(targets)
return self
def _repr_html_(self):
return " ".join(t._repr_html_() for t in self.targets)
def to_gnomic(self):
return Genotype([target.to_gnomic() for target in self.targets])