コード例 #1
0
ファイル: sync_steps_experiments.py プロジェクト: katur/eegi
    def sync_score_row(legacy_row):
        # Build the object using the minimimum fields
        count_adult = legacy_row[8]
        count_larva = legacy_row[9]
        if count_adult == -1:
            count_adult = None
        if count_larva == -1:
            count_larva = None

        machine_call = legacy_row[15]
        if machine_call:
            selected_for_scoring = True
        else:
            selected_for_scoring = False

        new_score = DevstarScore(
            experiment=get_experiment(legacy_row[0], legacy_row[1]),
            area_adult=legacy_row[5],
            area_larva=legacy_row[6],
            area_embryo=legacy_row[7],
            count_adult=count_adult,
            count_larva=count_larva,
            is_bacteria_present=legacy_row[16],
            selected_for_scoring=selected_for_scoring,
            gi_score_larva_per_adult=legacy_row[17],
            gi_score_survival=legacy_row[18]
        )

        # Clean the object to populate the fields derived from other fields
        new_score.clean()

        ###############
        # SANITY CHECKS
        ###############

        errors = []

        new_allele = new_score.experiment.worm_strain.allele
        if (new_allele != legacy_row[2]):
            # Deal with case of legacy database using zc310 instead of zu310
            if (legacy_row[2] == 'zc310' and
                    new_allele == 'zu310'):
                pass

            # Deal with some case sensitivity issues in legacy database
            # (e.g. see experiment 32405, where the allele is capitalized).
            # Can't do lower() in all cases because "N2" should always be
            # capitalized.
            elif new_allele == legacy_row[2].lower():
                pass

            else:
                errors.append('allele mismatch')

        # Deal with case of some experiments having the wrong RNAiPlateID
        # in the legacy database's RawDataWithScore table. This field is
        # redundant with the RawData table, and RawData is more trustworthy;
        # however it is still worthwhile to perform this check in order
        # to find the mismatches, and to confirm manually that each one
        # makes sense.
        new_lp = new_score.experiment.library_stock.plate_id
        legacy_lp = legacy_row[4].replace('_', '-').replace('zc310', 'zu310')
        if (legacy_lp != new_lp and
                new_score.experiment.plate_id not in (461, 8345) and
                ('vidal-' not in new_lp or
                    legacy_lp != new_lp.split('vidal-')[1])):
            errors.append('RNAi plate mismatch: {} {}')

        if new_score.count_embryo != legacy_row[10]:
            errors.append('embryo count mismatch')

        if (new_score.embryo_per_adult and legacy_row[8] and
                legacy_row[8] != -1 and
                int(new_score.embryo_per_adult) != legacy_row[11]):
            errors.append('embryo per adult mismatch')

        if (new_score.larva_per_adult and legacy_row[9] and
                legacy_row[9] != -1 and
                int(new_score.larva_per_adult) != legacy_row[12]):
            errors.append('larva per adult mismatch')

        if (new_score.survival and not compare_floats_for_equality(
                new_score.survival, legacy_row[13]) and
                legacy_row[13] != 0):
            errors.append('invalid survival')

        if (new_score.lethality and not compare_floats_for_equality(
                new_score.lethality, legacy_row[14]) and
                legacy_row[13] != 0):
            errors.append('invalid lethality')

        if errors:
            raise CommandError(
                'DevstarScore for {}:{} had these errors: {}'
                .format(legacy_row[0], legacy_row[1], errors))

        return update_or_save_object(
            command, new_score, recorded_scores, fields_to_compare,
            alternate_pk={'experiment': new_score.experiment})
コード例 #2
0
    def sync_score_row(legacy_row):
        # Build the object using the minimimum fields
        count_adult = legacy_row[8]
        count_larva = legacy_row[9]
        if count_adult == -1:
            count_adult = None
        if count_larva == -1:
            count_larva = None

        machine_call = legacy_row[15]
        if machine_call:
            selected_for_scoring = True
        else:
            selected_for_scoring = False

        new_score = DevstarScore(experiment=get_experiment(
            legacy_row[0], legacy_row[1]),
                                 area_adult=legacy_row[5],
                                 area_larva=legacy_row[6],
                                 area_embryo=legacy_row[7],
                                 count_adult=count_adult,
                                 count_larva=count_larva,
                                 is_bacteria_present=legacy_row[16],
                                 selected_for_scoring=selected_for_scoring,
                                 gi_score_larva_per_adult=legacy_row[17],
                                 gi_score_survival=legacy_row[18])

        # Clean the object to populate the fields derived from other fields
        new_score.clean()

        ###############
        # SANITY CHECKS
        ###############

        errors = []

        new_allele = new_score.experiment.worm_strain.allele
        if (new_allele != legacy_row[2]):
            # Deal with case of legacy database using zc310 instead of zu310
            if (legacy_row[2] == 'zc310' and new_allele == 'zu310'):
                pass

            # Deal with some case sensitivity issues in legacy database
            # (e.g. see experiment 32405, where the allele is capitalized).
            # Can't do lower() in all cases because "N2" should always be
            # capitalized.
            elif new_allele == legacy_row[2].lower():
                pass

            else:
                errors.append('allele mismatch')

        # Deal with case of some experiments having the wrong RNAiPlateID
        # in the legacy database's RawDataWithScore table. This field is
        # redundant with the RawData table, and RawData is more trustworthy;
        # however it is still worthwhile to perform this check in order
        # to find the mismatches, and to confirm manually that each one
        # makes sense.
        new_lp = new_score.experiment.library_stock.plate_id
        legacy_lp = legacy_row[4].replace('_', '-').replace('zc310', 'zu310')
        if (legacy_lp != new_lp
                and new_score.experiment.plate_id not in (461, 8345)
                and ('vidal-' not in new_lp
                     or legacy_lp != new_lp.split('vidal-')[1])):
            errors.append('RNAi plate mismatch: {} {}')

        if new_score.count_embryo != legacy_row[10]:
            errors.append('embryo count mismatch')

        if (new_score.embryo_per_adult and legacy_row[8]
                and legacy_row[8] != -1
                and int(new_score.embryo_per_adult) != legacy_row[11]):
            errors.append('embryo per adult mismatch')

        if (new_score.larva_per_adult and legacy_row[9] and legacy_row[9] != -1
                and int(new_score.larva_per_adult) != legacy_row[12]):
            errors.append('larva per adult mismatch')

        if (new_score.survival and not compare_floats_for_equality(
                new_score.survival, legacy_row[13]) and legacy_row[13] != 0):
            errors.append('invalid survival')

        if (new_score.lethality and not compare_floats_for_equality(
                new_score.lethality, legacy_row[14]) and legacy_row[13] != 0):
            errors.append('invalid lethality')

        if errors:
            raise CommandError(
                'DevstarScore for {}:{} had these errors: {}'.format(
                    legacy_row[0], legacy_row[1], errors))

        return update_or_save_object(
            command,
            new_score,
            recorded_scores,
            fields_to_compare,
            alternate_pk={'experiment': new_score.experiment})