Skip to content

Commit eadfe66

Browse files
Require metrics file in standalone pvacseq update_tiers step so that it can be updated with newly selected tiering parameters
1 parent 3e41430 commit eadfe66

File tree

6 files changed

+832459
-2
lines changed

6 files changed

+832459
-2
lines changed

pvactools/lib/update_tiers.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import tempfile
77
import shutil
88
import argparse
9+
import json
910

1011
from pvactools.lib.prediction_class import PredictionClass
1112
from pvactools.lib.run_utils import is_preferred_transcript, float_range, transcript_prioritization_strategy
@@ -33,6 +34,7 @@ def execute(self):
3334
output_df.to_csv(self.output_file, sep='\t', na_rep='NA', index=False, float_format='%.3f')
3435
shutil.copy(self.output_file.name, self.input_file)
3536
self.output_file.close()
37+
self.update_metrics_file()
3638

3739
@abstractmethod
3840
def get_tier(self, mutation):
@@ -42,6 +44,9 @@ def get_tier(self, mutation):
4244
def sort_table(self, output_lines):
4345
raise Exception("Must implement method in child class")
4446

47+
def update_metrics_file(self):
48+
pass
49+
4550
@classmethod
4651
def parser(cls, tool):
4752
parser = argparse.ArgumentParser(
@@ -53,6 +58,11 @@ def parser(cls, tool):
5358
'input_file',
5459
help="Input aggregated file with tiers to update. This file will be overwritten with the output."
5560
)
61+
if tool in ['pvacseq']:
62+
parser.add_argument(
63+
'metrics_file',
64+
help="metrics.json file corresponding to the input aggregated file. This file will be overwritten to update tiering parameters used by this command."
65+
)
5666
if tool in ['pvacseq', 'pvacsplice']:
5767
parser.add_argument(
5868
'vaf_clonal', type=float_range(0.0, 1.0),
@@ -167,6 +177,7 @@ def __init__(
167177
allele_specific_anchors=False,
168178
anchor_contribution_threshold=0.8,
169179
top_score_metric2='ic50',
180+
metrics_file=None,
170181
):
171182
self.input_file = input_file
172183
self.output_file = tempfile.NamedTemporaryFile()
@@ -180,6 +191,7 @@ def __init__(
180191
self.trna_vaf = trna_vaf
181192
self.transcript_prioritization_strategy = transcript_prioritization_strategy
182193
self.maximum_transcript_support_level = maximum_transcript_support_level
194+
self.metrics_file=metrics_file
183195
if top_score_metric2 == "percentile":
184196
self.top_score_mode = "%ile MT"
185197
else:
@@ -341,6 +353,28 @@ def sort_table(self, output_lines):
341353

342354
return df
343355

356+
def update_metrics_file(self):
357+
if self.metrics_file is not None:
358+
output_metrics_file = tempfile.NamedTemporaryFile()
359+
with open(self.metrics_file, 'r') as input_fh, open(output_metrics_file.name, 'w') as output_fh:
360+
metrics = json.loads(input_fh.read())
361+
metrics['vaf_clonal'] = round(self.vaf_clonal, 3)
362+
metrics['vaf_subclonal'] = round(self.vaf_clonal/2, 3)
363+
metrics['binding_threshold'] = self.binding_threshold
364+
metrics['trna_vaf'] = self.trna_vaf
365+
metrics['trna_cov'] = self.trna_cov
366+
metrics['allele_expr_threshold'] = self.allele_expr_threshold
367+
metrics['transcript_prioritization_strategy'] = sorted(self.transcript_prioritization_strategy)
368+
metrics['maximum_transcript_support_level'] = self.maximum_transcript_support_level
369+
metrics['percentile_threshold'] = self.percentile_threshold
370+
metrics['percentile_threshold_strategy'] = self.percentile_threshold_strategy
371+
metrics['use_allele_specific_binding_thresholds'] = self.use_allele_specific_binding_thresholds
372+
metrics['top_score_metric2'] = 'ic50' if self.top_score_mode == "IC50 MT" else 'percentile'
373+
metrics['allele_specific_anchors'] = self.anchor_calculator.use_allele_specific_anchors
374+
metrics['anchor_contribution_threshold'] = self.anchor_calculator.anchor_contribution_threshold
375+
json.dump(metrics, output_fh, indent=2, separators=(',', ': '))
376+
shutil.copy(output_metrics_file.name, self.metrics_file)
377+
344378
class PvacfuseUpdateTiers(UpdateTiers, metaclass=ABCMeta):
345379
def __init__(
346380
self,

pvactools/tools/pvacseq/update_tiers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def main(args_input = sys.argv[1:]):
2626
allele_specific_anchors=args.allele_specific_anchors,
2727
anchor_contribution_threshold=args.anchor_contribution_threshold,
2828
top_score_metric2=args.top_score_metric2,
29+
metrics_file=args.metrics_file,
2930
).execute()
3031

3132
if __name__ == "__main__":

0 commit comments

Comments
 (0)