• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

openvax / mhctools / 8415015115

25 Mar 2024 04:17AM UTC coverage: 96.061% (+9.4%) from 86.616%
8415015115

push

github

iskandr
skip IEDB tests

1585 of 1650 relevant lines covered (96.06%)

2.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.57
/mhctools/cli/script.py
1
# Copyright (c) 2016. Mount Sinai School of Medicine
2
#
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
6
#
7
#     http://www.apache.org/licenses/LICENSE-2.0
8
#
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
14

15
from __future__ import print_function, division, absolute_import
3✔
16
import logging
3✔
17
import logging.config
3✔
18
import pkg_resources
3✔
19
import sys
3✔
20

21
import pandas as pd
3✔
22
from pyensembl.fasta import parse_fasta_dictionary
3✔
23

24
from .args import make_mhc_arg_parser, mhc_binding_predictor_from_args
3✔
25
from mhctools.logging import get_logger
3✔
26

27

28
logger = logging.getLogger(__name__)
3✔
29

30

31
arg_parser = make_mhc_arg_parser(
3✔
32
    prog="mhctools",
3✔
33
    description=("Predict MHC ligands from protein sequences."))
3✔
34

35
def add_input_args(arg_parser):
3✔
36
    input_group = arg_parser.add_argument_group("Inputs")
3✔
37
    input_group.add_argument(
3✔
38
        "--sequence",
3✔
39
        nargs="*",
3✔
40
        help=(
41
            "Peptide sequences"))
3✔
42
    input_group.add_argument(
3✔
43
        "--extract-subsequences",
3✔
44
        default=False,
3✔
45
        action="store_true",
3✔
46
        help=(
47
            "Extract subsequences from peptides supplied by --sequence or "
3✔
48
            "--input-peptides-file, lengths specified by "
49
            "--mhc-peptide-lengths argument."))
50
    input_group.add_argument(
3✔
51
        "--input-peptides-file",
3✔
52
        help="Path to file with one peptide per line")
3✔
53
    input_group.add_argument(
3✔
54
        "--input-fasta-file",
3✔
55
        help="Path to FASTA file which contains protein sequences")
3✔
56
    return input_group
3✔
57

58
def add_output_args(parser):
3✔
59
    output_group = arg_parser.add_argument_group("Outputs")
3✔
60
    output_group.add_argument("--output-csv", default=None)
3✔
61
    return output_group
3✔
62

63
add_input_args(arg_parser)
3✔
64
add_output_args(arg_parser)
3✔
65

66
def parse_args(args_list=None):
3✔
67
    if args_list is None:
3✔
68
        args_list = sys.argv[1:]
×
69
    return arg_parser.parse_args(args_list)
3✔
70

71
def run_predictor(args):
3✔
72
    predictor = mhc_binding_predictor_from_args(args)
3✔
73

74
    if args.input_fasta_file:
3✔
75
        input_dictionary = parse_fasta_dictionary(args.input_fasta_file)
×
76
        if not input_dictionary:
×
77
            raise ValueError(
78
                "No sequences could be parsed from fasta file: %s" % (
79
                    args.input_fasta_file))
80
        # Capitalize sequences
81
        input_dictionary = dict(
82
            (key, value.upper()) for (key, value) in input_dictionary.items())
83
        binding_predictions = predictor.predict_subsequences(input_dictionary)
×
84
    elif args.sequence:
3✔
85
        if args.extract_subsequences:
3✔
86
            binding_predictions = predictor.predict_subsequences(args.sequence)
3✔
87
        else:
×
88
            binding_predictions = predictor.predict_peptides(args.sequence)
3✔
89
    elif args.input_peptides_file:
3✔
90
        with open(args.input_peptides_file) as f:
3✔
91
            peptides = [line.strip() for line in f if line]
3✔
92
        if args.extract_subsequences:
3✔
93
            binding_predictions = predictor.predict_subsequences(peptides)
3✔
94
        else:
×
95
            binding_predictions = predictor.predict_peptides(peptides)
3✔
96
    else:
×
97
        raise ValueError(
98
            ("No input sequences provided, "
99
             "use --sequence, --input-fasta-file, or input-peptides-file"))
100
    return binding_predictions
3✔
101

102
def main(args_list=None):
3✔
103
    """
104
    Script to make pMHC binding predictions from amino acid sequences.
105

106
    Usage example:
107
        mhctools
108
            --sequence SFFPIQQQQQAAALLLI \
109
            --sequence SILQQQAQAQQAQAASSSC \
110
            --extract-subsequences \
111
            --mhc-predictor netmhc \
112
            --mhc-alleles HLA-A0201 H2-Db \
113
            --mhc-predictor netmhc \
114
            --output-csv epitope.csv
115
    """
116
    args = parse_args(args_list)
×
117
    binding_predictions = run_predictor(args)
×
118
    df = binding_predictions.to_dataframe()
×
119
    pd.set_option('display.max_columns', None)
×
120
    logger.info('\n%s', df)
×
121
    if args.output_csv:
×
122
        df.to_csv(args.output_csv, index=False)
×
123
        print("Wrote: %s" % args.output_csv)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc