def _migrate_pedigree_member(self, member, family_id): new_instance = self.convert_class(self.new_model.RDParticipant, member) new_instance.versionControl = participant_old.VersionControl() new_instance.gelId = str(member.participantId) new_instance.gelFamilyId = family_id new_instance.sex = self._migrate_enumerations('Sex', member.sex) new_instance.lifeStatus = self._migrate_enumerations( 'LifeStatus', member.lifeStatus) new_instance.adoptedStatus = self._migrate_enumerations( 'AdoptedStatus', member.adoptedStatus) new_instance.affectionStatus = self._migrate_enumerations( 'AffectionStatus', member.affectionStatus) if new_instance.affectionStatus == 'uncertain': new_instance.affectionStatus = 'unknown' new_instance.hpoTermList = self.convert_collection( member.hpoTermList, self._migrate_hpo_terms, default=[]) if member.yearOfBirth is not None: new_instance.yearOfBirth = str(member.yearOfBirth) new_instance.samples = self.convert_collection(member.samples, lambda s: s.sampleId, default=[]) new_instance.disorderList = self.convert_collection( member.disorderList, self._migrate_disorders, default=[]) if member.ancestries is None: new_instance.ancestries = participant_old.Ancestries() return new_instance
def migrate_interpretation_request(self, interpretation_request): """ :type interpretation_request: reports_2_1_0.InterpretationRequestRD :rtype: reports_3_0_0.InterpretationRequestRD """ new_instance = self.convert_class( self.new_model.InterpretationRequestRD, interpretation_request) new_instance.pedigree = self.migrate_pedigree( interpretation_request.pedigree) new_instance.versionControl = reports_3_0_0.VersionControl() new_instance.TieredVariants = self.convert_collection( list( zip(interpretation_request.TieredVariants, new_instance.TieredVariants)), self._migrate_reported_variant) new_instance.BAMs = self.convert_collection( list(zip(interpretation_request.BAMs, new_instance.BAMs)), self._migrate_file) new_instance.VCFs = self.convert_collection( list(zip(interpretation_request.VCFs, new_instance.VCFs)), self._migrate_file) if interpretation_request.bigWigs is not None: new_instance.bigWigs = self.convert_collection( list(zip(interpretation_request.bigWigs, new_instance.bigWigs)), self._migrate_file) if interpretation_request.pedigreeDiagram: new_instance.pedigreeDiagram = self._migrate_file( (interpretation_request.pedigreeDiagram, new_instance.pedigreeDiagram)) if interpretation_request.annotationFile: new_instance.annotationFile = self._migrate_file( (interpretation_request.annotationFile, new_instance.annotationFile)) return self.validate_object(new_instance, self.new_model.InterpretationRequestRD)
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 migrate_interpreted_genome(self, interpreted_genome): """ :type interpreted_genome: reports_2_1_0.InterpretedGenomeRD :rtype: reports_3_0_0.InterpretedGenomeRD """ new_interpreted_genome = self.new_model.InterpretedGenomeRD.fromJsonDict( interpreted_genome.toJsonDict()) new_interpreted_genome.reportedVariants = [] new_interpreted_genome.ReportedStructuralVariant = [] interpreted_genome.versionControl = reports_3_0_0.VersionControl() for reported_variant in interpreted_genome.reportedVariants: new_interpreted_genome.reportedVariants.append( self.migrate_reported_variant(reported_variant)) if interpreted_genome.reportedStructuralVariants: for reported_structural_variant in interpreted_genome.reportedStructuralVariants: new_interpreted_genome.ReportedStructuralVariant.append( self.migrate_reported_structural_variant( reported_structural_variant)) new_interpreted_genome.softwareVersions = {} new_interpreted_genome.referenceDatabasesVersions = {} if new_interpreted_genome.validate( new_interpreted_genome.toJsonDict()): return new_interpreted_genome else: raise Exception('This model can not be converted')
class PedigreeFactory300Nulls(FactoryAvro): class Meta: model = reports_3_0_0.Pedigree _version = dependency_manager.VERSION_300 versionControl = reports_3_0_0.VersionControl() _fill_nullables = True
def _migrate_rd_participant(self, members): old_instance = members[0] new_instance = members[1] new_instance.versionControl = reports_3_0_0.VersionControl() if old_instance.additionalInformation: if 'yearOfBirth' in old_instance.additionalInformation: new_instance.yearOfBirth = old_instance.additionalInformation[ 'yearOfBirth'] return new_instance
class RDParticipantFactory300Nulls(FactoryAvro): class Meta: model = reports_3_0_0.RDParticipant _version = dependency_manager.VERSION_300 versionControl = reports_3_0_0.VersionControl() yearOfBirth = str( factory.fuzzy.FuzzyInteger(low=1900, high=2018).fuzz()) _fill_nullables = True
def migrate_pedigree_member(self, member, family_id): """ :type member: participant_1_0_1.PedigreeMember :rtype: participant_old.RDParticipant """ new_pedigree_member = self.new_model.RDParticipant.fromJsonDict( member.toJsonDict()) new_pedigree_member.versionControl = participant_old.VersionControl() new_pedigree_member.gelId = str(member.participantId) new_pedigree_member.gelFamilyId = family_id new_pedigree_member.sex = self.migrate_enumerations('Sex', member.sex) new_pedigree_member.lifeStatus = self.migrate_enumerations( 'LifeStatus', member.lifeStatus) new_pedigree_member.adoptedStatus = self.migrate_enumerations( 'AdoptedStatus', member.adoptedStatus) new_pedigree_member.affectionStatus = self.migrate_enumerations( 'AffectionStatus', member.affectionStatus) if new_pedigree_member.affectionStatus == 'uncertain': new_pedigree_member.affectionStatus = 'unknown' if member.hpoTermList: new_pedigree_member.hpoTermList = [ self.migrate_hpo_terms(hpo) for hpo in member.hpoTermList ] else: new_pedigree_member.hpoTermList = [] try: new_pedigree_member.yearOfBirth = str(int(member.yearOfBirth)) except TypeError: new_pedigree_member.yearOfBirth = None if member.samples: new_pedigree_member.samples = [ sample.sampleId for sample in member.samples ] else: new_pedigree_member.samples = [] if member.disorderList: new_pedigree_member.disorderList = [ self.migrate_disorders(d) for d in member.disorderList ] else: new_pedigree_member.disorderList = [] if member.ancestries is None: new_pedigree_member.ancestries = participant_old.Ancestries() if new_pedigree_member.validate(new_pedigree_member.toJsonDict()): return new_pedigree_member else: print new_pedigree_member.validate_parts() raise Exception('This model can not be converted')
def migrate_pedigree(self, pedigree): """ :type pedigree: reports_2_1_0.Pedigree :rtype: reports_3_0_0.Pedigree """ new_instance = self.convert_class(self.new_model.Pedigree, pedigree) new_instance.versionControl = reports_3_0_0.VersionControl() new_instance.participants = self.convert_collection( list(zip(pedigree.participants, new_instance.participants)), self._migrate_rd_participant) return self.validate_object(object_to_validate=new_instance, object_type=self.new_model.Pedigree)
def migrate_rd_participant(self, member): """ :type member: reports_2_1_0.RDParticipant :rtype: reports_3_0_0.RDParticipant """ new_rd_participant = self.new_model.RDParticipant.fromJsonDict( member.toJsonDict()) new_rd_participant.versionControl = reports_3_0_0.VersionControl() if 'yearOfBirth' in member.additionalInformation: new_rd_participant.yearOfBirth = member.additionalInformation[ 'yearOfBirth'] if new_rd_participant.validate(new_rd_participant.toJsonDict()): return new_rd_participant else: raise Exception('This model can not be converted')
def migrate_interpreted_genome(self, interpreted_genome): """ :type interpreted_genome: reports_2_1_0.InterpretedGenomeRD :rtype: reports_3_0_0.InterpretedGenomeRD """ new_instance = self.convert_class(self.new_model.InterpretedGenomeRD, interpreted_genome) new_instance.reportedVariants = self.convert_collection( list( zip(interpreted_genome.reportedVariants, new_instance.reportedVariants)), self._migrate_reported_variant) new_instance.reportedStructuralVariants = [] interpreted_genome.versionControl = reports_3_0_0.VersionControl() new_instance.softwareVersions = {} new_instance.referenceDatabasesVersions = {} return self.validate_object(new_instance, self.new_model.InterpretedGenomeRD)
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 migrate_pedigree(self, pedigree): """ :type pedigree: reports_2_1_0.Pedigree :rtype: reports_3_0_0.Pedigree """ new_pedigree = self.new_model.Pedigree() new_pedigree.analysisPanels = pedigree.analysisPanels new_pedigree.diseasePenetrances = None new_pedigree.versionControl = reports_3_0_0.VersionControl() new_pedigree.gelFamilyId = pedigree.gelFamilyId new_pedigree.participants = [] for member in pedigree.participants: new_pedigree.participants.append( self.migrate_rd_participant(member)) if new_pedigree.validate(new_pedigree.toJsonDict()): return new_pedigree else: raise Exception('This model can not be converted')
def migrate_interpretation_request(self, interpretation_request): """ :type interpretation_request: reports_2_1_0.InterpretationRequestRD :rtype: reports_3_0_0.InterpretationRequestRD """ new_interpretation_request = self.new_model.InterpretationRequestRD.fromJsonDict( interpretation_request.toJsonDict()) new_interpretation_request.TieredVariants = [] new_interpretation_request.pedigree = self.migrate_pedigree( interpretation_request.pedigree) new_interpretation_request.versionControl = reports_3_0_0.VersionControl( ) for tiered_variant in interpretation_request.TieredVariants: new_interpretation_request.TieredVariants.append( self.migrate_reported_variant(tiered_variant)) if new_interpretation_request.validate( new_interpretation_request.toJsonDict()): return new_interpretation_request else: raise Exception('This model can not be converted')