From 163239c75f082757b8c67d95e3f15e5240c183b9 Mon Sep 17 00:00:00 2001 From: christinehc Date: Fri, 10 May 2024 11:31:08 -0700 Subject: [PATCH] [skip ci] docs: add error catching for missing bg files in c/bg mode --- snekmer/scripts/score_with_background.py | 35 +++++++++++++++++------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/snekmer/scripts/score_with_background.py b/snekmer/scripts/score_with_background.py index 4da2ce9..b8c4990 100644 --- a/snekmer/scripts/score_with_background.py +++ b/snekmer/scripts/score_with_background.py @@ -87,16 +87,31 @@ # generate family scores and object scorer = skm.score.KmerScorer(method=config["score"]["method"]) -scorer.fit( - list(basis.kmer_set.kmers), - data, - family, - bg=counts_bg, - label_col=label, - vec_col="sequence_vector", - weight_bg=config["score"]["background_weight"], - **config["score"]["scaler_kwargs"], -) +try: + scorer.fit( + list(basis.kmer_set.kmers), + data, + family, + bg=counts_bg, + label_col=label, + vec_col="sequence_vector", + weight_bg=config["score"]["background_weight"], + **config["score"]["scaler_kwargs"], + ) +except TypeError as e: + raise ValueError( + """ + Snekmer model background weights detected as `None`. + This typically occurs when a score method of + `'combined'` or `'background'` is specified and no + accompanying background files are detected. + + Please make sure any background files are stored in + an `input/background/` directory, or if no background + files are to be used, the `'family'` scoring method + is selected. + """ + ) from e # append scored sequences to dataframe data = data.merge(