Skip to content

Commit

Permalink
Reduce unncessary auto-attempting matches on imports
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMadBug committed Sep 27, 2021
1 parent 14e018c commit 9eb987a
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions classification/models/condition_text_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ontology.models import OntologyTerm, OntologyService, OntologySnake, OntologyTermRelation, OntologyRelation
from ontology.ontology_matching import normalize_condition_text, \
OPRPHAN_OMIM_TERMS, SearchText, pretty_set, PREFIX_SKIP_TERMS
from snpdb.models import Lab, GenomeBuild
from snpdb.models import Lab


class ConditionText(TimeStampedModel, GuardianPermissionsMixin):
Expand Down Expand Up @@ -87,7 +87,7 @@ def root(self) -> 'ConditionTextMatch':
return self.conditiontextmatch_set.filter(gene_symbol__isnull=True, mode_of_inheritance__isnull=True, classification=None).first()

@property
def gene_levels(self) -> Iterable['ConditionTextMatch']:
def gene_levels(self) -> QuerySet['ConditionTextMatch']:
return self.conditiontextmatch_set.filter(condition_text=self, gene_symbol__isnull=False, mode_of_inheritance__isnull=True, classification=None)


Expand Down Expand Up @@ -248,7 +248,7 @@ def sync_all():
ct.save()

@staticmethod
def attempt_automatch(condition_text: ConditionText):
def attempt_automatch(condition_text: ConditionText, gene_symbol: Optional[str] = None):
"""
Set terms that we're effectively certain of, do not override what's already there
"""
Expand All @@ -260,7 +260,11 @@ def attempt_automatch(condition_text: ConditionText):
root.last_edited_by = admin_bot()
root.save()
else:
for gene_symbol_level in condition_text.gene_levels:
gene_levels_qs = condition_text.gene_levels
if gene_symbol:
gene_levels_qs = gene_levels_qs.filter(gene_symbol=gene_symbol)

for gene_symbol_level in gene_levels_qs:
if match.is_auto_assignable(gene_symbol=gene_symbol_level.gene_symbol) and not gene_symbol_level.condition_xrefs:
gene_symbol_level.condition_xrefs = match.term_str_array
gene_symbol_level.last_edited_by = admin_bot()
Expand Down Expand Up @@ -291,7 +295,7 @@ def sync_condition_text_classification(cm: ClassificationModification, update_co
return

lab = classification.lab
gene_symbol: GeneSymbol = None
gene_symbol: Optional[GeneSymbol] = None
gene_symbol_str = cm.get(SpecialEKeys.GENE_SYMBOL)
if gene_symbol_str:
gene_symbol = GeneSymbol.objects.filter(symbol=gene_symbol_str).first()
Expand Down Expand Up @@ -379,10 +383,9 @@ def sync_condition_text_classification(cm: ClassificationModification, update_co
)

if attempt_automatch and (new_root or new_gene_level):
ConditionTextMatch.attempt_automatch(ct)
ConditionTextMatch.attempt_automatch(ct, gene_symbol=gene_symbol)
ct_save_required = True

if update_counts:
elif update_counts: # attempt automatch update counts
update_condition_text_match_counts(ct)
ct_save_required = True

Expand Down

0 comments on commit 9eb987a

Please sign in to comment.