Skip to content

Refactor/ripley l template#357

Merged
fangliu117 merged 2 commits intodevfrom
refactor/ripley-l-template
Jul 24, 2025
Merged

Refactor/ripley l template#357
fangliu117 merged 2 commits intodevfrom
refactor/ripley-l-template

Conversation

@fangliu117
Copy link
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings July 24, 2025 18:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py with reusable functions for I/O, parameter parsing, and type conversion
  • Refactors ripley_l_template.py to 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
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra space before 'List' in the import statement.

Copilot uses AI. Check for mistakes.
Comment on lines +112 to +115
print(f"Saving AnnData to {str(filepath)}")
print(obj)
obj.write_h5ad(str(filepath))
print(f"Saved AnnData to {str(filepath)}")
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should be removed from production code. Consider using proper logging instead.

Suggested change
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)}")

Copilot uses AI. Check for mistakes.
Comment on lines +112 to +115
print(f"Saving AnnData to {str(filepath)}")
print(obj)
obj.write_h5ad(str(filepath))
print(f"Saved AnnData to {str(filepath)}")
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should be removed from production code. Consider using proper logging instead.

Suggested change
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)}")

Copilot uses AI. Check for mistakes.
Comment on lines +112 to +115
print(f"Saving AnnData to {str(filepath)}")
print(obj)
obj.write_h5ad(str(filepath))
print(f"Saved AnnData to {str(filepath)}")
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should be removed from production code. Consider using proper logging instead.

Suggested change
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)}")

Copilot uses AI. Check for mistakes.
Comment on lines +129 to +132
print(type(filepath))
print(type(filename))
saved_files[str(filename)] = str(filepath)
print(f"Saved: {filepath}")
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should be removed from production code. Consider using proper logging instead.

Suggested change
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}")

Copilot uses AI. Check for mistakes.
if not outfile.endswith(('.pickle', '.pkl', '.h5ad')):
outfile = outfile.replace('.h5ad', '.pickle')

print(type(outfile))
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should be removed from production code. Consider using proper logging instead.

Suggested change
print(type(outfile))
logger.debug(f"Type of outfile: {type(outfile)}")

Copilot uses AI. Check for mistakes.
Comment on lines +109 to +135
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")
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should be removed from production code. Consider using proper logging instead.

Suggested change
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")

Copilot uses AI. Check for mistakes.
Comment on lines +109 to +135
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")
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug print statements should be removed from production code. Consider using proper logging instead.

Suggested change
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")

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,245 @@
# tests/templates/test_ripley_l_template.py
"""Unit‑tests for the Ripley‑L template."""
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hyphen character in 'Unit‑tests' appears to be a non-standard character. Use a standard hyphen '-' instead.

Suggested change
"""Unittests for the RipleyL template."""
"""Unit-tests for the Ripley-L template."""

Copilot uses AI. Check for mistakes.


class TestRipleyLTemplate(unittest.TestCase):
"""Light‑weight sanity checks for the Ripley‑L template."""
Copy link

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hyphen characters in 'Light‑weight' and 'Ripley‑L' appear to be non-standard characters. Use standard hyphens '-' instead.

Suggested change
"""Lightweight sanity checks for the RipleyL template."""
"""Light-weight sanity checks for the Ripley-L template."""

Copilot uses AI. Check for mistakes.
@fangliu117 fangliu117 requested a review from georgezakinih July 24, 2025 18:14
@fangliu117 fangliu117 merged commit d291385 into dev Jul 24, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants