Skip to content

Commit

Permalink
added TODO list and wiring up use of Config across function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
iskandr committed May 9, 2024
1 parent 4af1707 commit 9ea5329
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 45 deletions.
6 changes: 4 additions & 2 deletions vaxrank/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
TemplateDataCreator,
)
from .patient_info import PatientInfo
from .config import Config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -280,13 +281,14 @@ def run_vaxrank_from_parsed_args(args):
df = isovar_results_to_dataframe(isovar_results)
df.to_csv(args.output_isovar_csv, index=False)

config = Config(min_epitope_score=args.min_epitope_score)
return run_vaxrank(
isovar_results=isovar_results,
mhc_predictor=mhc_predictor,
vaccine_peptide_length=args.vaccine_peptide_length,
max_vaccine_peptides_per_variant=args.max_vaccine_peptides_per_mutation,
min_epitope_score=args.min_epitope_score,
num_mutant_epitopes_to_keep=args.num_epitopes_per_vaccine_peptide)
num_mutant_epitopes_to_keep=args.num_epitopes_per_vaccine_peptide,
config=config)

def ranked_vaccine_peptides_with_metadata_from_parsed_args(args):
"""
Expand Down
87 changes: 45 additions & 42 deletions vaxrank/core_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,55 @@

from numpy import isclose

from .mutant_protein_fragment import MutantProteinFragment
from isovar import IsovarResult
from mhctools.base_predictor import BasePredictor

from .config import Config
from .epitope_logic import slice_epitope_predictions, predict_epitopes
from .mutant_protein_fragment import MutantProteinFragment
from .vaccine_peptide import VaccinePeptide
from .vaxrank_results import VaxrankResults

logger = logging.getLogger(__name__)

def run_vaxrank(
isovar_results,
mhc_predictor,
vaccine_peptide_length=25,
max_vaccine_peptides_per_variant=1,
num_mutant_epitopes_to_keep=10000,
min_epitope_score=0.0):
isovar_results : list[IsovarResult],
mhc_predictor : BasePredictor,
vaccine_peptide_length : int = 25,
max_vaccine_peptides_per_variant : int = 1,
num_mutant_epitopes_to_keep : int = 10000,
config : Config = None):
"""
Parameters
----------
isovar_results : list of isovar.IsovarResult
isovar_results
Each IsovarResult corresponds to one somatic variant and its collection
of protein sequences determined from RNA.
mhc_predictor : mhctools.BasePredictor
mhc_predictor
Object with predict_peptides method, used for making pMHC binding
predictions
vaccine_peptide_length : int
vaccine_peptide_length
Length of vaccine SLP to construct
max_vaccine_peptides_per_variant : int
max_vaccine_peptides_per_variant
Number of vaccine peptides to generate for each mutation.
num_mutant_epitopes_to_keep : int, optional
num_mutant_epitopes_to_keep
Number of top-ranking epitopes for each vaccine peptide to include in
computation.
min_epitope_score : float, optional
Ignore peptides with binding predictions whose normalized score is less
than this.
config
Configuration options for epitope scoring, using defaults if not provided
"""
variant_to_vaccine_peptides_dict = create_vaccine_peptides_dict(
isovar_results=isovar_results,
mhc_predictor=mhc_predictor,
vaccine_peptide_length=vaccine_peptide_length,
max_vaccine_peptides_per_variant=max_vaccine_peptides_per_variant,
num_mutant_epitopes_to_keep=num_mutant_epitopes_to_keep,
min_epitope_score=min_epitope_score)
config=config)
ranked_list = ranked_vaccine_peptides(variant_to_vaccine_peptides_dict)

return VaxrankResults(
Expand All @@ -70,35 +73,35 @@ def run_vaxrank(


def create_vaccine_peptides_dict(
isovar_results,
mhc_predictor,
vaccine_peptide_length=25,
max_vaccine_peptides_per_variant=1,
num_mutant_epitopes_to_keep=10 ** 5,
min_epitope_score=0.0):
isovar_results : list[IsovarResult],
mhc_predictor : BasePredictor,
vaccine_peptide_length : int = 25,
max_vaccine_peptides_per_variant : int = 1,
num_mutant_epitopes_to_keep : int = 10 ** 5,
config : Config = None):
"""
Parameters
----------
isovar_results : list of isovar.IsovarResult
isovar_results
List with one object per variant optionally containing protein sequences
mhc_predictor : mhctools.BasePredictor
mhc_predictor
Object with predict_peptides method, used for making pMHC binding
predictions
vaccine_peptide_length : int
vaccine_peptide_length
Length of vaccine SLP to construct
max_vaccine_peptides_per_variant : int
max_vaccine_peptides_per_variant
Number of vaccine peptides to generate for each mutation.
num_mutant_epitopes_to_keep : int, optional
num_mutant_epitopes_to_keep
Number of top-ranking epitopes for each vaccine peptide to include in
computation.
min_epitope_score : float, optional
Ignore peptides with binding predictions whose normalized score is less
than this.
config
Configuration options for epitope scoring, using defaults if not provided
Returns
-------
Expand All @@ -114,33 +117,33 @@ def create_vaccine_peptides_dict(
vaccine_peptide_length=vaccine_peptide_length,
max_vaccine_peptides_per_variant=max_vaccine_peptides_per_variant,
num_mutant_epitopes_to_keep=num_mutant_epitopes_to_keep,
min_epitope_score=min_epitope_score)
config=config)

