From 22e696ad1b79d4448fed6311d1124f49741fb584 Mon Sep 17 00:00:00 2001 From: Sherry Date: Thu, 30 Mar 2023 21:06:41 -0400 Subject: [PATCH 1/6] fix: user option for pca file not being used --- moseq2_pca/helpers/data.py | 19 ++++++++++--------- moseq2_pca/helpers/wrappers.py | 2 +- tests/integration_tests/test_cli.py | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/moseq2_pca/helpers/data.py b/moseq2_pca/helpers/data.py index e73bdc7..2e4a88e 100644 --- a/moseq2_pca/helpers/data.py +++ b/moseq2_pca/helpers/data.py @@ -22,21 +22,22 @@ def get_pca_paths(config_data, output_dir): pca_file_scores (str): path to pca_scores file """ - # Get path to pre-computed PCA file - pca_file_components = join(output_dir, 'pca.h5') - if 'pca_file_components' not in config_data: - config_data['pca_file_components'] = pca_file_components - elif config_data['pca_file_components'] is not None: - pca_file_components = config_data['pca_file_components'] + # Check if there is PCA file from config_data + if config_data.get('pca_file', None) is not None: + pca_file = config_data['pca_file'] + else: + # Assume PCA file is in output_dir + pca_file = join(output_dir, 'pca.h5') + config_data['pca_file'] = pca_file - if not exists(pca_file_components): - raise IOError(f'Could not find PCA components file {pca_file_components}') + if not exists(pca_file): + raise IOError(f'Could not find PCA components file {pca_file}') # Get path to PCA Scores pca_file_scores = config_data.get('pca_file_scores', join(output_dir, 'pca_scores.h5')) config_data['pca_file_scores'] = pca_file_scores - return config_data, pca_file_components, pca_file_scores + return config_data, pca_file, pca_file_scores def load_pcs_for_cp(pca_file_components, config_data): """ diff --git a/moseq2_pca/helpers/wrappers.py b/moseq2_pca/helpers/wrappers.py index 0d22936..d5979f0 100644 --- a/moseq2_pca/helpers/wrappers.py +++ b/moseq2_pca/helpers/wrappers.py @@ -235,7 +235,7 @@ def apply_pca_wrapper(input_dir, config_data, output_dir, output_file): config_data, pca_file, pca_file_scores = get_pca_paths(config_data, output_dir) print('Loading PCs from', pca_file) - with h5py.File(config_data['pca_file_components'], 'r') as f: + with h5py.File(config_data['pca_file'], 'r') as f: pca_components = f[config_data['pca_path']][()] # Get the yaml for pca, check parameters, if we used fft, be sure to turn on here... diff --git a/tests/integration_tests/test_cli.py b/tests/integration_tests/test_cli.py index 91fb6cb..43f2717 100644 --- a/tests/integration_tests/test_cli.py +++ b/tests/integration_tests/test_cli.py @@ -113,7 +113,7 @@ def test_compute_changepoints(self): with open(config, 'r') as f: config_data = yaml.safe_load(f) - config_data['pca_file_components'] = None + config_data['pca_file'] = None config_data['pca_file_scores'] = None with open(config, 'w') as f: From bcdfef4c6de1a234d25489691c7c38797e4539a6 Mon Sep 17 00:00:00 2001 From: Sherry Date: Thu, 30 Mar 2023 21:09:28 -0400 Subject: [PATCH 2/6] chore: update tests --- tests/integration_tests/test_gui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/integration_tests/test_gui.py b/tests/integration_tests/test_gui.py index 13eaf4d..346d08a 100644 --- a/tests/integration_tests/test_gui.py +++ b/tests/integration_tests/test_gui.py @@ -97,7 +97,7 @@ def test_apply_pca_command(self): with open(config_file, 'r') as f: config_data = yaml.safe_load(f) - config_data['pca_file_components'] = join(outpath, 'pca.h5') + config_data['pca_file'] = join(outpath, 'pca.h5') config_data['use_fft'] = True config_data['missing_data'] = False @@ -132,7 +132,7 @@ def test_compute_changepoints_command(self): with open(config_file, 'r') as f: config_data = yaml.safe_load(f) - config_data['pca_file_components'] = join(outpath, 'pca.h5') + config_data['pca_file'] = join(outpath, 'pca.h5') config_data['use_fft'] = True config_data['missing_data'] = False From 0734d6e0f192433500ef39f35ba72eb9b211857e Mon Sep 17 00:00:00 2001 From: Sherry Date: Thu, 30 Mar 2023 21:10:02 -0400 Subject: [PATCH 3/6] chore: change pca_file_component to pca_file --- moseq2_pca/helpers/data.py | 12 ++++++------ moseq2_pca/helpers/wrappers.py | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/moseq2_pca/helpers/data.py b/moseq2_pca/helpers/data.py index 2e4a88e..976c2ae 100644 --- a/moseq2_pca/helpers/data.py +++ b/moseq2_pca/helpers/data.py @@ -39,27 +39,27 @@ def get_pca_paths(config_data, output_dir): return config_data, pca_file, pca_file_scores -def load_pcs_for_cp(pca_file_components, config_data): +def load_pcs_for_cp(pca_file, config_data): """ Load computed Principal Components for Model-free Changepoint Analysis. Args: - pca_file_components (str): path to pca h5 file to read PCs + pca_file (str): path to pca h5 file to read PCs config_data (dict): config parameters Returns: - pca_components (str): path to pca components + pca_file (str): path to pca components changepoint_params (dict): dict of relevant changepoint parameters missing_data (bool): Indicates whether to use mask_params for missing data pca mask_params (dict): Mask parameters to use when computing CPs """ - print(f'Loading PCs from {pca_file_components}') - with h5py.File(pca_file_components, 'r') as f: + print(f'Loading PCs from {pca_file}') + with h5py.File(pca_file, 'r') as f: pca_components = f[config_data['pca_path']][()] # get the yaml for pca, check parameters, if we used fft, be sure to turn on here... - pca_yaml = splitext(pca_file_components)[0] + '.yaml' + pca_yaml = splitext(pca_files)[0] + '.yaml' if exists(pca_yaml): with open(pca_yaml, 'r') as f: diff --git a/moseq2_pca/helpers/wrappers.py b/moseq2_pca/helpers/wrappers.py index d5979f0..35bd11c 100644 --- a/moseq2_pca/helpers/wrappers.py +++ b/moseq2_pca/helpers/wrappers.py @@ -240,6 +240,7 @@ def apply_pca_wrapper(input_dir, config_data, output_dir, output_file): # Get the yaml for pca, check parameters, if we used fft, be sure to turn on here... pca_yaml = splitext(pca_file)[0] + '.yaml' + print('pca_yaml here',pca_yaml) # Get filtering parameters and optional PCA reconstruction parameters (if missing_data == True) use_fft, clean_params, mask_params, missing_data = get_pca_yaml_data(pca_yaml) @@ -313,10 +314,10 @@ def compute_changepoints_wrapper(input_dir, config_data, output_dir, output_file save_file = join(output_dir, output_file) # Get paths to PCA, PCA Scores file - config_data, pca_file_components, pca_file_scores = get_pca_paths(config_data, output_dir) + config_data, pca_file, pca_file_scores = get_pca_paths(config_data, output_dir) # Load Principal components, set up changepoint parameter dict, and optionally load reconstructed PCs. - pca_components, changepoint_params, missing_data, mask_params = load_pcs_for_cp(pca_file_components, config_data) + pca_components, changepoint_params, missing_data, mask_params = load_pcs_for_cp(pca_file, config_data) # Initialize Dask client client, cluster, workers = \ From 08f453a2868b7edfc232e379b159191830cf52a3 Mon Sep 17 00:00:00 2001 From: Sherry Date: Thu, 30 Mar 2023 21:16:21 -0400 Subject: [PATCH 4/6] fix: typo --- moseq2_pca/helpers/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moseq2_pca/helpers/data.py b/moseq2_pca/helpers/data.py index 976c2ae..6838dfc 100644 --- a/moseq2_pca/helpers/data.py +++ b/moseq2_pca/helpers/data.py @@ -59,7 +59,7 @@ def load_pcs_for_cp(pca_file, config_data): pca_components = f[config_data['pca_path']][()] # get the yaml for pca, check parameters, if we used fft, be sure to turn on here... - pca_yaml = splitext(pca_files)[0] + '.yaml' + pca_yaml = splitext(pca_file)[0] + '.yaml' if exists(pca_yaml): with open(pca_yaml, 'r') as f: From cc12c3e7f7eb816c050e50965207b3ee934a6a53 Mon Sep 17 00:00:00 2001 From: Sherry Date: Sat, 1 Apr 2023 13:48:08 -0400 Subject: [PATCH 5/6] chore: remove dev print --- moseq2_pca/helpers/wrappers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/moseq2_pca/helpers/wrappers.py b/moseq2_pca/helpers/wrappers.py index 35bd11c..14f1f4c 100644 --- a/moseq2_pca/helpers/wrappers.py +++ b/moseq2_pca/helpers/wrappers.py @@ -240,7 +240,6 @@ def apply_pca_wrapper(input_dir, config_data, output_dir, output_file): # Get the yaml for pca, check parameters, if we used fft, be sure to turn on here... pca_yaml = splitext(pca_file)[0] + '.yaml' - print('pca_yaml here',pca_yaml) # Get filtering parameters and optional PCA reconstruction parameters (if missing_data == True) use_fft, clean_params, mask_params, missing_data = get_pca_yaml_data(pca_yaml) From a1f8a71103d9facd60f7ce19e95ced96b85c29d1 Mon Sep 17 00:00:00 2001 From: Sherry Date: Wed, 5 Apr 2023 16:40:10 -0400 Subject: [PATCH 6/6] chore: version bump --- moseq2_pca/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/moseq2_pca/__init__.py b/moseq2_pca/__init__.py index 8f688c6..d7197db 100644 --- a/moseq2_pca/__init__.py +++ b/moseq2_pca/__init__.py @@ -1 +1 @@ -__version__ = 'v1.1.3' +__version__ = 'v1.2.0'