<commit_before># -*- coding: utf-8 -*-
"""

"main concept of MongoDB is embed whenever possible"
Ref: http://stackoverflow.com/questions/4655610#comment5129510_4656431
"""
from __future__ import (absolute_import, division)
import itertools

from mongoengine import (Document, EmbeddedDocument, EmbeddedDocumentField,
                         FloatField, IntField, ListField, StringField,
                         ReferenceField, SortedListField, Q)

from . import (CONSERVATION, ACMG_TERMS, GENETIC_MODELS)
from .gene import Gene
from scout._compat import zip
from scout.models import Event

######## These are defined terms for different categories ########


class Compound(EmbeddedDocument):
  # This must be the document_id for this variant
  variant = ReferenceField('Variant')
  # This is the variant id
  display_name = StringField(required=True)
  combined_score = FloatField(required=True)


class GTCall(EmbeddedDocument):
  sample_id = StringField()
  display_name = StringField()
  genotype_call = StringField()
  allele_depths = ListField(IntField())
  read_depth = IntField()
  genotype_quality = IntField()

  def __unicode__(self):
    return self.display_name


class Variant(Document):
  # document_id is a md5 string created by institute_genelist_caseid_variantid:
  document_id = StringField(primary_key=True)
  # variant_id is a md5 string created by variant_id
  variant_id = StringField(required=True)
  # display name in variant_id (no md5)
  display_name = StringField(required=True)
  # The variant can be either a reserch variant or a clinical variant.
  # For research variants we display all the available information while
  # the clinical variants hae limited annotation fields.
  variant_type = StringField(required=True,
                             choices=('research', 'clinical'))
  # case_id is a string like owner_caseid
  case_id = StringField(required=True)
  chromosome = StringField(required=True)
  position = IntField(required=True)
  reference = StringField(required=True)
  alternative = StringField(required=True)
  rank_score = FloatField(required=True)
  variant_rank = IntField(required=True)
  institute = ReferenceField('Institute', required=True)
  quality = FloatField()
  filters = ListField(StringField())
  samples = ListField(EmbeddedDocumentField(GTCall))
  genetic_models = ListField(StringField(choices=GENETIC_MODELS))
  compounds = SortedListField(EmbeddedDocumentField(Compound),
                              ordering='combined_score', reverse=True)

  genes = ListField(EmbeddedDocumentField(Gene))
  db_snp_ids = ListField(StringField())
  # Gene ids:
  hgnc_symbols = ListField(StringField())
  ensembl_gene_ids = ListField(StringField())
  # Frequencies:
  thousand_genomes_frequency = FloatField()
  exac_frequency = FloatField()
  local_frequency = FloatField()
  # Predicted deleteriousness:
  cadd_score = FloatField()
  clnsig = IntField()

  @property
  def reduced_penetrance_genes(self):
    return (gene for gene in self.genes if gene.reduced_penetrance)

  def has_comments(self, case):
    """
    Return True is there are any comments for this variant in the database
    """
    events = Event.objects.filter(Q(verb='comment') &
                                  Q(variant_id=self.variant_id) &
                                  Q(institute=self.institute) &
                                  (Q(case=case) | Q(level='global')))

    return True if events else False<commit_msg>Added clnsigacc to variant model<commit_after># -*- coding: utf-8 -*-
"""

"main concept of MongoDB is embed whenever possible"
Ref: http://stackoverflow.com/questions/4655610#comment5129510_4656431
"""
from __future__ import (absolute_import, division)
import itertools

from mongoengine import (Document, EmbeddedDocument, EmbeddedDocumentField,
                         FloatField, IntField, ListField, StringField,
                         ReferenceField, SortedListField, Q)

from . import (CONSERVATION, ACMG_TERMS, GENETIC_MODELS)
from .gene import Gene
from scout._compat import zip
from scout.models import Event

######## These are defined terms for different categories ########


class Compound(EmbeddedDocument):
  # This must be the document_id for this variant
  variant = ReferenceField('Variant')
  # This is the variant id
  display_name = StringField(required=True)
  combined_score = FloatField(required=True)


class GTCall(EmbeddedDocument):
  sample_id = StringField()
  display_name = StringField()
  genotype_call = StringField()
  allele_depths = ListField(IntField())
  read_depth = IntField()
  genotype_quality = IntField()

  def __unicode__(self):
    return self.display_name


class Variant(Document):
  # document_id is a md5 string created by institute_genelist_caseid_variantid:
  document_id = StringField(primary_key=True)
  # variant_id is a md5 string created by variant_id
  variant_id = StringField(required=True)
  # display name in variant_id (no md5)
  display_name = StringField(required=True)
  # The variant can be either a reserch variant or a clinical variant.
  # For research variants we display all the available information while
  # the clinical variants hae limited annotation fields.
  variant_type = StringField(required=True,
                             choices=('research', 'clinical'))
  # case_id is a string like owner_caseid
  case_id = StringField(required=True)
  chromosome = StringField(required=True)
  position = IntField(required=True)
  reference = StringField(required=True)
  alternative = StringField(required=True)
  rank_score = FloatField(required=True)
  variant_rank = IntField(required=True)
  institute = ReferenceField('Institute', required=True)
  quality = FloatField()
  filters = ListField(StringField())
  samples = ListField(EmbeddedDocumentField(GTCall))
  genetic_models = ListField(StringField(choices=GENETIC_MODELS))
  compounds = SortedListField(EmbeddedDocumentField(Compound),
                              ordering='combined_score', reverse=True)

  genes = ListField(EmbeddedDocumentField(Gene))
  db_snp_ids = ListField(StringField())
  # Gene ids:
  hgnc_symbols = ListField(StringField())
  ensembl_gene_ids = ListField(StringField())
  # Frequencies:
  thousand_genomes_frequency = FloatField()
  exac_frequency = FloatField()
  local_frequency = FloatField()
  # Predicted deleteriousness:
  cadd_score = FloatField()
  clnsig = IntField()
  clnsigacc = StringField()

  @property
  def reduced_penetrance_genes(self):
    return (gene for gene in self.genes if gene.reduced_penetrance)

  def has_comments(self, case):
    """
    Return True is there are any comments for this variant in the database
    """
    events = Event.objects.filter(Q(verb='comment') &
                                  Q(variant_id=self.variant_id) &
                                  Q(institute=self.institute) &
                                  (Q(case=case) | Q(level='global')))

    return True if events else False
{'fraction_non_alphanumeric': 0.08856035596382948, 'fraction_numerical': 0.0071766901105210276, 'mean_word_length': 3.9771428571428573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4309452', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1973, 'n_words': 517}