Ejemplo n.º 1
0
    def get_n2_control_filters(self):
        """
        Get the N2 + RNAi controls for this experiment.
        It does this by manually setting the strain as N2 and then applying
        all the other parameters which are shared by the controls.

        To get the actual control experiments from the returned filters,
        simply do Experiment.objects.filter(**filters). Returning
        the filters is more flexible for customization, or for inserting
        into a URL without performing the query.

        N2 controls for this experiment are restricted to those from
        the same date, *closest* temperature, same RNAi clone.
        """
        filters = {
            'is_junk': False,
            'plate__date': self.date(),
            'plate__temperature': self.temperature(),
            'library_stock': self.library_stock,
            'worm_strain': WormStrain.get_n2().pk,
        }

        filters['plate__temperature'] = Experiment.get_closest_temperature(
            self.temperature(), filters)

        return filters
Ejemplo n.º 2
0
    def get_n2_l4440_control_filters(self):
        """
        Get the filters for the L4440 controls for this experiment.

        To get the actual control experiments from the returned filters,
        simply do Experiment.objects.filter(**filters). Returning
        the filters is more flexible for customization, or for inserting
        into a URL without performing the query.

        L4440 controls for this experiment are restricted to those from
        the same date, same temperature, same worm.

        If this experiment is itself an L4440 clone, the function works
        the same way, returning all L4440 experiments from the same
        date, same worm, same temperature.
        """
        filters = {
            'is_junk': False,
            'plate__date': self.date(),
            'plate__temperature': self.temperature(),
            'worm_strain': WormStrain.get_n2().pk,
            'library_stock__intended_clone': Clone.get_l4440(),
        }

        return filters
Ejemplo n.º 3
0
def rnai_knockdown(request, clones, temperature=None):
    """
    Render the page showing knockdown by RNAi only.

    context['data'] is returned in format:

        {clone: {
            library_stock: [experiments]
        }}
    """
    data = OrderedDict()

    n2 = WormStrain.get_n2()
    clones = Clone.objects.filter(pk__in=clones.split(','))

    for clone in clones:
        filters = {
            'is_junk': False,
            'worm_strain': n2.pk,
            'library_stock__intended_clone': clone,
        }

        if temperature:
            filters['plate__temperature'] = temperature

        # Do not join manual scores, since N2 not manually scored
        experiments = (Experiment.objects.filter(**filters).select_related(
            'library_stock',
            'plate').prefetch_related('devstarscore_set').order_by(
                '-library_stock__plate__screen_stage', 'library_stock',
                '-plate__date', 'id'))

        data_by_well = OrderedDict()

        for experiment in experiments:
            library_stock = experiment.library_stock
            if library_stock not in data_by_well:
                data_by_well[library_stock] = []
            data_by_well[library_stock].append(experiment)

        if data_by_well:
            data[clone] = data_by_well

    context = {
        'n2': n2,
        'clones': clones,
        'temperature': temperature,
        'data': data,
    }

    return render(request, 'rnai_knockdown.html', context)
Ejemplo n.º 4
0
def rnai_knockdown(request, clones, temperature=None):
    """
    Render the page showing knockdown by RNAi only.

    context['data'] is returned in format:

        {clone: {
            library_stock: [experiments]
        }}
    """
    data = OrderedDict()

    n2 = WormStrain.get_n2()
    clones = Clone.objects.filter(pk__in=clones.split(','))

    for clone in clones:
        filters = {
            'is_junk': False,
            'worm_strain': n2.pk,
            'library_stock__intended_clone': clone,
        }

        if temperature:
            filters['plate__temperature'] = temperature

        # Do not join manual scores, since N2 not manually scored
        experiments = (Experiment.objects.filter(**filters)
                       .select_related('library_stock', 'plate')
                       .prefetch_related('devstarscore_set')
                       .order_by('-library_stock__plate__screen_stage',
                                 'library_stock', '-plate__date', 'id'))

        data_by_well = OrderedDict()

        for experiment in experiments:
            library_stock = experiment.library_stock
            if library_stock not in data_by_well:
                data_by_well[library_stock] = []
            data_by_well[library_stock].append(experiment)

        if data_by_well:
            data[clone] = data_by_well

    context = {
        'n2': n2,
        'clones': clones,
        'temperature': temperature,
        'data': data,
    }

    return render(request, 'rnai_knockdown.html', context)
