Beispiel #1
0
from avocado.query.translators import Translator, registry
from modeltree.tree import trees


class AllowMissingRecord(Translator):
    """HGMD is the only source of data for the variant-phenotype assocations.
    This leads to a nuance in what it means to "not be in HGMD". By default,
    Avocado adds a second condition to ensure the ID is also not null if the
    field itself is nullable (to exclude missing records). However because
    records _only_ exist if there is an HGMD ID, this behavior is confusing.

    This translator overrides this behavior and adds an OR to allow for no
    records if querying for an explicit NULL.
    """
    def translate(self, field, roperator, rvalue, tree, **kwargs):
        output = super(AllowMissingRecord, self).translate(field, roperator, rvalue, tree, **kwargs)
        cleaned_data = output['cleaned_data']

        if cleaned_data['operator'].lookup == 'isnull' and cleaned_data['value']:
            # Create a null condition for this field
            null_condition = trees[tree].query_condition(field.model._meta.pk, 'isnull', True)
            # Allow the null condition
            output['query_modifiers']['condition'] = null_condition
        return output


registry.register(AllowMissingRecord, 'Allow Missing Record')
Beispiel #2
0
from avocado.query.translators import Translator, registry
from modeltree.tree import trees


class AllowNullsTranslator(Translator):
    """For data sources that only apply to SNPs, this translator ensures only
    SNPs are filtered down and not other types of variants.
    """
    def translate(self, field, roperator, rvalue, tree, **kwargs):
        output = super(AllowNullsTranslator, self).translate(
            field, roperator, rvalue, tree, **kwargs)

        # We are excluding nulls in the case of range, gt, and gte operators.
        # If we did not do this, then null values would be included all the
        # time which would be confusing, especially then they are included
        # for both lt and gt queries as it appears nulls are simultaneously
        # 0 and infinity.
        if roperator not in ('range', 'gt', 'gte'):
            # Create a null condition for this field
            null_condition = trees[tree].query_condition(
                field.field, 'isnull', True)
            # Allow the null condition
            output['query_modifiers']['condition'] |= null_condition

        return output


registry.register(AllowNullsTranslator, 'Allow Nulls')
Beispiel #3
0
from modeltree.tree import trees


class AllowMissingRecord(Translator):
    """HGMD is the only source of data for the variant-phenotype assocations.
    This leads to a nuance in what it means to "not be in HGMD". By default,
    Avocado adds a second condition to ensure the ID is also not null if the
    field itself is nullable (to exclude missing records). However because
    records _only_ exist if there is an HGMD ID, this behavior is confusing.

    This translator overrides this behavior and adds an OR to allow for no
    records if querying for an explicit NULL.
    """
    def translate(self, field, roperator, rvalue, tree, **kwargs):
        output = super(AllowMissingRecord,
                       self).translate(field, roperator, rvalue, tree,
                                       **kwargs)
        cleaned_data = output['cleaned_data']

        if cleaned_data['operator'].lookup == 'isnull' and cleaned_data[
                'value']:
            # Create a null condition for this field
            null_condition = trees[tree].query_condition(
                field.model._meta.pk, 'isnull', True)
            # Allow the null condition
            output['query_modifiers']['condition'] = null_condition
        return output


registry.register(AllowMissingRecord, 'Allow Missing Record')
Beispiel #4
0
from datetime import date, timedelta
from avocado.query.translators import Translator, registry


class AgeTranslator(Translator):
    def translate(self,
                  field,
                  roperator,
                  rvalue,
                  tree,
                  units='years',
                  **kwargs):
        secs = float(rvalue) * 60 * 60 * 24 * 365.242
        if units == 'months':
            secs = float(rvalue) * 60 * 60 * 24 * 30.4368
        elif units == 'days':
            secs = float(rvalue) * 60 * 60 * 24
        rvalue = date.today() - timedelta(seconds=secs)
        output = super(AgeTranslator, self).translate(field, roperator, rvalue,
                                                      tree, **kwargs)
        return output


registry.register(AgeTranslator, 'Age')
Beispiel #5
0
from avocado.query.translators import Translator, registry
from modeltree.tree import trees


class AllowNullsTranslator(Translator):
    """For data sources that only apply to SNPs, this translator ensures only
    SNPs are filtered down and not other types of variants.
    """
    def translate(self, field, roperator, rvalue, tree, **kwargs):
        output = super(AllowNullsTranslator,
                       self).translate(field, roperator, rvalue, tree,
                                       **kwargs)

        # We are excluding nulls in the case of range, gt, and gte operators.
        # If we did not do this, then null values would be included all the
        # time which would be confusing, especially then they are included
        # for both lt and gt queries as it appears nulls are simultaneously
        # 0 and infinity.
        if roperator not in ('range', 'gt', 'gte'):
            # Create a null condition for this field
            null_condition = trees[tree].query_condition(
                field.field, 'isnull', True)
            # Allow the null condition
            output['query_modifiers']['condition'] |= null_condition

        return output


registry.register(AllowNullsTranslator, 'Allow Nulls')
from datetime import date, timedelta
from avocado.query.translators import Translator, registry

class AgeTranslator(Translator):
    def translate(self, field, roperator,rvalue, tree, units='years', **kwargs):
        secs= float(rvalue)*60*60*24*365.242
        if units == 'months':
            secs = float(rvalue)*60*60*24*30.4368
        elif units == 'days':
            secs = float(rvalue)*60*60*24
        rvalue =date.today() - timedelta(seconds=secs)
        output = super(AgeTranslator,self).translate(field,roperator,rvalue,tree, **kwargs)
        return output

registry.register(AgeTranslator, 'Age')