<commit_before># Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from __future__ import absolute_import, print_function, division

from operator import attrgetter

import numpy as np
from serializable import Serializable


class VaccinePeptide(Serializable):
    """
    VaccinePeptide combines the sequence information of MutantProteinFragment
    with MHC binding predictions for subsequences of the protein fragment.

    The resulting lists of mutant and wildtype epitope predictions
    are sorted by affinity.
    """

    def __init__(
            self,
            mutant_protein_fragment,
            epitope_predictions,
            num_mutant_epitopes_to_keep=10000,
            sort_predictions_by='ic50'):
        self.mutant_protein_fragment = mutant_protein_fragment
        self.epitope_predictions = epitope_predictions
        self.num_mutant_epitopes_to_keep = num_mutant_epitopes_to_keep
        self.sort_predictions_by = sort_predictions_by

        sort_key = attrgetter(sort_predictions_by)

        # only keep the top k epitopes
        self.mutant_epitope_predictions = sorted([
            p for p in epitope_predictions
            if p.overlaps_mutation and not p.occurs_in_reference
        ], key=sort_key)[:self.num_mutant_epitopes_to_keep]

        self.wildtype_epitope_predictions = sorted([
            p for p in epitope_predictions
            if not p.overlaps_mutation or p.occurs_in_reference
        ], key=sort_key)

        self.wildtype_epitope_score = sum(
            p.logistic_epitope_score()
            for p in self.wildtype_epitope_predictions)
        # only keep the top k epitopes for the purposes of the score
        self.mutant_epitope_score = sum(
            p.logistic_epitope_score()
            for p in self.mutant_epitope_predictions)

    def peptide_synthesis_difficulty_score_tuple(
            self,
            max_c_terminal_hydropathy=1.5,
            min_kmer_hydropathy=0,
            max_kmer_hydropathy_low_priority=1.5,
            max_kmer_hydropathy_high_priority=2.5):
        """
        Generates a tuple of scores used for lexicographic sorting of vaccine
        peptides.

        The most important criterion for choosing a vaccine peptide is to
        minimize the number of cysteines in the sequence (to prevent the
        formation of disulfide bonds).

        It is also important to keep the mean hydropathy of the C-terminal
        residues below 1.5 and also to ensure that no window of amino acids
        within the sequence has a mean hydropathy score > 2.5 (using
        AA values from Table 2 of Kyte & Doolittle 1982).

        If there are multiple vaccine peptides all of whose subsequence
        windows satisfy the GRAVY (mean hydropathy) < 2.5 constraint then
        let's optimize the terminal amino acids to exclude ones known to
        make solid phase synthesis difficult.

        If there are multiple vaccine peptides without difficult terminal<commit_msg>added manufacturability_scores back to vaccine_peptide<commit_after># Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


from __future__ import absolute_import, print_function, division

from operator import attrgetter

import numpy as np
from serializable import Serializable
from manufacturability import ManufacturabilityScores


class VaccinePeptide(Serializable):
    """
    VaccinePeptide combines the sequence information of MutantProteinFragment
    with MHC binding predictions for subsequences of the protein fragment.

    The resulting lists of mutant and wildtype epitope predictions
    are sorted by affinity.
    """

    def __init__(
            self,
            mutant_protein_fragment,
            epitope_predictions,
            num_mutant_epitopes_to_keep=10000,
            sort_predictions_by='ic50'):
        self.mutant_protein_fragment = mutant_protein_fragment
        self.epitope_predictions = epitope_predictions
        self.num_mutant_epitopes_to_keep = num_mutant_epitopes_to_keep
        self.sort_predictions_by = sort_predictions_by

        sort_key = attrgetter(sort_predictions_by)

        # only keep the top k epitopes
        self.mutant_epitope_predictions = sorted([
            p for p in epitope_predictions
            if p.overlaps_mutation and not p.occurs_in_reference
        ], key=sort_key)[:self.num_mutant_epitopes_to_keep]

        self.wildtype_epitope_predictions = sorted([
            p for p in epitope_predictions
            if not p.overlaps_mutation or p.occurs_in_reference
        ], key=sort_key)

        self.wildtype_epitope_score = sum(
            p.logistic_epitope_score()
            for p in self.wildtype_epitope_predictions)
        # only keep the top k epitopes for the purposes of the score
        self.mutant_epitope_score = sum(
            p.logistic_epitope_score()
            for p in self.mutant_epitope_predictions)

        self.manufacturability_scores = \
            ManufacturabilityScores.from_amino_acids(
                self.mutant_protein_fragment.amino_acids)

    def peptide_synthesis_difficulty_score_tuple(
            self,
            max_c_terminal_hydropathy=1.5,
            min_kmer_hydropathy=0,
            max_kmer_hydropathy_low_priority=1.5,
            max_kmer_hydropathy_high_priority=2.5):
        """
        Generates a tuple of scores used for lexicographic sorting of vaccine
        peptides.

        The most important criterion for choosing a vaccine peptide is to
        minimize the number of cysteines in the sequence (to prevent the
        formation of disulfide bonds).

        It is also important to keep the mean hydropathy of the C-terminal
        residues below 1.5 and also to ensure that no window of amino acids
        within the sequence has a mean hydropathy score > 2.5 (using
        AA values from Table 2 of Kyte & Doolittle 1982).

        If there are multiple vaccine peptides all of whose subsequence
        windows satisfy the GRAVY (mean hydropathy) < 2.5 constraint then
        let's optimize the terminal amino acids to exclude ones known to
        make solid phase synthesis difficult.

        If there are multiple vaccine peptides without difficult terminal
{'fraction_non_alphanumeric': 0.042777777777777776, 'fraction_numerical': 0.008055555555555555, 'mean_word_length': 2.871505376344086, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4091593', 'n_tokens_mistral': 2088, 'n_tokens_neox': 1868, 'n_words': 684}