Skip to content

Commit d803527

Browse files
adjusted the logic of creation of folder to save results
1 parent ca4e510 commit d803527

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

pyleida/_leida.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def fit_predict(self,kmin=2,kmax=20,TR=None,paired_tests=False,n_replicates='aut
218218
raise TypeError("'save_results' must be a boolean value (True or False)!")
219219

220220
#Run the analysis
221-
self._results_path_ = os.path.split(os.path.abspath(self._data_path_))[0]+'/LEiDA_results'
221+
self._results_path_ = os.path.split(os.path.abspath(self._data_path_))[0]+'/LEiDA_results_run_1'
222222

223223
self.eigenvectors,self._clustering_,self._dynamics_ = self._execute_all(
224224
TR=TR,
@@ -296,16 +296,18 @@ def _execute_all(self,TR=None,random_state=None,paired_tests=False,n_perm=5_000,
296296
#creating folder to save results
297297
if save_results:
298298
if os.path.exists(self._results_path_):
299-
raise Warning("EXECUTION ABORTED: The folder 'LEiDA_results' already "
300-
"exists. If you have results from earlier executions of "
301-
"the analysis, consider changing the folder's name or moving "
302-
"the folder to another location.")
303-
else:
304-
try:
305-
print(f"\n-Creating folder to save results: '{self._results_path_}'")
306-
os.makedirs(self._results_path_)
307-
except:
308-
raise Exception("The folder to save the results could't be created.")
299+
#getting info of previous results to define
300+
#the 'run' number.
301+
root_folder = os.path.split(os.path.abspath(self._data_path_))[0]
302+
preexisting_results = [f for f in os.listdir(root_folder) if os.path.isdir(f'{root_folder}/{f}') and f.startswith('LEiDA_results_run')]
303+
execution_number = np.max([int(i.split('_')[-1]) for i in preexisting_results])+1
304+
#redefine results path
305+
self._results_path_ = root_folder+f'/LEiDA_results_run_{execution_number}'
306+
try:
307+
print(f"\n-Creating folder to save results: '{self._results_path_}'")
308+
os.makedirs(self._results_path_)
309+
except:
310+
raise Exception("The folder to save the results could't be created.")
309311

310312
#creating variables to save results
311313
eigens = []

0 commit comments

Comments
 (0)