forked from enviPath/enviPy
minor
This commit is contained in:
@ -11,6 +11,7 @@ from .models import (
|
||||
CompoundStructure,
|
||||
Edge,
|
||||
EnviFormer,
|
||||
EnzymeLink,
|
||||
ExternalDatabase,
|
||||
ExternalIdentifier,
|
||||
Group,
|
||||
@ -212,6 +213,10 @@ class CompoundStructureAdmin(EPAdmin):
|
||||
pass
|
||||
|
||||
|
||||
class EnzymeLinkAdmin(EPAdmin):
|
||||
pass
|
||||
|
||||
|
||||
class SimpleAmbitRuleAdmin(EPAdmin):
|
||||
pass
|
||||
|
||||
@ -266,6 +271,7 @@ admin.site.register(License, LicenseAdmin)
|
||||
admin.site.register(ClassifierPluginModel, ClassifierPluginModelAdmin)
|
||||
admin.site.register(Compound, CompoundAdmin)
|
||||
admin.site.register(CompoundStructure, CompoundStructureAdmin)
|
||||
admin.site.register(EnzymeLink, EnzymeLinkAdmin)
|
||||
admin.site.register(SimpleAmbitRule, SimpleAmbitRuleAdmin)
|
||||
admin.site.register(ParallelRule, ParallelRuleAdmin)
|
||||
admin.site.register(Reaction, ReactionAdmin)
|
||||
|
||||
@ -665,11 +665,11 @@ class PackageManager(object):
|
||||
# EDIT START
|
||||
if data.get("classification"):
|
||||
if data["classification"] == "INTERNAL":
|
||||
pack.classification = Package.Classification.RESTRICTED
|
||||
pack.classification_level = Package.Classification.RESTRICTED
|
||||
elif data["classification"] == "RESTRICTED":
|
||||
pack.classification = Package.Classification.RESTRICTED
|
||||
pack.classification_level = Package.Classification.RESTRICTED
|
||||
elif data["classification"] == "SECRET":
|
||||
pack.classification = Package.Classification.SECRET
|
||||
pack.classification_level = Package.Classification.SECRET
|
||||
|
||||
if not "datapool" in data:
|
||||
raise ValueError("Missing datapool in package")
|
||||
|
||||
@ -21,6 +21,8 @@ from epdb.models import (
|
||||
Compound,
|
||||
CompoundStructure,
|
||||
Edge,
|
||||
EnzymeLink,
|
||||
Group,
|
||||
License,
|
||||
Node,
|
||||
ParallelRule,
|
||||
@ -150,6 +152,8 @@ class ReactionExportSchema(RefReactionExportSchema):
|
||||
# Rules #
|
||||
#########
|
||||
class EnzymeExportSchema(RefEnzymeExportSchema):
|
||||
name: str
|
||||
description: str
|
||||
ec_number: str
|
||||
classification_level: int
|
||||
linking_method: str
|
||||
@ -162,12 +166,12 @@ class EnzymeRuleExportSchema(RefRuleExportSchema):
|
||||
|
||||
@staticmethod
|
||||
def resolve_enzymes(obj):
|
||||
if isinstance(obj, dict):
|
||||
res = []
|
||||
for e in obj.get("enzymes", []):
|
||||
res.append(EnzymeExportSchema.model_validate(e))
|
||||
return res
|
||||
return obj.enzymelink_set.all()
|
||||
if isinstance(obj, EnzymeRuleExportSchema):
|
||||
return obj.enzymes
|
||||
elif isinstance(obj, dict):
|
||||
return obj.get("enzymes", [])
|
||||
else:
|
||||
return obj.enzymelink_set.all()
|
||||
|
||||
|
||||
class RuleExportSchema(EnzymeRuleExportSchema):
|
||||
@ -679,6 +683,27 @@ class PackageImporter:
|
||||
for scen in elem.scenarios:
|
||||
elem_obj.scenarios.add(self._cache[scen.uuid])
|
||||
|
||||
def _import_enzyme(self, rule: Rule, enzyme: EnzymeExportSchema):
|
||||
e = EnzymeLink()
|
||||
e.uuid = str(uuid.uuid4()) if not self.preserve_uuids else enzyme.uuid
|
||||
e.rule = rule
|
||||
e.name = enzyme.name
|
||||
e.description = enzyme.description
|
||||
e.ec_number = enzyme.ec_number
|
||||
e.classification_level = enzyme.classification_level
|
||||
e.linking_method = enzyme.linking_method
|
||||
e.save()
|
||||
for reaction in enzyme.reaction_evidence:
|
||||
e.reaction_evidence.add(self._cache[reaction.uuid])
|
||||
for edge in enzyme.edge_evidence:
|
||||
e.edge_evidence.add(self._cache[edge.uuid])
|
||||
self._cache[enzyme.uuid] = e
|
||||
|
||||
def _import_and_link_enzymes(self, data: PackageExportSchema):
|
||||
for rule in data.composite_rules:
|
||||
for enzyme in rule.enzymes:
|
||||
self._import_enzyme(self._cache[rule.uuid], enzyme)
|
||||
|
||||
def _import_package_from_json(
|
||||
self,
|
||||
) -> Package:
|
||||
@ -717,6 +742,7 @@ class PackageImporter:
|
||||
self._import_scenarios(package, parsed.scenarios)
|
||||
self._import_additional_information(package, parsed.additional_information)
|
||||
self._link_scenarios_after_import(parsed)
|
||||
self._import_and_link_enzymes(parsed)
|
||||
|
||||
return package
|
||||
|
||||
|
||||
Reference in New Issue
Block a user