diff --git a/envipath/settings.py b/envipath/settings.py index 29a7f694..1f37cf73 100644 --- a/envipath/settings.py +++ b/envipath/settings.py @@ -340,6 +340,7 @@ DEFAULT_MODEL_PARAMS = { DEFAULT_MAX_NUMBER_OF_NODES = 50 DEFAULT_MAX_DEPTH = 8 DEFAULT_MODEL_THRESHOLD = 0.25 +BATCH_PREDICT_MAX_COMPOUNDS = 150 # Loading Plugins PLUGINS_ENABLED = os.environ.get("PLUGINS_ENABLED", "False") == "True" diff --git a/epdb/logic.py b/epdb/logic.py index c2a41a59..ab87b1fb 100644 --- a/epdb/logic.py +++ b/epdb/logic.py @@ -44,7 +44,7 @@ class EPDBURLParser: MODEL_PATTERNS = { "epdb.User": re.compile(rf"^.*/user/{UUID_PATTERN}"), "epdb.Group": re.compile(rf"^.*/group/{UUID_PATTERN}"), - "epdb.Package": re.compile(rf"^.*/package/{UUID_PATTERN}"), + s.EPDB_PACKAGE_MODEL: re.compile(rf"^.*/package/{UUID_PATTERN}"), "epdb.Compound": re.compile(rf"^.*/package/{UUID_PATTERN}/compound/{UUID_PATTERN}"), "epdb.CompoundStructure": re.compile( rf"^.*/package/{UUID_PATTERN}/compound/{UUID_PATTERN}/structure/{UUID_PATTERN}" @@ -94,7 +94,7 @@ class EPDBURLParser: def contains_package_url(self): return ( - bool(self.MODEL_PATTERNS["epdb.Package"].findall(self.url)) + bool(self.MODEL_PATTERNS[s.EPDB_PACKAGE_MODEL].findall(self.url)) and not self.is_package_url() ) @@ -122,7 +122,7 @@ class EPDBURLParser: "epdb.EPModel", "epdb.Pathway", # 1st level - "epdb.Package", + s.EPDB_PACKAGE_MODEL, "epdb.Setting", "epdb.Group", "epdb.User", @@ -144,7 +144,7 @@ class EPDBURLParser: hierarchy_order = [ # 1st level - "epdb.Package", + s.EPDB_PACKAGE_MODEL, "epdb.Setting", "epdb.Group", "epdb.User", diff --git a/epdb/models.py b/epdb/models.py index 947acf28..6cb7eff5 100644 --- a/epdb/models.py +++ b/epdb/models.py @@ -3003,7 +3003,14 @@ class PackageBasedModel(EPModel): prec, rec = dict(), dict() - for t in np.arange(0, 1.05, 0.05): + thresholds = list(np.arange(0, 1.05, 0.05)) + + # Add specific threshold set during object creation if not already present + if np.float64(threshold) not in thresholds: + thresholds.append(np.float64(threshold)) + thresholds.sort() + + for t in thresholds: temp_thresholded = (y_pred_filtered >= t).astype(int) prec[f"{t:.2f}"] = precision_score( y_test_filtered, temp_thresholded, zero_division=0 @@ -3013,7 +3020,14 @@ class PackageBasedModel(EPModel): return acc, prec, rec def evaluate_mg(model, pathways: Union[QuerySet["Pathway"] | List["Pathway"]], threshold): - thresholds = np.arange(0.1, 1.1, 0.1) + thresholds = list(np.arange(0, 1.05, 0.05)) + + # Add specific threshold set during object creation if not already present + if np.float64(threshold) not in thresholds: + thresholds.append(np.float64(threshold)) + thresholds.sort() + + logger.info(f"Thresholds: {thresholds}") precision = {f"{t:.2f}": [] for t in thresholds} recall = {f"{t:.2f}": [] for t in thresholds} @@ -3039,7 +3053,7 @@ class PackageBasedModel(EPModel): s = Setting() s.model = mod - s.model_threshold = thresholds.min() + s.model_threshold = 0.0 s.max_depth = 10 s.max_nodes = 50 diff --git a/epdb/views.py b/epdb/views.py index a4db722e..f3ad53cf 100644 --- a/epdb/views.py +++ b/epdb/views.py @@ -523,6 +523,7 @@ def batch_predict_pathway(request): context = get_base_context(request) context["title"] = "enviPath - Batch Predict Pathway" context["meta"]["current_package"] = context["meta"]["user"].default_package + context["batch_predict_max_compounds"] = s.BATCH_PREDICT_MAX_COMPOUNDS return render(request, "batch_predict_pathway.html", context) diff --git a/templates/batch_predict_pathway.html b/templates/batch_predict_pathway.html index ed9f351c..34c18df0 100644 --- a/templates/batch_predict_pathway.html +++ b/templates/batch_predict_pathway.html @@ -37,7 +37,8 @@ class="text-xs text-base-content/50 border-t border-base-300 pt-3" > Format: First column = SMILES, Second column = - Name (headers optional) • Maximum 30 rows + Name (headers optional) • Maximum + {{ batch_predict_max_compoundss|default:150 }} rows @@ -195,8 +196,7 @@ // Function to populate table from CSV data function populateTableFromCSV(csvData) { const lines = csvData.trim().split("\n"); - const maxRows = 30; - + const maxRows = Number("{{ batch_predict_max_compounds|default:150 }}"); // Clear existing table clearTable(); diff --git a/templates/errors/error.html b/templates/errors/error.html index c59bb327..bd37ca97 100644 --- a/templates/errors/error.html +++ b/templates/errors/error.html @@ -51,7 +51,10 @@ Go Home -