From f6e776c1580874639755bd346aa47ab541d5c397 Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Mon, 30 Oct 2023 20:48:35 +0100
Subject: [PATCH] move valideInitTableNamePattern into initTable sources

---
 jass/models/inittable.py | 3 ++-
 jass/models/phenotype.py | 9 +++------
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/jass/models/inittable.py b/jass/models/inittable.py
index dc7fc85e..a7cd1b5e 100644
--- a/jass/models/inittable.py
+++ b/jass/models/inittable.py
@@ -5,6 +5,7 @@ Created on Tue Mar 28 09:57:33 2017
 @author: vguillem, hjulienne, hmenager
 """
 import os
+import re
 import glob
 import logging
 from pandas import HDFStore, DataFrame, read_csv, concat, options, read_hdf
@@ -18,7 +19,7 @@ from functools import reduce
 options.mode.chained_assignment = None
 warnings.filterwarnings("ignore", category=tables.NaturalNameWarning)
 
-from pydantic import BaseModel
+valideInitTableNamePattern = re.compile("^([A-Z]*[a-z]*-*\.?[0-9]*)+$")
 
 class InitMeta(object):
     def __init__(self, nb_snps, nb_phenotypes):
diff --git a/jass/models/phenotype.py b/jass/models/phenotype.py
index b19bb5d7..d5074302 100644
--- a/jass/models/phenotype.py
+++ b/jass/models/phenotype.py
@@ -3,10 +3,10 @@ from typing import List, Optional
 
 import os
 import pandas
-import re
 from pydantic import BaseModel, validator
 
 from jass.config import config
+from jass.models.inittable import valideInitTableNamePattern
 
 
 class Phenotype(BaseModel):
@@ -76,16 +76,13 @@ def get_available_phenotypes(init_file_path: str):
     return phenotypes
 
 
-_initTableNamePattern = re.compile("^([A-Z]*[a-z]*-*\.?[0-9]*)+$")
-
-
 class InitTableNameModel(BaseModel):
     initTableName: Optional[str] = "initTable.hdf5"
 
     @validator("initTableName")
     def validate_path_injection(cls, value):
-        if not _initTableNamePattern.match(value):
-            raise ValueError(f"Prohibited char, only \"{_initTableNamePattern.pattern}\" allowed.")
+        if not valideInitTableNamePattern.match(value):
+            raise ValueError(f"Prohibited char, only \"{valideInitTableNamePattern.pattern}\" allowed.")
         return value
 
     def get_init_table_path(self):
-- 
GitLab