diff --git a/README.md b/README.md index cd23277..5699021 100644 --- a/README.md +++ b/README.md @@ -129,8 +129,8 @@ When a list of PIL images is passed the index of the image will be filled in for ## Command Line Usage ``` bioclip predict [-h] [--format {table,csv}] [--output OUTPUT] - [--rank {kingdom,phylum,class,order,family,genus,species} | --cls CLS | --bins BINS] - [--subset SUBSET] [--k K] [--device DEVICE] image_file [image_file ...] + [--rank {kingdom,phylum,class,order,family,genus,species} | --cls CLS | --bins BINS | --subset SUBSET] + [--k K] [--device DEVICE] image_file [image_file ...] bioclip embed [-h] [--device=DEVICE] [--output=OUTPUT] [IMAGE_FILE...] Commands: @@ -145,13 +145,13 @@ Options: --format=FORMAT format of the output (table or csv) for predict mode [default: csv] --rank {kingdom,phylum,class,order,family,genus,species} rank of the classification, default: species (when) - --cls CLS classes to predict: either a comma separated list or a path to a text file of classes (one per line), when specified the - --rank and --bins arguments are not allowed. - --bins BINS path to CSV file with two columns with the first being classes and second being bin names, when specified the --cls - argument is not allowed. + --cls CLS classes to predict: either a comma separated list or a path to a text file of classes (one per line), + when specified the --rank, --bins, and --subset arguments are not allowed. + --bins BINS path to CSV file with two columns with the first being classes and second being bin names, + when specified the --rank, --cls, and --subset arguments are not allowed. --subset SUBSET CSV used to subset the tree of life embeddings. CSV first column must be named one of kingdom,phylum,class,order,family,genus,species. - When specified the --rank and --bins arguments are not allowed. + When specified the --rank, --bins, and --cls arguments are not allowed. --k K number of top predictions to show, default: 5 --device=DEVICE device to use matrix math (cpu or cuda or mps) [default: cpu] --output=OUTFILE print output to file OUTFILE [default: stdout] diff --git a/src/bioclip/__main__.py b/src/bioclip/__main__.py index 2430ebb..f8b0ead 100644 --- a/src/bioclip/__main__.py +++ b/src/bioclip/__main__.py @@ -103,12 +103,12 @@ def create_parser(): cls_group = predict_parser.add_mutually_exclusive_group(required=False) cls_group.add_argument('--rank', choices=['kingdom', 'phylum', 'class', 'order', 'family', 'genus', 'species'], help='rank of the classification, default: species (when)') - cls_help = "classes to predict: either a comma separated list or a path to a text file of classes (one per line), when specified the --rank and --bins arguments are not allowed." + cls_help = "classes to predict: either a comma separated list or a path to a text file of classes (one per line), when specified the --rank, --bins, and --subset arguments are not allowed." cls_group.add_argument('--cls', help=cls_help) - cls_group.add_argument('--bins', help='path to CSV file with two columns with the first being classes and second being bin names, when specified the --cls argument is not allowed.') + cls_group.add_argument('--bins', help='path to CSV file with two columns with the first being classes and second being bin names, when specified the --rank, --cls, and --subset arguments are not allowed.') subset_labels = ','.join(get_rank_labels()) - SUBSET_HELP = f"path to CSV file used to subset the tree of life embeddings. CSV first column must be named one of {subset_labels}. When specified the --rank and --bins arguments are not allowed." - predict_parser.add_argument('--subset', help=SUBSET_HELP) + SUBSET_HELP = f"path to CSV file used to subset the tree of life embeddings. CSV first column must be named one of {subset_labels}. When specified the --rank, --bins, and --cls arguments are not allowed." + cls_group.add_argument('--subset', help=SUBSET_HELP) predict_parser.add_argument('--k', type=int, help='number of top predictions to show, default: 5') predict_parser.add_argument('--device', **device_arg) @@ -148,8 +148,6 @@ def parse_args(input_args=None): args.rank = Rank[args.rank.upper()] if not args.k: args.k = 5 - elif args.subset: - raise ValueError("The --subset argument cannot be used with --cls or --bins.") return args diff --git a/tests/test_main.py b/tests/test_main.py index b2762d0..854546d 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -76,13 +76,18 @@ def test_parse_args(self): self.assertEqual(args.k, 10) # test error when using --cls with --subset - with self.assertRaises(ValueError): + with self.assertRaises(SystemExit): parse_args(['predict', 'image.jpg', '--cls', 'class1,class2', '--subset', 'somefile.cvs']) # test error when using --bins with --subset - with self.assertRaises(ValueError): + with self.assertRaises(SystemExit): parse_args(['predict', 'image.jpg', '--bins', 'somefile.csv', '--subset', 'somefile.cvs']) + # test error when using --rank with --subset + with self.assertRaises(SystemExit): + parse_args(['predict', 'image.jpg', '--rank', 'class', '--subset', 'somefile.cvs']) + + # example showing filename args = parse_args(['predict', 'image.jpg', '--cls', 'classes.txt', '--k', '10']) self.assertEqual(args.cls, 'classes.txt')