Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Ripley-L template with comprehensive test coverage and utility functions. The refactoring extracts common template functionality into reusable utilities while maintaining backward compatibility.
- Adds comprehensive unit tests for both template utilities and the Ripley-L template
- Introduces
template_utils.pywith reusable functions for I/O, parameter parsing, and type conversion - Refactors
ripley_l_template.pyto use the new utility functions
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| tests/templates/test_template_utils.py | Comprehensive test suite for template utility functions including I/O operations and parameter conversions |
| tests/templates/test_ripley_l_template.py | Unit tests for Ripley-L template functionality with mock integration |
| src/spac/templates/template_utils.py | New utility module with functions for loading inputs, saving outputs, and parameter processing |
| src/spac/templates/ripley_l_template.py | Refactored Ripley-L template using the new utility functions |
| @@ -0,0 +1,359 @@ | |||
| from pathlib import Path | |||
| import pickle | |||
| from typing import Any, Dict, Union, Optional, List | |||
There was a problem hiding this comment.
Remove the extra space before 'List' in the import statement.
| print(f"Saving AnnData to {str(filepath)}") | ||
| print(obj) | ||
| obj.write_h5ad(str(filepath)) | ||
| print(f"Saved AnnData to {str(filepath)}") |
There was a problem hiding this comment.
Debug print statements should be removed from production code. Consider using proper logging instead.
| print(f"Saving AnnData to {str(filepath)}") | |
| print(obj) | |
| obj.write_h5ad(str(filepath)) | |
| print(f"Saved AnnData to {str(filepath)}") | |
| logger.info(f"Saving AnnData to {str(filepath)}") | |
| logger.debug(f"AnnData object: {obj}") | |
| obj.write_h5ad(str(filepath)) | |
| logger.info(f"Saved AnnData to {str(filepath)}") |
| print(f"Saving AnnData to {str(filepath)}") | ||
| print(obj) | ||
| obj.write_h5ad(str(filepath)) | ||
| print(f"Saved AnnData to {str(filepath)}") |
There was a problem hiding this comment.
Debug print statements should be removed from production code. Consider using proper logging instead.
| print(f"Saving AnnData to {str(filepath)}") | |
| print(obj) | |
| obj.write_h5ad(str(filepath)) | |
| print(f"Saved AnnData to {str(filepath)}") | |
| logger.info(f"Saving AnnData to {str(filepath)}") | |
| logger.debug(f"AnnData object: {obj}") | |
| obj.write_h5ad(str(filepath)) | |
| logger.info(f"Saved AnnData to {str(filepath)}") |
| print(f"Saving AnnData to {str(filepath)}") | ||
| print(obj) | ||
| obj.write_h5ad(str(filepath)) | ||
| print(f"Saved AnnData to {str(filepath)}") |
There was a problem hiding this comment.
Debug print statements should be removed from production code. Consider using proper logging instead.
| print(f"Saving AnnData to {str(filepath)}") | |
| print(obj) | |
| obj.write_h5ad(str(filepath)) | |
| print(f"Saved AnnData to {str(filepath)}") | |
| logging.info(f"Saving AnnData to {str(filepath)}") | |
| logging.debug(f"AnnData object: {obj}") | |
| obj.write_h5ad(str(filepath)) | |
| logging.info(f"Saved AnnData to {str(filepath)}") |
| print(type(filepath)) | ||
| print(type(filename)) | ||
| saved_files[str(filename)] = str(filepath) | ||
| print(f"Saved: {filepath}") |
There was a problem hiding this comment.
Debug print statements should be removed from production code. Consider using proper logging instead.
| print(type(filepath)) | |
| print(type(filename)) | |
| saved_files[str(filename)] = str(filepath) | |
| print(f"Saved: {filepath}") | |
| logger.debug(f"Filepath type: {type(filepath)}") | |
| logger.debug(f"Filename type: {type(filename)}") | |
| saved_files[str(filename)] = str(filepath) | |
| logger.info(f"Saved: {filepath}") |
| if not outfile.endswith(('.pickle', '.pkl', '.h5ad')): | ||
| outfile = outfile.replace('.h5ad', '.pickle') | ||
|
|
||
| print(type(outfile)) |
There was a problem hiding this comment.
Debug print statements should be removed from production code. Consider using proper logging instead.
| print(type(outfile)) | |
| logger.debug(f"Type of outfile: {type(outfile)}") |
| print(type(outfile)) | ||
| saved_files = save_outputs({outfile: adata}) | ||
| print(saved_files) | ||
|
|
||
| print(f"Ripley-L completed → {str(saved_files[outfile])}") | ||
| print(adata) | ||
| return saved_files | ||
| else: | ||
| # Return the adata object directly for in-memory workflows | ||
| print("Returning AnnData object (not saving to file)") | ||
| return adata | ||
|
|
||
|
|
||
| # CLI interface | ||
| if __name__ == "__main__": | ||
| if len(sys.argv) != 2: | ||
| print("Usage: python ripley_l_template.py <params.json>") | ||
| sys.exit(1) | ||
|
|
||
| saved_files = run_from_json(sys.argv[1]) | ||
|
|
||
| if isinstance(saved_files, dict): | ||
| print("\nOutput files:") | ||
| for filename, filepath in saved_files.items(): | ||
| print(f" {filename}: {filepath}") | ||
| else: | ||
| print("\nReturned AnnData object") |
There was a problem hiding this comment.
Debug print statements should be removed from production code. Consider using proper logging instead.
| print(type(outfile)) | |
| saved_files = save_outputs({outfile: adata}) | |
| print(saved_files) | |
| print(f"Ripley-L completed → {str(saved_files[outfile])}") | |
| print(adata) | |
| return saved_files | |
| else: | |
| # Return the adata object directly for in-memory workflows | |
| print("Returning AnnData object (not saving to file)") | |
| return adata | |
| # CLI interface | |
| if __name__ == "__main__": | |
| if len(sys.argv) != 2: | |
| print("Usage: python ripley_l_template.py <params.json>") | |
| sys.exit(1) | |
| saved_files = run_from_json(sys.argv[1]) | |
| if isinstance(saved_files, dict): | |
| print("\nOutput files:") | |
| for filename, filepath in saved_files.items(): | |
| print(f" {filename}: {filepath}") | |
| else: | |
| print("\nReturned AnnData object") | |
| logging.debug(f"Output file type: {type(outfile)}") | |
| saved_files = save_outputs({outfile: adata}) | |
| logging.debug(f"Saved files: {saved_files}") | |
| logging.info(f"Ripley-L completed → {str(saved_files[outfile])}") | |
| logging.debug(f"AnnData object: {adata}") | |
| return saved_files | |
| else: | |
| # Return the adata object directly for in-memory workflows | |
| logging.info("Returning AnnData object (not saving to file)") | |
| return adata | |
| # CLI interface | |
| if __name__ == "__main__": | |
| if len(sys.argv) != 2: | |
| logging.error("Usage: python ripley_l_template.py <params.json>") | |
| sys.exit(1) | |
| saved_files = run_from_json(sys.argv[1]) | |
| if isinstance(saved_files, dict): | |
| logging.info("Output files:") | |
| for filename, filepath in saved_files.items(): | |
| logging.info(f" {filename}: {filepath}") | |
| else: | |
| logging.info("Returned AnnData object") |
| print(type(outfile)) | ||
| saved_files = save_outputs({outfile: adata}) | ||
| print(saved_files) | ||
|
|
||
| print(f"Ripley-L completed → {str(saved_files[outfile])}") | ||
| print(adata) | ||
| return saved_files | ||
| else: | ||
| # Return the adata object directly for in-memory workflows | ||
| print("Returning AnnData object (not saving to file)") | ||
| return adata | ||
|
|
||
|
|
||
| # CLI interface | ||
| if __name__ == "__main__": | ||
| if len(sys.argv) != 2: | ||
| print("Usage: python ripley_l_template.py <params.json>") | ||
| sys.exit(1) | ||
|
|
||
| saved_files = run_from_json(sys.argv[1]) | ||
|
|
||
| if isinstance(saved_files, dict): | ||
| print("\nOutput files:") | ||
| for filename, filepath in saved_files.items(): | ||
| print(f" {filename}: {filepath}") | ||
| else: | ||
| print("\nReturned AnnData object") |
There was a problem hiding this comment.
Debug print statements should be removed from production code. Consider using proper logging instead.
| print(type(outfile)) | |
| saved_files = save_outputs({outfile: adata}) | |
| print(saved_files) | |
| print(f"Ripley-L completed → {str(saved_files[outfile])}") | |
| print(adata) | |
| return saved_files | |
| else: | |
| # Return the adata object directly for in-memory workflows | |
| print("Returning AnnData object (not saving to file)") | |
| return adata | |
| # CLI interface | |
| if __name__ == "__main__": | |
| if len(sys.argv) != 2: | |
| print("Usage: python ripley_l_template.py <params.json>") | |
| sys.exit(1) | |
| saved_files = run_from_json(sys.argv[1]) | |
| if isinstance(saved_files, dict): | |
| print("\nOutput files:") | |
| for filename, filepath in saved_files.items(): | |
| print(f" {filename}: {filepath}") | |
| else: | |
| print("\nReturned AnnData object") | |
| logger.debug(f"Output file type: {type(outfile)}") | |
| saved_files = save_outputs({outfile: adata}) | |
| logger.debug(f"Saved files: {saved_files}") | |
| logger.info(f"Ripley-L completed → {str(saved_files[outfile])}") | |
| logger.debug(f"AnnData object: {adata}") | |
| return saved_files | |
| else: | |
| # Return the adata object directly for in-memory workflows | |
| logger.info("Returning AnnData object (not saving to file)") | |
| return adata | |
| # CLI interface | |
| if __name__ == "__main__": | |
| if len(sys.argv) != 2: | |
| logger.error("Usage: python ripley_l_template.py <params.json>") | |
| sys.exit(1) | |
| saved_files = run_from_json(sys.argv[1]) | |
| if isinstance(saved_files, dict): | |
| logger.info("\nOutput files:") | |
| for filename, filepath in saved_files.items(): | |
| logger.info(f" {filename}: {filepath}") | |
| else: | |
| logger.info("\nReturned AnnData object") |
| @@ -0,0 +1,245 @@ | |||
| # tests/templates/test_ripley_l_template.py | |||
| """Unit‑tests for the Ripley‑L template.""" | |||
There was a problem hiding this comment.
The hyphen character in 'Unit‑tests' appears to be a non-standard character. Use a standard hyphen '-' instead.
| """Unit‑tests for the Ripley‑L template.""" | |
| """Unit-tests for the Ripley-L template.""" |
|
|
||
|
|
||
| class TestRipleyLTemplate(unittest.TestCase): | ||
| """Light‑weight sanity checks for the Ripley‑L template.""" |
There was a problem hiding this comment.
The hyphen characters in 'Light‑weight' and 'Ripley‑L' appear to be non-standard characters. Use standard hyphens '-' instead.
| """Light‑weight sanity checks for the Ripley‑L template.""" | |
| """Light-weight sanity checks for the Ripley-L template.""" |
No description provided.