-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpredict_class.py
More file actions
41 lines (30 loc) · 1.14 KB
/
predict_class.py
File metadata and controls
41 lines (30 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from __future__ import annotations
import argparse
from functools import lru_cache
from typing import Literal
from binary_classifiers.predict_class import PredictClass
@lru_cache(maxsize=2)
def _get_predictor(model_name: Literal["RandomForest", "SVM"]) -> PredictClass:
return PredictClass(model_name=model_name)
def predict_class(
dna_sequence: str, model_name: Literal["RandomForest", "SVM"] = "SVM"
) -> Literal["Virus", "Host"]:
if not isinstance(dna_sequence, str):
raise ValueError("Input must be a string.")
cleaned = dna_sequence.strip().upper()
if not cleaned:
raise ValueError("DNA sequence cannot be empty.")
return _get_predictor(model_name).predict(cleaned)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Predict whether a DNA sequence is Virus or Host."
)
parser.add_argument("sequence", help="DNA sequence to classify")
parser.add_argument(
"--model",
choices=["RandomForest", "SVM"],
default="SVM",
help="Classifier model to use",
)
args = parser.parse_args()
print(predict_class(args.sequence, args.model))