Ejemplo n.º 5
0
Archivo: models.py Proyecto: katur/eegi
    def get_n2_control_filters(self):
        """
        Get the N2 + RNAi controls for this experiment.

        To get the actual control experiments from the returned filters,
        simply do Experiment.objects.filter(**filters). Returning
        the filters is more flexible for customization, or for inserting
        into a URL without performing the query.

        N2 controls for this experiment are restricted to those from
        the same date, *closest* temperature, same RNAi clone.
        """
        filters = {
            'is_junk': False,
            'plate__date': self.date(),
            'plate__temperature': self.temperature(),
            'library_stock': self.library_stock,
            'worm_strain': WormStrain.get_n2().pk,
        }

        filters['plate__temperature'] = Experiment.get_closest_temperature(
            self.temperature(), filters)

        return filters
Ejemplo n.º 6
0
def double_knockdown(request, mutant, clones, temperature):
    """
    Render the page showing knockdown by both mutation and RNAi.

    context['data'] is returned in format:

        {clone: {
            library_stock: {
                date: {
                    'mutant_rnai': {
                        'experiments': [experiments], 'link_to_all': url
                    },
                    'n2_rnai': {
                        'experiments': [experiments], 'link_to_all': url
                    },
                    'mutant_l4440': {
                        'experiments': [experiments], 'link_to_all': url
                    },
                    'n2_l4440': {
                        'experiments': [experiments], 'link_to_all': url
                    },
                }
            }
        }}

    """

    data = OrderedDict()

    n2 = WormStrain.get_n2()
    l4440 = Clone.get_l4440()
    mutant = get_object_or_404(WormStrain, pk=mutant)
    clones = Clone.objects.filter(pk__in=clones.split(','))

    for clone in clones:
        data_per_clone = OrderedDict()

        library_stocks = (LibraryStock.objects.filter(
            intended_clone=clone).order_by('-plate__screen_stage', 'id'))

        for library_stock in library_stocks:
            data_per_well = OrderedDict()

            dates = Experiment.get_distinct_dates({
                'is_junk':
                False,
                'worm_strain':
                mutant,
                'library_stock':
                library_stock,
                'plate__temperature':
                temperature,
            })

            for date in dates:
                # Add double knockdowns
                filters = {
                    'is_junk': False,
                    'plate__date': date,
                    'worm_strain': mutant.pk,
                    'library_stock': library_stock,
                    'plate__temperature': temperature,
                }
                mutant_rnai = _create_inner_dictionary(filters,
                                                       join_manual=True)

                # Add mutant + L4440 controls
                filters = {
                    'is_junk': False,
                    'plate__date': date,
                    'worm_strain': mutant.pk,
                    'library_stock__intended_clone': l4440,
                    'plate__temperature': temperature,
                }
                mutant_l4440 = _create_inner_dictionary(filters)

                # Add N2 + RNAi controls
                filters = {
                    'is_junk': False,
                    'plate__date': date,
                    'worm_strain': n2.pk,
                    'library_stock': library_stock,
                }

                t = Experiment.get_closest_temperature(temperature, filters)
                filters['plate__temperature'] = t

                n2_rnai = _create_inner_dictionary(filters)

                # Add N2 + L4440 controls
                filters = {
                    'is_junk': False,
                    'plate__date': date,
                    'worm_strain': n2.pk,
                    'library_stock__intended_clone': l4440,
                }

                t = Experiment.get_closest_temperature(temperature, filters)
                filters['plate__temperature'] = t

                n2_l4440 = _create_inner_dictionary(filters)

                data_per_well[date] = {
                    'mutant_rnai': mutant_rnai,
                    'mutant_l4440': mutant_l4440,
                    'n2_rnai': n2_rnai,
                    'n2_l4440': n2_l4440,
                }

            if data_per_well:
                data_per_clone[library_stock] = data_per_well

        data[clone] = data_per_clone

    context = {
        'mutant': mutant,
        'clones': clones,
        'temperature': temperature,
        'data': data,
    }

    return render(request, 'double_knockdown.html', context)
