def test_migrate_reported_variant_with_consequence(self, fill_nullables=True): old_reported_variant = GenericFactoryAvro.get_factory_avro( self.old_model.ReportedVariant, VERSION_61, fill_nullables=fill_nullables).create() old_reported_variant.additionalTextualVariantAnnotations = { 'ConsequenceType': "initiator_codon_variant,incomplete_terminal_codon_variant" } old_reported_variant.reportEvents[0].tier = self.old_model.Tier.TIER1 old_reported_variant.reportEvents[1].tier = self.old_model.Tier.TIER2 new_small_variant = BaseMigration.convert_class( reports_6_0_0.SmallVariant, old_reported_variant) new_small_variant = MigrateReports500To600()._migrate_variant( (old_reported_variant, new_small_variant)) self._validate(new_small_variant) self.assertIsInstance(new_small_variant, self.new_model.SmallVariant) self.assertEqual( len(new_small_variant.reportEvents[0].variantConsequences), 1) self.assertTrue( new_small_variant.reportEvents[0].variantConsequences[0].name == 'initiator_codon_variant') self.assertEqual( len(new_small_variant.reportEvents[1].variantConsequences), 1) self.assertTrue( new_small_variant.reportEvents[1].variantConsequences[0].name == 'incomplete_terminal_codon_variant')
def test_migrate_reported_variant(self, fill_nullables=True): old_reported_variant = GenericFactoryAvro.get_factory_avro( self.old_model.ReportedVariant, VERSION_61, fill_nullables=fill_nullables ).create() new_small_variant = BaseMigration.convert_class(reports_6_0_0.SmallVariant, old_reported_variant) new_small_variant = MigrateReports500To600()._migrate_variant((old_reported_variant, new_small_variant)) self._validate(new_small_variant) self.assertIsInstance(new_small_variant, self.new_model.SmallVariant) for attribute in ["dbSnpId", "cosmicIds", "clinVarIds"]: if getattr(old_reported_variant, attribute) is not None: self.assertEqual( getattr(old_reported_variant, attribute), getattr(new_small_variant.variantAttributes.variantIdentifiers, attribute) ) attributes = [ "genomicChanges", "cdnaChanges", "proteinChanges", "additionalTextualVariantAnnotations", "references", "additionalNumericVariantAnnotations", "comments" ] for attribute in attributes: if getattr(old_reported_variant, attribute) is not None: self.assertEqual( getattr(old_reported_variant, attribute), getattr(new_small_variant.variantAttributes, attribute) ) if old_reported_variant.alleleFrequencies is not None: old_frequencies = old_reported_variant.alleleFrequencies new_frequencies = new_small_variant.variantAttributes.alleleFrequencies for old, new in zip(old_frequencies, new_frequencies): self.assertIsInstance(new, self.new_model.AlleleFrequency) if old_reported_variant.alleleOrigins is not None: old_origins = old_reported_variant.alleleOrigins new_origins = new_small_variant.variantAttributes.alleleOrigins for old, new in zip(old_origins, new_origins): self.assertEqual(new, old) old_calls = old_reported_variant.variantCalls new_calls = new_small_variant.variantCalls for old, new in zip(old_calls, new_calls): self.assertIsInstance(new, self.new_model.VariantCall) self.assertEqual(new, MigrateReports500To600()._migrate_variant_call((old, new))) old_events = old_reported_variant.reportEvents new_events = new_small_variant.reportEvents for old, new in zip(old_events, new_events): self.assertIsInstance(new, self.new_model.ReportEvent) self.assertEqual(new.toJsonDict(), MigrateReports500To600()._migrate_report_event((old, new)).toJsonDict()) self.assertIsInstance(new_small_variant.variantAttributes, self.new_model.VariantAttributes) self.assertEqual( new_small_variant.variantAttributes, MigrateReports500To600()._migrate_variant_attributes(old_variant=old_reported_variant) )
def test_migrate_report_event(self, fill_nullables=True): re_rd_6 = self.get_valid_object(object_type=old_model.ReportEvent, version=self.version_7_0, fill_nullables=fill_nullables) re_rd_6.eventJustification = None re_rd_6.segregationPattern = old_model.SegregationPattern.CompoundHeterozygous re_rd_5 = BaseMigration.convert_class( target_klass=new_model.ReportEvent, instance=re_rd_6) re_rd_5 = MigrateReports600To500()._migrate_report_event( (re_rd_6, re_rd_5)) self.assertIsInstance(re_rd_5, new_model.ReportEvent) self.assertTrue(re_rd_5.validate(re_rd_5.toJsonDict())) self.assertTrue(old_model.SegregationPattern.CompoundHeterozygous in re_rd_5.eventJustification) re_rd_6 = self.get_valid_object(object_type=old_model.ReportEvent, version=self.version_7_0, fill_nullables=fill_nullables) re_rd_6.eventJustification = "I have an event justification" re_rd_6.segregationPattern = old_model.SegregationPattern.CompoundHeterozygous re_rd_5 = BaseMigration.convert_class( target_klass=new_model.ReportEvent, instance=re_rd_6) re_rd_5 = MigrateReports600To500()._migrate_report_event( (re_rd_6, re_rd_5)) self.assertIsInstance(re_rd_5, new_model.ReportEvent) self.assertTrue(re_rd_5.validate(re_rd_5.toJsonDict())) self.assertTrue(re_rd_5.eventJustification is not None) self.assertTrue(old_model.SegregationPattern.CompoundHeterozygous not in re_rd_5.eventJustification) re_rd_6 = self.get_valid_object(object_type=old_model.ReportEvent, version=self.version_7_0, fill_nullables=fill_nullables) re_rd_6.eventJustification = None re_rd_6.segregationPattern = None re_rd_5 = BaseMigration.convert_class( target_klass=new_model.ReportEvent, instance=re_rd_6) re_rd_5 = MigrateReports600To500()._migrate_report_event( (re_rd_6, re_rd_5)) self.assertIsInstance(re_rd_5, new_model.ReportEvent) self.assertTrue(re_rd_5.validate(re_rd_5.toJsonDict())) self.assertTrue(re_rd_5.eventJustification is None)
def _validate(self, instance): return BaseMigration.validate_object(instance, type(instance))
def test_migrate_report_event(self): old_report_event = GenericFactoryAvro.get_factory_avro(self.old_model.ReportEvent, VERSION_61, fill_nullables=True).create() new_report_event = BaseMigration.convert_class(reports_4_0_0.ReportEvent, old_report_event) new_report_event = MigrateReports500To400()._migrate_report_event((old_report_event, new_report_event)) self.assertTrue(isinstance(new_report_event, self.new_model.ReportEvent)) self._validate(new_report_event)