def get_annotations( self, mutated_peptide_mhci: PredictedEpitope, mutated_peptide_mhcii: PredictedEpitope) -> List[Annotation]: """ returns IEDB immunogenicity for best predicted MHC I (based on affinity) and MHC II (based on affinity) epitopes """ iedb = None iedb_mhcii = None if mutated_peptide_mhci and mutated_peptide_mhci.peptide: iedb = self.calculate_iedb_immunogenicity( peptide=mutated_peptide_mhci.peptide, mhc_allele=mutated_peptide_mhci.hla, mhc_score=mutated_peptide_mhci.affinity_score, ) if mutated_peptide_mhcii and mutated_peptide_mhcii.peptide: iedb_mhcii = self.calculate_iedb_immunogenicity( peptide=mutated_peptide_mhcii.peptide, mhc_allele=mutated_peptide_mhcii.hla, mhc_score=mutated_peptide_mhcii.affinity_score, ) annotations = [ AnnotationFactory.build_annotation( value=iedb, name="IEDB_Immunogenicity_MHCI", ), AnnotationFactory.build_annotation( name="IEDB_Immunogenicity_MHCII", value=iedb_mhcii ) ] return annotations
def get_annotations(self) -> List[Annotation]: return [ AnnotationFactory.build_annotation(value=self.total_binding_score, name="vaxrank_binding_score"), AnnotationFactory.build_annotation(value=self.ranking_score, name="vaxrank_total_score"), ]
def get_annotations( self, mutated_peptide_mhci: PredictedEpitope, mutated_peptide_mhcii: PredictedEpitope) -> List[Annotation]: """ returns dissimilarity for MHC I (affinity) MHC II (affinity) """ dissimilarity_mhci = None dissimilarity_mhcii = None if mutated_peptide_mhci and mutated_peptide_mhci.peptide: dissimilarity_mhci = self.calculate_dissimilarity( mutated_peptide=mutated_peptide_mhci.peptide, mhc_affinity=mutated_peptide_mhci.affinity_score) if mutated_peptide_mhcii and mutated_peptide_mhcii.peptide: dissimilarity_mhcii = self.calculate_dissimilarity( mutated_peptide=mutated_peptide_mhcii.peptide, mhc_affinity=mutated_peptide_mhcii.affinity_score) annotations = [ AnnotationFactory.build_annotation( value=dissimilarity_mhci, name="Dissimilarity_MHCI", ), AnnotationFactory.build_annotation( value=dissimilarity_mhcii, name="Dissimilarity_MHCII", ) ] return annotations
def get_annotations(self, mutated_peptide_mhci: PredictedEpitope, mutated_peptide_mhcii: PredictedEpitope, amplitude, mutation_in_anchor) -> List[Annotation]: pathogen_similarity_9mer = None pathogen_similarity_mhcii = None recognition_potential = None if mutated_peptide_mhci and mutated_peptide_mhci.peptide: pathogen_similarity_9mer = self.get_pathogen_similarity( peptide=mutated_peptide_mhci.peptide) if pathogen_similarity_9mer is not None: recognition_potential = self.calculate_recognition_potential( amplitude=amplitude, pathogen_similarity=pathogen_similarity_9mer, mutation_in_anchor=mutation_in_anchor, mhc_affinity_mut=mutated_peptide_mhci.affinity_score, ) if mutated_peptide_mhcii and mutated_peptide_mhcii.peptide: pathogen_similarity_mhcii = self.get_pathogen_similarity( peptide=mutated_peptide_mhcii.peptide) annotations = [ AnnotationFactory.build_annotation( name="Pathogensimiliarity_MHCI_9mer", value=pathogen_similarity_9mer, ), AnnotationFactory.build_annotation( name="Recognition_Potential_MHCI_9mer", value=recognition_potential), AnnotationFactory.build_annotation( name="Pathogensimiliarity_MHCII", value=pathogen_similarity_mhcii), ] return annotations
def _get_positions_and_mutation_in_anchor(self, mutation): """ returns if mutation is in anchor position for best affinity epitope over all lengths and best 9mer affinity """ position_9mer = None mutation_in_anchor_9mer = None if self.best_ninemer_epitope_by_affinity.peptide and mutation.wild_type_xmer: position_9mer = EpitopeHelper.position_of_mutation_epitope( wild_type=self.best_ninemer_wt_epitope_by_affinity.peptide, mutation=self.best_ninemer_epitope_by_affinity.peptide, ) mutation_in_anchor_9mer = EpitopeHelper.position_in_anchor_position( position_mhci=position_9mer, peptide_length=len( self.best_ninemer_epitope_by_affinity.peptide), ) annotations = [ AnnotationFactory.build_annotation( value=position_9mer, name="Best_affinity_MHCI_9mer_position_mutation"), AnnotationFactory.build_annotation( value=mutation_in_anchor_9mer, name="Best_affinity_MHCI_9mer_anchor_mutated", ), ] return annotations
def test_booleans(self): self.assertEqual( "1", AnnotationFactory.build_annotation("test", True).value) self.assertEqual( "0", AnnotationFactory.build_annotation("test", False).value)
def get_annotation( self, mutated_peptide_mhci: PredictedEpitope, mutated_peptide_mhcii: PredictedEpitope) -> List[Annotation]: """ wrapper function for HEX (Homology evaluation of Xenopeptides) (Chiaro et al., 2021) """ # TODO: add annotation of b score when re-implemented in python. The annotation is too slow for bigger datasets hex_aln_score_mhci = None hex_aln_score_mhcii = None # hex_b_score = None if mutated_peptide_mhci and mutated_peptide_mhci.peptide: # hex_aln_score, hex_b_score = self.apply_hex(netmhcpan.best_epitope_by_affinity.peptide).split(" ") hex_aln_score_mhci = self.apply_hex(mutated_peptide_mhci.peptide) if mutated_peptide_mhcii and mutated_peptide_mhcii.peptide: hex_aln_score_mhcii = self.apply_hex(mutated_peptide_mhcii.peptide) annotations = [ AnnotationFactory.build_annotation( value=hex_aln_score_mhci, name="Hex_alignment_score_MHCI"), AnnotationFactory.build_annotation( value=hex_aln_score_mhcii, name="Hex_alignment_score_MHCII") # AnnotationFactory.build_annotation( # value=hex_b_score, name="hex_B_score" #) ] return annotations
def test_strings(self): # TODO: I am wondering if we should transform this to NA. Franziska what do you think? self.assertEqual("", AnnotationFactory.build_annotation("test", "").value) self.assertEqual( "blabla", AnnotationFactory.build_annotation("test", "blabla").value)
def get_annotations(self, mutated_peptide_mhci: PredictedEpitope, amplitude: Amplitude) -> List[Annotation]: bdg_cutoff_classical_mhci = 50 bdg_cutoff_alternative_mhci = 5000 amplitude_cutoff_mhci = 10 cdn = None adn = None if mutated_peptide_mhci.peptide: cdn = self.classify_adn_cdn( score_mutation=mutated_peptide_mhci.affinity_score, amplitude=amplitude.amplitude_mhci_affinity, bdg_cutoff_classical=bdg_cutoff_classical_mhci, bdg_cutoff_alternative=bdg_cutoff_alternative_mhci, amplitude_cutoff=amplitude_cutoff_mhci, category="CDN", ) adn = self.classify_adn_cdn( score_mutation=mutated_peptide_mhci.affinity_score, amplitude=amplitude.amplitude_mhci_affinity, bdg_cutoff_classical=bdg_cutoff_classical_mhci, bdg_cutoff_alternative=bdg_cutoff_alternative_mhci, amplitude_cutoff=amplitude_cutoff_mhci, category="ADN", ) annotations = [ AnnotationFactory.build_annotation(name="CDN_MHCI", value=cdn), AnnotationFactory.build_annotation(name="ADN_MHCI", value=adn), ] return annotations
def get_annotations(self) -> List[Annotation]: return [ AnnotationFactory.build_annotation( value=self.amplitude_mhci_affinity_9mer, name="Amplitude_MHCI_affinity_9mer", ), AnnotationFactory.build_annotation( value=self.amplitude_mhci_affinity, name="Amplitude_MHCI_affinity"), ]
def test_float_values_precision_limit(self): self.assertEqual( "0.12346", AnnotationFactory.build_annotation("test", 0.123456789).value) self.assertEqual( "0.12346", AnnotationFactory.build_annotation("test", 0.1234567891234).value) self.assertEqual( "0.12345", AnnotationFactory.build_annotation("test", 0.12345).value) self.assertEqual( "0.123", AnnotationFactory.build_annotation("test", 0.123).value)
def get_annotations(self, mhc: List[Mhc2], mutation: Mutation, uniprot) -> List[Annotation]: best_peptide, best_rank, best_allele = self.run(mhc=mhc, mutation=mutation, uniprot=uniprot) return [ AnnotationFactory.build_annotation( value=best_peptide, name="MixMHC2pred_best_peptide"), AnnotationFactory.build_annotation(value=best_rank, name="MixMHC2pred_best_rank"), AnnotationFactory.build_annotation(value=best_allele, name="MixMHC2pred_best_allele"), ]
def get_annotations(self, sequence_not_in_uniprot: bool) -> List[Annotation]: return [ AnnotationFactory.build_annotation( name="mutation_not_found_in_proteome", value=sequence_not_in_uniprot) ]
def get_annnotations( self, mutated_peptide_mhci: PredictedEpitope, wt_peptide_mhci: PredictedEpitope, mutated_peptide_mhcii: PredictedEpitope, wt_peptide_mhcii: PredictedEpitope) -> List[Annotation]: improved_binding_mhci = None self_similarity_mhci = None self_similarity_mhcii = None if mutated_peptide_mhci and wt_peptide_mhci and \ mutated_peptide_mhci.peptide and wt_peptide_mhci.peptide: improved_binding_mhci = self.is_improved_binder( score_mutation=mutated_peptide_mhci.rank, score_wild_type=wt_peptide_mhci.rank, ) self_similarity_mhci = self.get_self_similarity( mutated_peptide=mutated_peptide_mhci.peptide, wt_peptide=wt_peptide_mhci.peptide, ) if mutated_peptide_mhcii and wt_peptide_mhcii and \ mutated_peptide_mhcii.peptide and wt_peptide_mhcii.peptide: self_similarity_mhcii = self.get_self_similarity( mutated_peptide=mutated_peptide_mhcii.peptide, wt_peptide=wt_peptide_mhcii.peptide, ) annotations = [ AnnotationFactory.build_annotation(value=improved_binding_mhci, name="Improved_Binder_MHCI"), AnnotationFactory.build_annotation(value=self_similarity_mhcii, name="Selfsimilarity_MHCII"), AnnotationFactory.build_annotation(value=self_similarity_mhci, name="Selfsimilarity_MHCI"), AnnotationFactory.build_annotation( value=self.self_similarity_of_conserved_binder_only( is_improved_binder=improved_binding_mhci, similarity=self_similarity_mhci, ), name="Selfsimilarity_MHCI_conserved_binder", ), ] return annotations
def get_annotations( self, netmhcpan: BestAndMultipleBinder, mut_not_in_prot, expr, vaf_tum, vaf_transcr, ) -> List[Annotation]: """ returns number of mismatches between best MHCI / MHC II epitopes (rank) and their corresponding WTs """ num_mismatches_mhc1 = None priority_score = None if netmhcpan.best_wt_epitope_by_rank.peptide and netmhcpan.best_epitope_by_rank.peptide: num_mismatches_mhc1 = EpitopeHelper.number_of_mismatches( epitope_wild_type=netmhcpan.best_wt_epitope_by_rank.peptide, epitope_mutation=netmhcpan.best_epitope_by_rank.peptide, ) priority_score = self.calc_priority_score( vaf_tumor=vaf_tum, vaf_rna=vaf_transcr, transcript_expr=expr, no_mismatch=num_mismatches_mhc1, score_mut=netmhcpan.best_epitope_by_rank.rank, score_wt=netmhcpan.best_wt_epitope_by_rank.rank, mut_not_in_prot=mut_not_in_prot, ) annotations = [ AnnotationFactory.build_annotation( value=num_mismatches_mhc1, name="Number_of_mismatches_MCHI" ), # priority score with rank score AnnotationFactory.build_annotation( value=priority_score, name="Priority_score", ), ] return annotations
def get_annotations_dai( self, mutated_peptide_mhci: PredictedEpitope, wt_peptide_mhcii: PredictedEpitope) -> List[Annotation]: dai = None if mutated_peptide_mhci.peptide and wt_peptide_mhcii.peptide: dai = self.dai( score_mutation=mutated_peptide_mhci.affinity_score, score_wild_type=wt_peptide_mhcii.affinity_score, affin_filtering=True, ) annotations = [ AnnotationFactory.build_annotation(name="DAI_MHCI_affinity", value=dai), ] return annotations
def get_annotations_mhc2(self, mutated_peptide_mhcii: PredictedEpitope, amplitude: Amplitude) -> List[Annotation]: bdg_cutoff_classical_mhcii = 1 bdg_cutoff_alternative_mhcii = 4 amplitude_cutoff_mhcii = 4 cdn = None adn = None if mutated_peptide_mhcii.peptide: cdn = self.classify_adn_cdn( score_mutation=mutated_peptide_mhcii.rank, amplitude=amplitude.amplitude_mhcii_rank, bdg_cutoff_classical=bdg_cutoff_classical_mhcii, bdg_cutoff_alternative=bdg_cutoff_alternative_mhcii, amplitude_cutoff=amplitude_cutoff_mhcii, category="CDN", ) adn = self.classify_adn_cdn( score_mutation=mutated_peptide_mhcii.rank, amplitude=amplitude.amplitude_mhcii_rank, bdg_cutoff_classical=bdg_cutoff_classical_mhcii, bdg_cutoff_alternative=bdg_cutoff_alternative_mhcii, amplitude_cutoff=amplitude_cutoff_mhcii, category="ADN", ) annotations = [ AnnotationFactory.build_annotation( value=cdn, name="CDN_MHCII", ), AnnotationFactory.build_annotation( value=adn, name="ADN_MHCII", ), ] return annotations
def get_annotations(self, neoantigen: Neoantigen, netmhcpan: BestAndMultipleBinder) -> List[Annotation]: # TODO: this is difficult to extend to more complex mutations (eg: MNVs, indels) as only considers first mutated # position tcell_predictor_score = None if neoantigen.mutation.wild_type_xmer and netmhcpan.best_ninemer_epitope_by_affinity.peptide: mutation_position = neoantigen.mutation.position[0] wild_type_aminoacid = neoantigen.mutation.wild_type_xmer[ mutation_position - 1] # it is 1-based mutated_aminoacid = neoantigen.mutation.mutated_xmer[ mutation_position - 1] tcell_predictor_score = self._calculate_tcell_predictor_score( gene=neoantigen.gene, substitution=wild_type_aminoacid + mutated_aminoacid, epitope=netmhcpan.best_ninemer_epitope_by_affinity.peptide, score=netmhcpan.best_ninemer_epitope_by_affinity.affinity_score ) annotations = [ AnnotationFactory.build_annotation( value=tcell_predictor_score, name="Tcell_predictor_score", ) ] return annotations
def get_annotation( self, sample_id, mutated_peptide_mhci: PredictedEpitope, wt_peptide_mhci: PredictedEpitope, peptide_variant_position, mutation ) -> Annotation: """wrapper function to determine neoag immunogenicity score for a mutated peptide sequence""" neoag_score = None if mutation.wild_type_xmer and mutated_peptide_mhci.peptide and wt_peptide_mhci.peptide: # TODO: move this tmp file creation inside the method tmp_file_name = intermediate_files.create_temp_file( prefix="tmp_neoag_", suffix=".txt" ) self._prepare_tmp_for_neoag( sample_id, mutated_peptide_mhci.peptide, mutated_peptide_mhci.affinity_score, wt_peptide_mhci.peptide, peptide_variant_position, tmp_file_name, ) neoag_score = self._apply_gbm(tmp_file_name) annotation = AnnotationFactory.build_annotation( value=neoag_score, name="Neoag_immunogenicity" ) return annotation
def get_annotations(self) -> List[Annotation]: return [ AnnotationFactory.build_annotation( name="Expression_mutated_transcript", value=self.expression), ]
def test_integers(self): self.assertEqual("123", AnnotationFactory.build_annotation("test", 123).value) self.assertEqual( "-123", AnnotationFactory.build_annotation("test", -123).value)
def test_none(self): self.assertEqual( NOT_AVAILABLE_VALUE, AnnotationFactory.build_annotation("test", None).value)
def get_annotations(self) -> List[Annotation]: annotations = [] if self.best_predicted_epitope_rank: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_predicted_epitope_rank.rank, name="Best_rank_MHCII_score", ), AnnotationFactory.build_annotation( value=self.best_predicted_epitope_rank.peptide, name="Best_rank_MHCII_score_epitope", ), AnnotationFactory.build_annotation( value=self.best_predicted_epitope_rank.hla.name, name="Best_rank_MHCII_score_allele", ) ]) if self.best_predicted_epitope_affinity: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_predicted_epitope_affinity.affinity_score, name="Best_affinity_MHCII_score", ), AnnotationFactory.build_annotation( value=self.best_predicted_epitope_affinity.peptide, name="Best_affinity_MHCII_epitope", ), AnnotationFactory.build_annotation( value=self.best_predicted_epitope_affinity.hla.name, name="Best_affinity_MHCII_allele", ) ]) if self.best_predicted_epitope_rank_wt: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_predicted_epitope_rank_wt.rank, name="Best_rank_MHCII_score_WT", ), AnnotationFactory.build_annotation( value=self.best_predicted_epitope_rank_wt.peptide, name="Best_rank_MHCII_score_epitope_WT", ), AnnotationFactory.build_annotation( value=self.best_predicted_epitope_rank_wt.hla.name, name="Best_rank_MHCII_score_allele_WT", ) ]) if self.best_predicted_epitope_affinity_wt: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_predicted_epitope_affinity_wt. affinity_score, name="Best_affinity_MHCII_score_WT", ), AnnotationFactory.build_annotation( value=self.best_predicted_epitope_affinity_wt.peptide, name="Best_affinity_MHCII_epitope_WT", ), AnnotationFactory.build_annotation( value=self.best_predicted_epitope_affinity_wt.hla.name, name="Best_affinity_MHCII_allele_WT", ) ]) if self.organism == ORGANISM_HOMO_SAPIENS: annotations.extend([ AnnotationFactory.build_annotation(value=self.phbr_ii, name="PHBR_II") ]) annotations.extend([ # generator rate AnnotationFactory.build_annotation(value=self.generator_rate, name="Generator_rate_MHCII"), AnnotationFactory.build_annotation( value=self.generator_rate_cdn, name="Generator_rate_CDN_MHCII"), AnnotationFactory.build_annotation( value=self.generator_rate_adn, name="Generator_rate_ADN_MHCII"), ]) return annotations
def get_annotations(self, mutation) -> List[Annotation]: annotations = [] if self.best_epitope_by_rank: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_epitope_by_rank.rank, name="Best_rank_MHCI_score"), AnnotationFactory.build_annotation( value=self.best_epitope_by_rank.peptide, name="Best_rank_MHCI_score_epitope", ), AnnotationFactory.build_annotation( value=self.best_epitope_by_rank.hla.name, name="Best_rank_MHCI_score_allele") ]) if self.best_epitope_by_affinity: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_epitope_by_affinity.affinity_score, name="Best_affinity_MHCI_score", ), AnnotationFactory.build_annotation( value=self.best_epitope_by_affinity.peptide, name="Best_affinity_MHCI_epitope", ), AnnotationFactory.build_annotation( value=self.best_epitope_by_affinity.hla.name, name="Best_affinity_MHCI_allele", ) ]) if self.best_ninemer_epitope_by_rank: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_ninemer_epitope_by_rank.rank, name="Best_rank_MHCI_9mer_score", ), AnnotationFactory.build_annotation( value=self.best_ninemer_epitope_by_rank.peptide, name="Best_rank_MHCI_9mer_epitope", ), AnnotationFactory.build_annotation( value=self.best_ninemer_epitope_by_rank.hla.name, name="Best_rank_MHCI_9mer_allele", ) ]) if self.best_ninemer_epitope_by_affinity: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_ninemer_epitope_by_affinity.affinity_score, name="Best_affinity_MHCI_9mer_score", ), AnnotationFactory.build_annotation( value=self.best_ninemer_epitope_by_affinity.hla.name, name="Best_affinity_MHCI_9mer_allele", ), AnnotationFactory.build_annotation( value=self.best_ninemer_epitope_by_affinity.peptide, name="Best_affinity_MHCI_9mer_epitope", ) ]) # wt if self.best_wt_epitope_by_affinity: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_wt_epitope_by_affinity.affinity_score, name="Best_affinity_MHCI_score_WT", ), AnnotationFactory.build_annotation( value=self.best_wt_epitope_by_affinity.peptide, name="Best_affinity_MHCI_epitope_WT", ), AnnotationFactory.build_annotation( value=self.best_wt_epitope_by_affinity.hla.name, name="Best_affinity_MHCI_allele_WT", ) ]) if self.best_wt_epitope_by_rank: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_wt_epitope_by_rank.rank, name="Best_rank_MHCI_score_WT"), AnnotationFactory.build_annotation( value=self.best_wt_epitope_by_rank.peptide, name="Best_rank_MHCI_score_epitope_WT", ), AnnotationFactory.build_annotation( value=self.best_wt_epitope_by_rank.hla.name, name="Best_rank_MHCI_score_allele_WT", ) ]) if self.best_ninemer_wt_epitope_by_rank: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_ninemer_wt_epitope_by_rank.rank, name="Best_rank_MHCI_9mer_score_WT", ), AnnotationFactory.build_annotation( value=self.best_ninemer_wt_epitope_by_rank.peptide, name="Best_rank_MHCI_9mer_epitope_WT", ), AnnotationFactory.build_annotation( value=self.best_ninemer_wt_epitope_by_rank.hla.name, name="Best_rank_MHCI_9mer_allele_WT", ) ]) if self.best_ninemer_wt_epitope_by_affinity: annotations.extend([ AnnotationFactory.build_annotation( value=self.best_ninemer_wt_epitope_by_affinity. affinity_score, name="Best_affinity_MHCI_9mer_score_WT", ), AnnotationFactory.build_annotation( value=self.best_ninemer_wt_epitope_by_affinity.hla.name, name="Best_affinity_MHCI_9mer_allele_WT", ), AnnotationFactory.build_annotation( value=self.best_ninemer_wt_epitope_by_affinity.peptide, name="Best_affinity_MHCI_9mer_epitope_WT", ) ]) if self.organism == ORGANISM_HOMO_SAPIENS: annotations.extend([ AnnotationFactory.build_annotation(value=self.phbr_i, name="PHBR_I") ]) annotations.extend([ # generator rate AnnotationFactory.build_annotation(value=self.generator_rate, name="Generator_rate_MHCI"), AnnotationFactory.build_annotation(value=self.generator_rate_cdn, name="Generator_rate_CDN_MHCI"), AnnotationFactory.build_annotation(value=self.generator_rate_adn, name="Generator_rate_ADN_MHCI") ]) annotations.extend( self._get_positions_and_mutation_in_anchor(mutation)) return annotations
def get_annotations_mhc2(self) -> List[Annotation]: return [ AnnotationFactory.build_annotation(value=self.amplitude_mhcii_rank, name="Amplitude_MHCII_rank") ]