Ejemplo n.º 7
0
def double_knockdown(request, mutant, clones, temperature):
    """
    Render the page showing knockdown by both mutation and RNAi.

    context['data'] is returned in format:

        {clone: {
            library_stock: {
                date: {
                    'mutant_rnai': {
                        'experiments': [experiments], 'link_to_all': url
                    },
                    'n2_rnai': {
                        'experiments': [experiments], 'link_to_all': url
                    },
                    'mutant_l4440': {
                        'experiments': [experiments], 'link_to_all': url
                    },
                    'n2_l4440': {
                        'experiments': [experiments], 'link_to_all': url
                    },
                }
            }
        }}

    """

    data = OrderedDict()

    n2 = WormStrain.get_n2()
    l4440 = Clone.get_l4440()
    mutant = get_object_or_404(WormStrain, pk=mutant)
    clones = Clone.objects.filter(pk__in=clones.split(','))

    for clone in clones:
        data_per_clone = OrderedDict()

        library_stocks = (LibraryStock.objects.filter(intended_clone=clone)
                          .order_by('-plate__screen_stage', 'id'))

        for library_stock in library_stocks:
            data_per_well = OrderedDict()

            dates = Experiment.get_distinct_dates({
                'is_junk': False,
                'worm_strain': mutant,
                'library_stock': library_stock,
                'plate__temperature': temperature,
            })

            for date in dates:
                # Add double knockdowns
                filters = {
                    'is_junk': False,
                    'plate__date': date,
                    'worm_strain': mutant.pk,
                    'library_stock': library_stock,
                    'plate__temperature': temperature,
                }
                mutant_rnai = _create_inner_dictionary(
                    filters, join_manual=True)

                # Add mutant + L4440 controls
                filters = {
                    'is_junk': False,
                    'plate__date': date,
                    'worm_strain': mutant.pk,
                    'library_stock__intended_clone': l4440,
                    'plate__temperature': temperature,
                }
                mutant_l4440 = _create_inner_dictionary(filters)

                # Add N2 + RNAi controls
                filters = {
                    'is_junk': False,
                    'plate__date': date,
                    'worm_strain': n2.pk,
                    'library_stock': library_stock,
                }

                t = Experiment.get_closest_temperature(temperature, filters)
                filters['plate__temperature'] = t

                n2_rnai = _create_inner_dictionary(filters)

                # Add N2 + L4440 controls
                filters = {
                    'is_junk': False,
                    'plate__date': date,
                    'worm_strain': n2.pk,
                    'library_stock__intended_clone': l4440,
                }

                t = Experiment.get_closest_temperature(temperature, filters)
                filters['plate__temperature'] = t

                n2_l4440 = _create_inner_dictionary(filters)

                data_per_well[date] = {
                    'mutant_rnai': mutant_rnai,
                    'mutant_l4440': mutant_l4440,
                    'n2_rnai': n2_rnai,
                    'n2_l4440': n2_l4440,
                }

            if data_per_well:
                data_per_clone[library_stock] = data_per_well

        data[clone] = data_per_clone

    context = {
        'mutant': mutant,
        'clones': clones,
        'temperature': temperature,
        'data': data,
    }

    return render(request, 'double_knockdown.html', context)
Ejemplo n.º 8
0
 def test_get_n2(self):
     n2 = WormStrain.get_n2()
     self.assertEquals(n2.id, 'N2')
     self.assertIsNone(n2.permissive_temperature)
     self.assertIsNone(n2.restrictive_temperature)