Thank you for your interest in contributing to Bioinfo Tools! This document provides guidelines for adding new features and maintaining the codebase.
- Clone the repository:
git clone https://github.com/Mxrcon/Bioinfo-python-scripts.git
cd Bioinfo-python-scripts- Install in development mode:
pip install -e .- Run tests to ensure everything works:
python tests/test_scripts.pyBioinfo-python-scripts/
├── bioinfo_tools/ # Main package
│ ├── __init__.py # Package metadata
│ ├── __main__.py # CLI entry point
│ ├── cli.py # Main CLI parser and command routing
│ ├── commands/ # Subcommand modules
│ │ ├── __init__.py
│ │ ├── extract_cds.py
│ │ ├── extract_proteins.py
│ │ ├── extract_genes.py
│ │ └── blast.py
│ └── utils/ # Shared utilities
│ ├── __init__.py
│ └── common.py
├── tests/ # Test suite
├── conda_recipe/ # Conda packaging
├── setup.py # Package setup
├── pyproject.toml # Modern Python packaging
└── pixi.toml # Pixi configuration
Follow these steps to add a new subcommand to the CLI:
Create a new file in bioinfo_tools/commands/ (e.g., my_command.py):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
My Command subcommand for bioinfo-tools.
Brief description of what this command does.
"""
import logging
from bioinfo_tools.utils import setup_logging
def register_subcommand(subparsers):
"""
Register the my-command subcommand.
Args:
subparsers: The subparsers object from argparse
"""
parser = subparsers.add_parser(
'my-command',
help='Short description for help listing',
description='Longer description of what the command does.',
formatter_class=__import__('argparse').RawDescriptionHelpFormatter,
epilog="""
Examples:
bioinfo-tools my-command -i input.txt -o output.txt
bioinfo-tools my-command --input input.txt --output output.txt
"""
)
# Add arguments
parser.add_argument(
'--input', '-i',
required=True,
metavar='FILE',
help='Input file path'
)
parser.add_argument(
'--output', '-o',
required=True,
metavar='FILE',
help='Output file path'
)
# Set the function to run when this command is called
parser.set_defaults(func=run)
def run(args):
"""
Execute the my-command command.
Args:
args: Parsed command line arguments
Returns:
int: Exit code (0 for success, 1 for failure)
"""
setup_logging()
try:
logging.info("My Command started")
logging.info(f"Input: {args.input}")
logging.info(f"Output: {args.output}")
# Your command logic here
logging.info("My Command finished successfully")
return 0
except Exception as e:
logging.error(f"Fatal error: {e}")
return 1Add your command to bioinfo_tools/commands/__init__.py:
from . import my_command
__all__ = [
'extract_cds',
'extract_proteins',
'extract_genes',
'blast',
'my_command' # Add your command here
]Update bioinfo_tools/cli.py to import and register your command:
def create_parser():
# ... existing code ...
# Import and register all subcommands
from bioinfo_tools.commands import (
extract_cds,
extract_proteins,
extract_genes,
blast,
my_command # Add your import here
)
# Register each subcommand
extract_cds.register_subcommand(subparsers)
extract_proteins.register_subcommand(subparsers)
extract_genes.register_subcommand(subparsers)
blast.register_subcommand(subparsers)
my_command.register_subcommand(subparsers) # Add registration here
return parserAdd tests for your new command in tests/test_scripts.py:
def test_my_command():
"""Test my-command."""
print_header("Testing my-command")
tests_passed = 0
tests_total = 0
# Test help command
tests_total += 1
if run_command(
["bioinfo-tools", "my-command", "--help"],
"bioinfo-tools my-command --help"
):
tests_passed += 1
# Add more tests...
print(f"\n{Colors.BOLD}my-command: {tests_passed}/{tests_total} tests passed{Colors.END}")
return tests_passed, tests_total# Test help
bioinfo-tools my-command --help
# Test functionality
bioinfo-tools my-command -i test_input.txt -o test_output.txt
# Run full test suite
python tests/test_scripts.py- Follow PEP 8 style guidelines
- Use descriptive variable and function names
- Add docstrings to all functions and classes
- Use type hints where appropriate
- Keep functions focused and modular
- Add logging statements for important operations
- Handle errors gracefully with try-except blocks
- Return 0 for success, non-zero for failures
The bioinfo_tools.utils module provides common functionality:
from bioinfo_tools.utils import (
setup_logging, # Configure logging
load_gene_list, # Load gene names from file
validate_input_folder, # Validate folder exists and has files
ensure_output_folder # Create output folder if needed
)For consistency across all commands, use these argument patterns:
- Input files/folders:
--input-folder,-ior--input-file,-i - Output files/folders:
--output-folder,-oor--output-file,-o - Gene lists:
--genes-list,-g - Database folder:
--db-folder,-d - E-value:
--evalue,-e - Type parameters:
--db-type,-tor--blast-type,-b
- Create a new branch for your feature
- Make your changes following the coding standards
- Add tests for new functionality
- Ensure all tests pass
- Update documentation (README, help messages, etc.)
- Submit a pull request with a clear description
If you have questions or need help:
- Open an issue on GitHub
- Email: davijosuemarcon@gmail.com