def _migrate_allele_frequencies(additional_numeric_annotations):
     # NOTE: This is assuming all values in `additionalNumericVariantAnnotations` are frequencies
     frequencies = []
     for pop in additional_numeric_annotations:
         frequencies.append(
             reports_5_0_0.AlleleFrequency(
                 alternateFrequency=additional_numeric_annotations[pop],
                 population=pop.split('_')[-1],
                 study='_'.join(pop.split('_')[:-1])))
     return frequencies
    def _migrate_reported_variant_cancer(self, old_instance, assembly,
                                         participant_id, sample_ids):
        ne_instance = old_instance.reportedVariantCancer
        new_instance = self.convert_class(
            self.new_model.ReportedVariantCancer,
            ne_instance)  # :type: reports_5_0_0.ReportedVariant
        new_instance.variantCoordinates = self.convert_class(
            reports_5_0_0.VariantCoordinates, ne_instance)
        new_instance.variantCoordinates.assembly = self._migrate_assembly(
            assembly)
        if old_instance.reportedVariantCancer.cDnaChange:
            new_instance.cdnaChanges = [
                old_instance.reportedVariantCancer.cDnaChange
            ]
        if ne_instance.proteinChange:
            new_instance.proteinChanges = [ne_instance.proteinChange]

        # NOTE: missing fields: genomicChanges
        sample_id = sample_ids.get(old_instance.alleleOrigins[0], None)
        if not sample_id:
            raise MigrationError('Couldn\'t retrieve Sample ID for {}'.format(
                old_instance.alleleOrigins[0]))

        # builds up the VariantCall object
        # NOTE: fields that cannot be filled "phaseSet"
        new_instance.variantCalls = [
            reports_5_0_0.VariantCall(
                depthReference=ne_instance.depthReference,
                depthAlternate=ne_instance.depthAlternate,
                vaf=ne_instance.vaf,
                zygosity=reports_5_0_0.Zygosity.na,
                alleleOrigins=old_instance.alleleOrigins,
                participantId=participant_id,
                sampleId=sample_id)
        ]
        if ne_instance.commonAf is not None:
            new_instance.alleleFrequencies = [
                reports_5_0_0.AlleleFrequency(
                    study='genomics_england',
                    population='ALL',
                    alternateFrequency=self.convert_string_to_float(
                        ne_instance.commonAf) / 100)
            ]
        # NOTE: some fields cannot be filled: "fdp50", "recurrentlyReported", "others"
        new_instance.variantAttributes = reports_5_0_0.VariantAttributes(
            ihp=ne_instance.ihp)
        new_instance.alleleOrigins = old_instance.alleleOrigins
        new_instance.reportEvents = self.convert_collection(
            list(zip(ne_instance.reportEvents, new_instance.reportEvents)),
            self._migrate_report_event_cancer)
        return new_instance
    def migrate_reported_variant_cancer(self, old_instance, assembly, participant_id, sample_id):
        """
        NOTE: fields that cannot be filled are "genomicChanges", "references"
        :type old_instance: reports_4_0_0.ReportedSomaticVariants
        :type assembly: reports_5_0_0.Assembly
        :type participant_id: str
        :type sample_id: str
        :rtype reports_5_0_0.ReportedVariantCancer
        :return:
        """
        new_instance = self.convert_class(
            self.new_model.ReportedVariantCancer,
            old_instance.reportedVariantCancer)  # :type: reports_5_0_0.ReportedVariant

        # builds up the variant coordinates
        new_instance.variantCoordinates = reports_5_0_0.VariantCoordinates(
            chromosome=old_instance.reportedVariantCancer.chromosome,
            position=old_instance.reportedVariantCancer.position,
            reference=old_instance.reportedVariantCancer.reference,
            alternate=old_instance.reportedVariantCancer.alternate,
            assembly=self.migrate_assembly(assembly)
        )

        # field cDnaChange renamed to cdnaChange
        if old_instance.reportedVariantCancer.cDnaChange:
            new_instance.cdnaChanges = [old_instance.reportedVariantCancer.cDnaChange]

        # field proteinChange changed to a list
        if old_instance.reportedVariantCancer.proteinChange:
            new_instance.proteinChanges = [old_instance.reportedVariantCancer.proteinChange]

        # NOTE: missing fields: genomicChanges

        # builds up the VariantCall object
        # NOTE: fields that cannot be filled "phaseSet"
        new_instance.variantCalls = [reports_5_0_0.VariantCall(
            depthReference=old_instance.reportedVariantCancer.depthReference,
            depthAlternate=old_instance.reportedVariantCancer.depthAlternate,
            vaf=old_instance.reportedVariantCancer.vaf,
            zygosity=reports_5_0_0.Zygosity.na,
            alleleOrigins=old_instance.alleleOrigins,
            participantId=participant_id,
            sampleId=sample_id
        )]

        # builds up an AlleleFrequency object
        if old_instance.reportedVariantCancer.commonAf is not None:
            new_instance.alleleFrequencies = [reports_5_0_0.AlleleFrequency(
                study='genomics_england',
                population='ALL',
                alternateFrequency=self.convert_string_to_float(old_instance.reportedVariantCancer.commonAf)
            )]

        # builds up the VariantAttributes
        # NOTE: some fields cannot be filled: "fdp50", "recurrentlyReported", "others"
        new_instance.variantAttributes = reports_5_0_0.VariantAttributes(
            ihp=old_instance.reportedVariantCancer.ihp
        )

        # list of allele origins is flattened and received as a parameter
        new_instance.alleleOrigins = old_instance.alleleOrigins

        # migrates cancer report events
        new_instance.reportEvents = self.migrate_report_events_cancer(old_instance.reportedVariantCancer.reportEvents)

        return self.validate_object(
            object_to_validate=new_instance, object_type=self.new_model.ReportedVariantCancer
        )