Skip to content

Commit

Permalink
working on YAML config
Browse files Browse the repository at this point in the history
  • Loading branch information
iskandr committed Aug 8, 2024
1 parent b13a543 commit ce1ac5d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 21 deletions.
4 changes: 2 additions & 2 deletions vaxrank/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from .epitope_logic import predict_epitopes
from .vaccine_peptide import VaccinePeptide
from .version import __version__
from .epitope_config import EpitopeConfig
from .vaccine_config import VaccineConfig
from .cli.epitope_config_args import EpitopeConfig
from .cli.vaccine_config_args import VaccineConfig

__all__ = [
"__version__",
Expand Down
11 changes: 11 additions & 0 deletions vaxrank/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 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.
2 changes: 1 addition & 1 deletion vaxrank/cli/entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


from varcode.cli import variant_collection_from_args
from isovar import isovar_results_to_dataframe
from isovar import isovar_results_to_dataframe, run_isovar_from_parsed_args
from mhctools.cli import (
mhc_alleles_from_args,
mhc_binding_predictor_from_args,
Expand Down
4 changes: 3 additions & 1 deletion vaxrank/cli/vaccine_config_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@


def add_vaccine_peptide_args(arg_parser : argparse.ArgumentParser) -> None:
default_vaccine_config = VaccineConfig()

vaccine_peptide_group = arg_parser.add_argument_group("Vaccine peptide options")
vaccine_peptide_group.add_argument(
"--vaccine-peptide-length",
default=25,
default=default_vaccine_config.vaccine_peptide_length,
type=int,
help="Number of amino acids in the vaccine peptides. (default: %(default)s)")

Expand Down
16 changes: 10 additions & 6 deletions vaxrank/core_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,7 @@ def create_vaccine_peptides_dict(
def vaccine_peptides_for_variant(
isovar_result : IsovarResult,
mhc_predictor : BasePredictor,
vaccine_peptide_length : int,
max_vaccine_peptides_per_variant : int,
num_mutant_epitopes_to_keep : int = None,

epitope_config : EpitopeConfig = None,
vaccine_config : VaccineConfig = None):
"""
Expand Down Expand Up @@ -179,12 +177,18 @@ def vaccine_peptides_for_variant(
variant,
long_protein_fragment)

epitope_predictions = predict_epitopes(
epitope_predictions_dict = predict_epitopes(
mhc_predictor=mhc_predictor,
protein_fragment=long_protein_fragment,
epitope_config=epitope_config,
genome=variant.ensembl).values()
genome=variant.ensembl)
epitope_predictions : list[] = epitope_predictions_dict.values()
return vaccine_peptides_from_epitopes(
epitope_predictions,
vaccine_config=vaccine_config)


def vaccine_peptides_from_epitopes():
# TODO: make a function called vaccine_peptides_from_epitopes that
# takes vaccine_config as an option
candidate_vaccine_peptides = []
Expand All @@ -210,7 +214,7 @@ def vaccine_peptides_for_variant(
candidate_vaccine_peptide = VaccinePeptide(
mutant_protein_fragment=candidate_fragment,
epitope_predictions=subsequence_epitope_predictions,
num_mutant_epitopes_to_keep=num_mutant_epitopes_to_keep)
num_mutant_epitopes_to_keep=vaccine_config.num_mutant_epitopes_to_keep)

logger.debug(
"%s, combined score: %0.4f",
Expand Down
23 changes: 13 additions & 10 deletions vaxrank/epitope_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from mhctools.base_predictor import BasePredictor


from .epitope_config import EpitopeConfig
from .cli.epitope_config_args import EpitopeConfig
from .epitope_prediction import EpitopePrediction
from .mutant_protein_fragment import MutantProteinFragment
from .reference_proteome import ReferenceProteome
Expand All @@ -42,11 +42,14 @@ def slice_epitope_predictions(
if p.offset >= start_offset and p.offset + p.length <= end_offset
]

Peptide = str
Allele = str

def predict_epitopes(
mhc_predictor : BasePredictor,
protein_fragment : MutantProteinFragment,
config : EpitopeConfig = None,
genome : Genome = None):
epitope_config : EpitopeConfig = None,
genome : Genome = None) -> dict[tuple[Peptide, Allele], EpitopePrediction]
"""
Parameters
----------
Expand All @@ -56,7 +59,7 @@ def predict_epitopes(
protein_fragment
Protein sub-sequence to run MHC binding predictor over
config
epitope_config
Configuration object with parameters for scoring epitopes, if
missing then default values are used
Expand All @@ -69,8 +72,8 @@ def predict_epitopes(
Uses the input genome to evaluate whether the epitope occurs in reference.
"""
if config is None:
config = EpitopeConfig()
if epitope_config is None:
epitope_config = EpitopeConfig()

results = OrderedDict()
reference_proteome = ReferenceProteome(genome)
Expand Down Expand Up @@ -185,11 +188,11 @@ def predict_epitopes(
offset=peptide_start_offset,
occurs_in_reference=occurs_in_reference)
epitope_score = epitope_prediction.logistic_epitope_score(
midpoint=config.logistic_epitope_score_midpoint,
width=config.logistic_epitope_score_width,
ic50_cutoff=config.binding_affinity_cutoff)
midpoint=epitope_config.logistic_epitope_score_midpoint,
width=epitope_config.logistic_epitope_score_width,
ic50_cutoff=epitope_config.binding_affinity_cutoff)

if epitope_score >= config.min_epitope_score:
if epitope_score >= epitope_config.min_epitope_score:
key = (epitope_prediction.peptide_sequence, epitope_prediction.allele)
results[key] = epitope_prediction
else:
Expand Down
2 changes: 1 addition & 1 deletion vaxrank/vaccine_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ class VaccineConfig(msgspec.Struct):

max_vaccine_peptides_per_variant : int = 1

num_mutant_epitopes_to_keep : int = 1000
num_mutant_epitopes_to_keep : int = 1000

0 comments on commit ce1ac5d

Please sign in to comment.