forked from enviPath/enviPy
App Domain Pathway Prediction (#47)
Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#47
This commit is contained in:
@ -912,7 +912,8 @@ class Pathway(EnviPathModel, AliasMixin, ScenarioMixin):
|
||||
'reaction_probability': link['reaction_probability'],
|
||||
'scenarios': link['scenarios'],
|
||||
'source': node_url_to_idx[link['start_node_urls'][0]],
|
||||
'target': pseudo_idx
|
||||
'target': pseudo_idx,
|
||||
'app_domain': link.get('app_domain', None)
|
||||
}
|
||||
adjusted_links.append(new_link)
|
||||
|
||||
@ -927,7 +928,8 @@ class Pathway(EnviPathModel, AliasMixin, ScenarioMixin):
|
||||
'reaction_probability': link['reaction_probability'],
|
||||
'scenarios': link['scenarios'],
|
||||
'source': pseudo_idx,
|
||||
'target': node_url_to_idx[target]
|
||||
'target': node_url_to_idx[target],
|
||||
'app_domain': link.get('app_domain', None)
|
||||
}
|
||||
adjusted_links.append(new_link)
|
||||
|
||||
@ -1044,6 +1046,8 @@ class Node(EnviPathModel, AliasMixin, ScenarioMixin):
|
||||
return '{}/node/{}'.format(self.pathway.url, self.uuid)
|
||||
|
||||
def d3_json(self):
|
||||
app_domain_data = self.get_app_domain_assessment_data()
|
||||
|
||||
return {
|
||||
"depth": self.depth,
|
||||
"url": self.url,
|
||||
@ -1053,6 +1057,10 @@ class Node(EnviPathModel, AliasMixin, ScenarioMixin):
|
||||
"name": self.default_node_label.name,
|
||||
"smiles": self.default_node_label.smiles,
|
||||
"scenarios": [{'name': s.name, 'url': s.url} for s in self.scenarios.all()],
|
||||
"app_domain": {
|
||||
'inside_app_domain': app_domain_data['assessment']['inside_app_domain'] if app_domain_data else None,
|
||||
'uncovered_functional_groups': False,
|
||||
}
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
@ -1078,6 +1086,32 @@ class Node(EnviPathModel, AliasMixin, ScenarioMixin):
|
||||
def as_svg(self):
|
||||
return IndigoUtils.mol_to_svg(self.default_node_label.smiles)
|
||||
|
||||
def get_app_domain_assessment_data(self):
|
||||
data = self.kv.get('app_domain_assessment', None)
|
||||
|
||||
if data:
|
||||
rule_ids = dict()
|
||||
for e in Edge.objects.filter(start_nodes__in=[self]):
|
||||
for r in e.edge_label.rules.all():
|
||||
rule_ids[str(r.uuid)] = e
|
||||
|
||||
|
||||
for t in data['assessment']['transformations']:
|
||||
if t['rule']['uuid'] in rule_ids:
|
||||
t['is_predicted'] = True
|
||||
t['edge'] = rule_ids[t['rule']['uuid']].simple_json()
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def simple_json(self, include_description=False):
|
||||
res = super().simple_json()
|
||||
name = res.get('name', None)
|
||||
if name == 'no name':
|
||||
res['name'] = self.default_node_label.name
|
||||
|
||||
return res
|
||||
|
||||
|
||||
class Edge(EnviPathModel, AliasMixin, ScenarioMixin):
|
||||
pathway = models.ForeignKey('epdb.Pathway', verbose_name='belongs to', on_delete=models.CASCADE, db_index=True)
|
||||
@ -1090,19 +1124,44 @@ class Edge(EnviPathModel, AliasMixin, ScenarioMixin):
|
||||
return '{}/edge/{}'.format(self.pathway.url, self.uuid)
|
||||
|
||||
def d3_json(self):
|
||||
return {
|
||||
edge_json = {
|
||||
'name': self.name,
|
||||
'id': self.url,
|
||||
'url': self.url,
|
||||
'image': self.url + '?image=svg',
|
||||
'reaction': {'name': self.edge_label.name, 'url': self.edge_label.url } if self.edge_label else None,
|
||||
'reaction_probability': self.kv.get('probability'),
|
||||
# TODO
|
||||
'start_node_urls': [x.url for x in self.start_nodes.all()],
|
||||
'end_node_urls': [x.url for x in self.end_nodes.all()],
|
||||
"scenarios": [{'name': s.name, 'url': s.url} for s in self.scenarios.all()],
|
||||
}
|
||||
|
||||
for n in self.start_nodes.all():
|
||||
app_domain_data = n.get_app_domain_assessment_data()
|
||||
|
||||
if app_domain_data:
|
||||
for t in app_domain_data['assessment']['transformations']:
|
||||
if 'edge' in t and t['edge']['uuid'] == str(self.uuid):
|
||||
passes_app_domain = (
|
||||
t['local_compatibility'] >= app_domain_data['ad_params']['local_compatibility_threshold']
|
||||
) and (
|
||||
t['reliability'] >= app_domain_data['ad_params']['reliability_threshold']
|
||||
)
|
||||
|
||||
edge_json['app_domain'] = {
|
||||
'passes_app_domain': passes_app_domain,
|
||||
'local_compatibility': t['local_compatibility'],
|
||||
'local_compatibility_threshold': app_domain_data['ad_params']['local_compatibility_threshold'],
|
||||
'reliability': t['reliability'],
|
||||
'reliability_threshold': app_domain_data['ad_params']['reliability_threshold'],
|
||||
'times_triggered': t['times_triggered'],
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
return edge_json
|
||||
|
||||
|
||||
@staticmethod
|
||||
def create(pathway, start_nodes: List[Node], end_nodes: List[Node], rule: Optional[Rule] = None, name: Optional[str] = None,
|
||||
description: Optional[str] = None):
|
||||
@ -1136,6 +1195,14 @@ class Edge(EnviPathModel, AliasMixin, ScenarioMixin):
|
||||
def as_svg(self):
|
||||
return self.edge_label.as_svg if self.edge_label else None
|
||||
|
||||
def simple_json(self, include_description=False):
|
||||
res = super().simple_json()
|
||||
name = res.get('name', None)
|
||||
if name == 'no name':
|
||||
res['name'] = self.edge_label.name
|
||||
|
||||
return res
|
||||
|
||||
|
||||
class EPModel(PolymorphicModel, EnviPathModel):
|
||||
package = models.ForeignKey('epdb.Package', verbose_name='Package', on_delete=models.CASCADE, db_index=True)
|
||||
@ -1463,6 +1530,7 @@ class MLRelativeReasoning(EPModel):
|
||||
|
||||
return res
|
||||
|
||||
|
||||
class ApplicabilityDomain(EnviPathModel):
|
||||
model = models.ForeignKey(MLRelativeReasoning, on_delete=models.CASCADE)
|
||||
|
||||
@ -1614,7 +1682,7 @@ class ApplicabilityDomain(EnviPathModel):
|
||||
'model': self.model.simple_json(),
|
||||
'num_neighbours': self.num_neighbours,
|
||||
'reliability_threshold': self.reliability_threshold,
|
||||
'local_compatibilty_threshold': self.local_compatibilty_threshold,
|
||||
'local_compatibility_threshold': self.local_compatibilty_threshold,
|
||||
},
|
||||
'assessment': {
|
||||
'smiles': smiles,
|
||||
|
||||
Reference in New Issue
Block a user