if any(x.contains_mutant_epitopes() for x in vaccine_peptides):
vaccine_peptides_dict[variant] = vaccine_peptides

return vaccine_peptides_dict

def vaccine_peptides_for_variant(
isovar_result,
mhc_predictor,
vaccine_peptide_length,
max_vaccine_peptides_per_variant,
num_mutant_epitopes_to_keep=None,
min_epitope_score=0.0):
isovar_result : IsovarResult,
mhc_predictor : BasePredictor,
vaccine_peptide_length : int,
max_vaccine_peptides_per_variant : int,
num_mutant_epitopes_to_keep : int = None,
config : Config = None):
"""
Parameters
----------
isovar_result : isovar.IsovarResult
isovar_result
mhc_predictor : mhctools.BasePredictor
mhc_predictor
Object with predict_peptides method, used for making pMHC binding
predictions
vaccine_peptide_length : int
vaccine_peptide_length
Length of vaccine SLP to construct
max_vaccine_peptides_per_variant : int
max_vaccine_peptides_per_variant
Number of vaccine peptides to generate for each mutation.
num_mutant_epitopes_to_keep : int, optional
Expand Down Expand Up @@ -172,7 +175,7 @@ def vaccine_peptides_for_variant(
epitope_predictions = predict_epitopes(
mhc_predictor=mhc_predictor,
protein_fragment=long_protein_fragment,
min_epitope_score=min_epitope_score,
config=config,
genome=variant.ensembl).values()

candidate_vaccine_peptides = []
Expand Down
2 changes: 1 addition & 1 deletion vaxrank/epitope_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


from pyensembl import Genome
from mhctools import BasePredictor
from mhctools.base_predictor import BasePredictor


from .config import Config
Expand Down
24 changes: 24 additions & 0 deletions vaxrank/epitope_prediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,30 @@


class EpitopePrediction(Serializable):
# TODO:
# - rename to CandidateEpitope
# - add groups of predictions:
# * mhc_affinity_ic50
# * mhc_affinity_score
# * mhc_affinity_percentile_rank
# * mhc_stability_hours
# * mhc_stability_score
# * mhc_stability_percentile_rank
# * antigen_processing_score
# * antigen_processing_percentile_rank
# * pmhc_presentation_score
# * pmhc_presentation_percentile_rank
# * immunogenicity_score
# * immunogenicity_percentile_rank
# - also change wt_peptide_sequence to:
# * closest_reference_peptide_sequence_in_any_protein
# * closest_reference_peptide_sequence_in_same_protein
# - and calculate:
# * edit_distance_to_closest_reference_peptide_in_any_protein
# * edit_distance_to_closest_reference_peptide_in_same_protein
# * edit_distance_to_closest_reference_peptide_in_any_protein_PMBEC
# * edit_distance_to_closest_reference_peptide_in_same_protein_PMBEC
# - how to avoid duplicating every prediction for MT vs. WT-any vs. WT-same?
def __init__(
self,
allele,
Expand Down

0 comments on commit 9ea5329

Please sign in to comment.