diff --git a/volia/__init__.py b/volia/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/volia/data_io.py b/volia/data_io.py new file mode 100644 index 0000000..4c1bdae --- /dev/null +++ b/volia/data_io.py @@ -0,0 +1,44 @@ +''' +Data management input/output +''' + +# Import packages and modules +import numpy as np + +# Defining some types +from typing import List, Dict +KeyToList = Dict[str, List[str]] +KeyToFeatures = Dict[str, List[float]] + + +def read_lst(file_path: str) -> KeyToList: + ''' + Read lst file with this structure: + [id] [value1] [value2] ... [value n] + + This is a basic function reused by others like read_features. + returns a dictionary with id as key and a list of value as corresponding values + ''' + # KeyToList type variable + key_to_list = dict() + with open(file_path, "r") as f: + for line in f: + splited = line.replace("\n", "").split(" ") + id = splited[0] + values = splited[1:] + key_to_list[id] = values + return key_to_list + + +def read_features(file_path: str) -> KeyToFeatures: + ''' + ''' + # KeyToFeatures type variable + key_to_features = dict() + # and the KeyToList + key_to_list = read_lst(file_path) + + for key_, list_ in key_to_list.items(): + key_to_features[key_] = np.asarray(list_, dtype=float) + + return key_to_features \ No newline at end of file