def test_migrate_rd_interpretation_request(self, fill_nullables=True): # get original IR in version 3.0.0 assembly = Assembly.GRCh38 original_ir = self.get_valid_object( object_type=reports_3_0_0.InterpretationRequestRD, version=self.version_3_0_0, fill_nullables=fill_nullables, genomeAssemblyVersion=assembly, versionControl=reports_3_0_0.VersionControl( )) # type: reports_3_0_0.InterpretationRequestRD for p in original_ir.pedigree.participants: p.gelFamilyId = original_ir.pedigree.gelFamilyId p.yearOfBirth for p in original_ir.pedigree.participants: for hpo in p.hpoTermList: hpo.modifiers = self._get_random_hpo_modifiers() migrated, round_tripped = MigrationRunner().roundtrip_rd_ir( original_ir, assembly) self.assertFalse( self.diff_round_tripped(original_ir, round_tripped, ignore_fields=[ "ageOfOnset", "consanguineousPopulation", "additionalInfo", "analysisVersion" ]))
def test_migrate_cancer_clinical_report(self, fill_nullables=True): assembly = Assembly.GRCh38 original_cr = self.get_valid_object( object_type=reports_4_0_0.ClinicalReportCancer, version=self.version_4_0_0, fill_nullables=fill_nullables, genomeAssemblyVersion=assembly, interpretGenome=True, candidateStructuralVariants=[], versionControl=reports_4_0_0.ReportVersionControl(gitVersionControl='4.0.0'), interpretationRequestVersion='123' ) migrated, round_tripped = MigrationRunner().roundtrip_cancer_cr(original_cr, assembly) self.assertFalse(self.diff_round_tripped(original_cr, round_tripped, ignore_fields=[ "analysisId", "actions", "additionalTextualVariantAnnotations", "commonAf", "genePanelsCoverage"])) # NOTE: not all fields in actions are kept and the order is not maintained, thus we ignore it in the # dictionary comparison and then here manually check them if original_cr.candidateVariants: expected_report_events = chain.from_iterable( map(lambda v: [re for re in v.reportedVariantCancer.reportEvents], original_cr.candidateVariants)) else: expected_report_events = [] if round_tripped.candidateVariants: observed_report_events = chain.from_iterable( map(lambda v: [re for re in v.reportedVariantCancer.reportEvents], round_tripped.candidateVariants)) else: observed_report_events = [] self.assertFalse(self.diff_actions(chain(expected_report_events, observed_report_events)))
def test_migrate_rd_exit_questionnaire(self, fill_nullables=True): original = self.get_valid_object( object_type=reports_3_0_0.RareDiseaseExitQuestionnaire, version=self.version_3_0_0, fill_nullables=fill_nullables ) # type: reports_3_0_0.RareDiseaseExitQuestionnaire for g in original.variantGroupLevelQuestions: for v in g.variantLevelQuestions: v.variant_details = self._get_random_variant_details() migrated, round_tripped = MigrationRunner().roundtrip_rd_eq( original, Assembly.GRCh38) self.assertFalse( self.diff_round_tripped(original, round_tripped, ignore_fields=[]))
def test_migrate_rd_clinical_report(self, fill_nullables=True): # get original IR in version 3.0.0 original = self.get_valid_object( object_type=reports_3_0_0.ClinicalReportRD, version=self.version_3_0_0, fill_nullables=fill_nullables, interpretationRequestVersion='1', candidateStructuralVariants=None) migrated, round_tripped = MigrationRunner().roundtrip_rd_cr( original, Assembly.GRCh38) self.assertFalse( self.diff_round_tripped( original, round_tripped, ignore_fields=["interpretationRequestAnalysisVersion"]))
def __init__(self, log_file, program, data_folder=None, use_data=False): # configures logging to get only logs about the failed cases self.log_file = log_file self.program = program self.data_folder = data_folder self.use_data = use_data logging.basicConfig(filename=self.log_file, level=logging.ERROR, format='%(asctime)s.%(msecs)03d\t%(message)s', datefmt='%H:%M:%S' ,) if not use_data: gel_user = raw_input("User:"******"Password:"******"URL:") self.cipapi_client = CipApiClient(cipapi_url, user=gel_user, password=gel_password, retries=-1) self.migration_runner = MigrationRunner()
def test_migrate_rd_interpreted_genome(self, fill_nullables=True): # get original IG in version 3.0.0 # NOTE: we do not want to structural variants and we remove them to avoid noise original_ig = self.get_valid_object( object_type=reports_3_0_0.InterpretedGenomeRD, version=self.version_3_0_0, fill_nullables=fill_nullables, reportedStructuralVariants=None, versionControl=reports_3_0_0.VersionControl(), analysisId='1', reportURI='') migrated, round_tripped = MigrationRunner().roundtrip_rd_ig( original_ig, Assembly.GRCh38) self.assertFalse( self.diff_round_tripped( original_ig, round_tripped, ignore_fields=['additionalNumericVariantAnnotations']))
def test_migrate_cancer_exit_questionnaire(self, fill_nullables=True): assembly = Assembly.GRCh38 original_eq = self.get_valid_object( object_type=reports_5_0_0.CancerExitQuestionnaire, version=self.version_6_1, fill_nullables=fill_nullables, versionControl=reports_5_0_0.ReportVersionControl() ) if original_eq.somaticVariantLevelQuestions: for q in original_eq.somaticVariantLevelQuestions: q.variantDetails = self._get_random_variant_details() if original_eq.germlineVariantLevelQuestions: for q in original_eq.germlineVariantLevelQuestions: q.variantDetails = self._get_random_variant_details() if original_eq.otherActionableVariants: for q in original_eq.otherActionableVariants: q.variantDetails = self._get_random_variant_details() migrated, round_tripped = MigrationRunner().roundtrip_cancer_eq(original_eq, assembly) self.diff_round_tripped(original_eq, round_tripped, ignore_fields=[])
def test_migrate_cancer_interpretation_request(self, fill_nullables=True): # get original IR in version 4.0.0 assembly = Assembly.GRCh38 original_ir = self.get_valid_object( object_type=reports_4_0_0.CancerInterpretationRequest, version=self.version_4_0_0, fill_nullables=fill_nullables, genomeAssemblyVersion=assembly, structuralTieredVariants=[], versionControl=reports_4_0_0.ReportVersionControl( gitVersionControl='4.0.0')) valid_cancer_origins = ['germline_variant', 'somatic_variant'] for tiered_variant in original_ir.tieredVariants: if tiered_variant.alleleOrigins[0] not in valid_cancer_origins: tiered_variant.alleleOrigins[0] = random.choice( valid_cancer_origins) # # migration requires there is exactly one tumour sample original_ir.cancerParticipant.tumourSamples = [ original_ir.cancerParticipant.tumourSamples[0] ] migrated, round_tripped = MigrationRunner().roundtrip_cancer_ir( original_ir, assembly) self.assertFalse( self.diff_round_tripped(original_ir, round_tripped, ignore_fields=[ "TNMStageVersion", "TNMStageGrouping", "actions", "additionalTextualVariantAnnotations", "matchedSamples", "commonAf", "additionalInfo" ])) # NOTE: not all fields in actions are kept and the order is not maintained, thus we ignore it in the # dictionary comparison and then here manually check them expected_report_events = chain.from_iterable( map(lambda v: [re for re in v.reportedVariantCancer.reportEvents], original_ir.tieredVariants)) observed_report_events = chain.from_iterable( map(lambda v: [re for re in v.reportedVariantCancer.reportEvents], round_tripped.tieredVariants)) self.assertFalse( self.diff_actions( chain(expected_report_events, observed_report_events)))
def test_migrate_cancer_interpreted_genome(self, fill_nullables=True): assembly = Assembly.GRCh38 original_ig = self.get_valid_object( object_type=reports_4_0_0.CancerInterpretedGenome, version=self.version_4_0_0, fill_nullables=fill_nullables, genomeAssemblyVersion=assembly, interpretGenome=True, reportedStructuralVariants=[], versionControl=reports_4_0_0.ReportVersionControl(gitVersionControl='4.0.0') ) # migration requires there is exactly one tumour sample migrated, round_tripped = MigrationRunner().roundtrip_cancer_ig(original_ig, assembly) self.assertFalse(self.diff_round_tripped(original_ig, round_tripped, ignore_fields=[ "analysisId", "actions", "additionalTextualVariantAnnotations", "commonAf"])) # NOTE: not all fields in actions are kept and the order is not maintained, thus we ignore it in the # dictionary comparison and then here manually check them expected_report_events = chain.from_iterable( map(lambda v: [re for re in v.reportedVariantCancer.reportEvents], original_ig.reportedVariants)) observed_report_events = chain.from_iterable( map(lambda v: [re for re in v.reportedVariantCancer.reportEvents], round_tripped.reportedVariants)) self.assertFalse(self.diff_actions(chain(expected_report_events, observed_report_events)))
def test_migrate_rd_interpretation_request(self, fill_nullables=True): # get original IR in version 3.0.0 assembly = Assembly.GRCh38 original_ir = self.get_valid_object( object_type=reports_2_1_0.InterpretationRequestRD, version=self.version_2_1_0, fill_nullables=fill_nullables, genomeAssemblyVersion=assembly, versionControl=reports_2_1_0.VersionControl()) for p in original_ir.pedigree.participants: p.gelFamilyId = original_ir.pedigree.gelFamilyId original_ir = Migration21To3().migrate_interpretation_request( original_ir) migrated, round_tripped = MigrationRunner().roundtrip_rd_ir( original_ir, assembly) self.assertFalse( self.diff_round_tripped(original_ir, round_tripped, ignore_fields=[ "ageOfOnset", "consanguineousPopulation", "modifiers", "copyNumber", "additionalInfo" ]))