Skip to content

Commit

Permalink
add CLI to config
Browse files Browse the repository at this point in the history
  • Loading branch information
iskandr committed May 10, 2024
1 parent fba0bb6 commit 476988a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
8 changes: 4 additions & 4 deletions vaxrank/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

__all__ = [
"__version__",
EpitopePrediction,
VaccinePeptide,
run_vaxrank,
predict_epitopes,
"EpitopePrediction",
"VaccinePeptide",
"run_vaxrank",
"predict_epitopes",
]
41 changes: 31 additions & 10 deletions vaxrank/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging.config
import pkg_resources

import msgspec
from argparse import ArgumentParser
from isovar import isovar_results_to_dataframe
from isovar.cli import (make_isovar_arg_parser, run_isovar_from_parsed_args,)
Expand All @@ -28,8 +29,9 @@
import serializable
from varcode.cli import variant_collection_from_args

from . import __version__
from .version import __version__
from .core_logic import run_vaxrank
from .config import MIN_EPITOPE_SCORE_DEFAULT
from .gene_pathway_check import GenePathwayCheck
from .report import (
make_ascii_report,
Expand Down Expand Up @@ -60,6 +62,7 @@ def make_vaxrank_arg_parser():
)
add_mhc_args(arg_parser)
add_vaccine_peptide_args(arg_parser)
add_epitope_prediction_args(arg_parser)
add_output_args(arg_parser)
add_optional_output_args(arg_parser)
add_supplemental_report_args(arg_parser)
Expand Down Expand Up @@ -193,6 +196,21 @@ def add_output_args(arg_parser):
type=int,
help="Number of mutations to report")

def add_epitope_prediction_args(arg_parser):
epitope_prediction_args = arg_parser.add_argument_group("T-cell epitope prediction options")
epitope_prediction_args.add_argument(
"--min-epitope-score",
default=MIN_EPITOPE_SCORE_DEFAULT,
type=float,
help=(
"Ignore predicted MHC ligands whose normalized binding score "
"falls below this threshold. (default: %(default)s)"))

epitope_prediction_args.add_argument(
"--epitope-prediction-config",
default=None,
help="Path to YAML file with options related to epitope prediction, scoring, and filtering.")


def add_vaccine_peptide_args(arg_parser):
vaccine_peptide_group = arg_parser.add_argument_group("Vaccine peptide options")
Expand Down Expand Up @@ -220,14 +238,6 @@ def add_vaccine_peptide_args(arg_parser):
"(default: %(default)s)"
))

vaccine_peptide_group.add_argument(
"--min-epitope-score",
default=1e-10,
type=float,
help=(
"Ignore predicted MHC ligands whose normalized binding score "
"falls below this threshold. (default: %(default)s)"))

vaccine_peptide_group.add_argument(
"--num-epitopes-per-vaccine-peptide",
type=int,
Expand Down Expand Up @@ -280,7 +290,18 @@ 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)


if args.epitope_prediction_config:
with open(args.epitope_prediction_config) as f:
config = msgspec.yaml.decode(f.read(), Config)
else:
config = Config()

if args.min_epitope_score != config.min_epitope_score:
config.min_epitope_score = args.min_epitope_score


return run_vaxrank(
isovar_results=isovar_results,
mhc_predictor=mhc_predictor,
Expand Down
20 changes: 18 additions & 2 deletions vaxrank/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
# 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.


import msgspec

MIN_EPITOPE_SCORE_DEFAULT = 1e-10
BINDING_AFFINITY_CUTOFF = 5000.0

class Config(msgspec.Struct):

"""Parameters for score, filtering, and ranking both epitopes and vaccine peptides"""
logistic_epitope_score_midpoint : float = 350.0
logistic_epitope_score_width : float = 150.0

min_epitope_score : float = 0.0
binding_affinity_cutoff : float = 5000.0
min_epitope_score : float = MIN_EPITOPE_SCORE_DEFAULT
binding_affinity_cutoff : float = BINDING_AFFINITY_CUTOFF

0 comments on commit 476988a

Please sign in to comment.