Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/KarrLab/wc_kb
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Apr 20, 2018
2 parents 4a2caec + 30fd1da commit a677bc1
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 41 deletions.
95 changes: 58 additions & 37 deletions tests/test_core.py
Expand Up @@ -50,17 +50,15 @@ def test_constructor(self):
class CellTestCase(unittest.TestCase):
def test_constructor(self):
cell = core.Cell()

self.assertEqual(cell.knowledge_base, None)
self.assertEqual(cell.species_types, [])
self.assertEqual(cell.species_types.get(__type=core.DnaSpeciesType), [])

dna = [
core.DnaSpeciesType(id='chr1', seq='AAA'),
core.DnaSpeciesType(id='chr2', seq='CCC'),
]
self.assertEqual(cell.compartments, [])
self.assertEqual(cell.reactions, [])
self.assertEqual(cell.loci, [])

cell = core.Cell(species_types=dna)
self.assertEqual(cell.species_types, dna)
self.assertEqual(cell.species_types.get(__type=core.DnaSpeciesType), [])
self.assertEqual(cell.loci.get(__type=core.PromoterLocus), [])


class CompartmentTestCase(unittest.TestCase):
Expand Down Expand Up @@ -503,32 +501,7 @@ def test(self):


class ReactionTestCase(unittest.TestCase):
def test_constructor(self):
cell1 = core.Cell()
compartment1 = core.Compartment(cell=cell1)
species1 = core.MetaboliteSpeciesType(id='1')
species2 = core.MetaboliteSpeciesType(id='2')
participant1 = core.ReactionParticipant(species_types=[species1], compartments=[compartment1], coefficient=1)
participant2 = core.ReactionParticipant(species_types=[species2], compartments=[compartment1], coefficient=1)

reaction1 = core.Reaction(
id='reaction1',
name='test_reaction',
cell=cell1,
participants=[participant1, participant2],
k_m=0.1,
v_max=0.5,
reversible=0)

self.assertEqual(reaction1.id, 'reaction1')
self.assertEqual(reaction1.name, 'test_reaction')
self.assertEqual(reaction1.cell, cell1)
self.assertEqual(reaction1.participants, [participant1, participant2])
self.assertEqual(reaction1.k_m, 0.1)
self.assertEqual(reaction1.v_max, 0.5)
self.assertEqual(reaction1.reversible, 0)

def test_constructor(self):
def test_Reaction(self):
cell_1 = core.Cell()
compartment_1 = core.Compartment(cell=cell_1)
species_type_1 = core.MetaboliteSpeciesType(id='1')
Expand Down Expand Up @@ -557,6 +530,54 @@ def test_constructor(self):


class ComplexSpeciesTypeTestCase(unittest.TestCase):
@unittest.skip('Implement tests')
def test(self):
pass # todo: add tests
def test_ComplexSpeciesType(self):

# Test constructor
complex1 = core.ComplexSpeciesType()

self.assertEqual(complex1.region, '')
self.assertEqual(complex1.binding, '')
self.assertEqual(complex1.complex_type, '')
self.assertEqual(complex1.formation_process, None)
self.assertEqual(complex1.formation_reaction, None)

# prot1: = Collagen Type IV a3 (https://pubchem.ncbi.nlm.nih.gov/compound/44511378)
dna1 = core.DnaSpeciesType(seq=Bio.Seq.Seq(
'TGTAATTATTATTCTAATTCTTATTCTTTTTGGTTAGCTTCTTTAAATCCTGAACGT', alphabet=Bio.Alphabet.DNAAlphabet()))
cell1 = dna1.cell = core.Cell()
cell1.knowledge_base = core.KnowledgeBase(translation_table=1)
gene1 = core.GeneLocus(id='gene1', cell=cell1, polymer=dna1, start=1, end=dna1.get_len(), strand=core.PolymerStrand.positive)
tu1 = core.TranscriptionUnitLocus(id='tu1', genes=[gene1], polymer=dna1)
prot1 = core.ProteinSpeciesType(id='prot1', gene=gene1)

# prot2: Tuftsin (hhttps://pubchem.ncbi.nlm.nih.gov/compounds/156080)
dna2 = core.DnaSpeciesType(seq=Bio.Seq.Seq('ACTAAACCTCGT', alphabet=Bio.Alphabet.DNAAlphabet()))
cell1 = dna2.cell = core.Cell()
cell1.knowledge_base = core.KnowledgeBase(translation_table=1)
gene2 = core.GeneLocus(id='gene2', cell=cell1, polymer=dna2, start=1, end=dna2.get_len(), strand=core.PolymerStrand.positive)
tu2 = core.TranscriptionUnitLocus(id='tu2', genes=[gene2], polymer=dna2)
prot2 = core.ProteinSpeciesType(id='prot2', gene=gene2)

# Test adding formation reaction
# Add formation reaction: [c]: (2) prot1 + (3) prot2 ==> complex1
comp1 = core.Compartment(id='comp1')
species1 = core.Species(species_type=prot1, compartment=comp1)
species2 = core.Species(species_type=prot2, compartment=comp1)
species_coeff1 = core.SpeciesCoefficient(species=species1, coefficient=2)
species_coeff2 = core.SpeciesCoefficient(species=species2, coefficient=3)
reaction1 = core.Reaction(participants=[species_coeff1,species_coeff2])
complex1.formation_reaction = reaction1

self.assertEqual(complex1.get_subunits(), [prot1, prot1, prot2, prot2, prot2])

# test get_charge
self.assertEqual(complex1.get_charge(), 6)

# test get_mol_wt
self.assertAlmostEqual(complex1.get_mol_wt(), 6130.837)

# test get_empirical_formula
self.assertEqual(complex1.get_empirical_formula(), chem.EmpiricalFormula('C273H408N76O82S2'))

class ReactionParticipantAttributeTestCase(unittest.TestCase):
def test_ReactionParticipantAttribute(self): pass
4 changes: 2 additions & 2 deletions wc_kb/__init__.py
Expand Up @@ -5,14 +5,14 @@
# :obj:`str`: version

# API
from .core import (PolymerStrand,
KnowledgeBaseObject,
from .core import (KnowledgeBaseObject,
KnowledgeBase,
Cell,
Compartment,
SpeciesType,
MetaboliteSpeciesType,
PolymerSpeciesType,
ComplexSpeciesType,
DnaSpeciesType,
RnaType,
RnaSpeciesType,
Expand Down
5 changes: 3 additions & 2 deletions wc_kb/core.py
Expand Up @@ -520,7 +520,7 @@ class PolymerLocus(KnowledgeBaseObject):

cell = obj_model.core.ManyToOneAttribute(Cell, related_name='loci')
polymer = obj_model.core.ManyToOneAttribute(PolymerSpeciesType, related_name='loci')
strand = obj_model.core.EnumAttribute(PolymerStrand, default=PolymerStrand.positive, none=True)
strand = obj_model.core.EnumAttribute(PolymerStrand, default=PolymerStrand.positive) #dropped none = True flag
start = obj_model.core.IntegerAttribute()
end = obj_model.core.IntegerAttribute()

Expand Down Expand Up @@ -943,8 +943,9 @@ def get_empirical_formula(self):
:obj:`chem.EmpiricalFormula`: empirical formula
"""
# Formula addition
formula = chem.EmpiricalFormula()
for subunit in self.get_subunits():
formula = subunit.get_empirical_formula()
formula = formula + subunit.get_empirical_formula()

return formula

Expand Down

0 comments on commit a677bc1

Please sign in to comment.