Skip to content

Commit

Permalink
delaying validation until after implicit relationships are constructed
Browse files Browse the repository at this point in the history
  • Loading branch information
jonrkarr committed Apr 21, 2018
1 parent df7f0a3 commit 359e447
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions wc_kb/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

from . import core
from wc_utils.util.string import indent_forest
import Bio.SeqIO
import Bio.SeqRecord
import obj_model
Expand Down Expand Up @@ -76,11 +77,11 @@ def run(self, knowledge_base, core_path, seq_path):
# export core
_, ext = os.path.splitext(core_path)
writer = obj_model.io.get_writer(ext)()

kwargs = {}
if isinstance(writer, obj_model.io.WorkbookWriter):
kwargs['include_all_attributes'] = False

writer.run(core_path, [knowledge_base], models=self.model_order,
language='wc_kb',
creator='{}.{}'.format(self.__class__.__module__, self.__class__.__name__),
Expand Down Expand Up @@ -171,7 +172,7 @@ def run(self, core_path, seq_path, strict=True):
kwargs['ignore_extra_attributes'] = True
kwargs['ignore_attribute_order'] = True

objects = reader.run(core_path, models=Writer.model_order, **kwargs)
objects = reader.run(core_path, models=Writer.model_order, validate=False, **kwargs)

# check that file has 0 or 1 knowledge bases
if not objects[core.KnowledgeBase]:
Expand Down Expand Up @@ -214,6 +215,17 @@ def run(self, core_path, seq_path, strict=True):
for dna in Bio.SeqIO.parse(seq_path, "fasta"):
kb.cell.species_types.get_one(id=dna.id).seq = dna.seq

# validate
objs = []
for cls_objs in objects.values():
objs.extend(cls_objs)

errors = obj_model.Validator().validate(objs)
if errors:
raise ValueError(
indent_forest(['The knowledge base cannot be loaded because it fails to validate:', [errors]]))

# return kb
return kb


Expand Down

0 comments on commit 359e447

Please sign in to comment.