Skip to content

Commit

Permalink
Added save/load methods to DataSet for analysis parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
npalacioescat committed Oct 28, 2024
1 parent e59a836 commit 5ed3a49
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/funki/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class DataSet(anndata.AnnData):

def __init__(self, X=None, **kwargs):
super().__init__(X, **kwargs)
self.uns['funki'] = dict()

def __getitem__(self, index):
'''
Expand Down Expand Up @@ -157,6 +158,29 @@ def deserialize(self, serial):
self.__dict__.update(pickle.loads(serial).__dict__)

return self

def save_params(self, path='funki_params.json'):
'''
Saves the analysis parameters into a JSON file.
:param path: Destination path for the parameters file. Optional,
defaults to ``'funki_params.json'``.
:type path: str
'''

with open(path, 'w') as f:
json.dump(self.uns['funki'], f)

def load_params(self, path):
'''
Loads the analysis parameters from a JSON file.
:param path: Path where the parameters file is stored.
:type path: str
'''

with open(path, 'r') as f:
self.uns['funki'] = json.load(f)


def read(path, *args, **kwargs):
Expand Down

0 comments on commit 5ed3a49

Please sign in to comment.