Skip to content

PlasmoGenEpi/pmotools-python

Repository files navigation

pmotools

A collection of tools to interact with portable microhaplotype object (pmo) file format

Setup

Install using pip

pip install .

Usage

This package is built to either be used as a library in python projects and a command line interface already created which can be called from the commandline pmotools-python which will install with pip install ..

Auto completion

If you want to add auto-completion to the scripts master function pmotools-python you can add the following to your ~/.bash_completion. This can also be found in etc/bash_completion in the current directory. Or can be generated with pmotools-python --bash-completion

# bash completion for pmotools-python
# add the below to your ~/.bash_completion

_pmotools_python_complete()
{
    # Make sure underscores (and =) are NOT treated as word breaks
    # so options like --pmo_files or --file=path complete as one token.
    local _OLD_WB="${COMP_WORDBREAKS-}"
    COMP_WORDBREAKS="${COMP_WORDBREAKS//_/}"
    COMP_WORDBREAKS="${COMP_WORDBREAKS//=}"

    local cur prev
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # 1) Completing the command name (1st arg): list all commands
    if [[ ${COMP_CWORD} -eq 1 ]]; then
        # Our CLI prints machine-friendly list via --list-plain:
        # "<command>\t<group>\t<help>"
        local lines cmds
        lines="$(${COMP_WORDS[0]} --list-plain 2>/dev/null)"
        cmds="$(printf '%s\n' "${lines}" | awk -F'\t' '{print $1}')"
        COMPREPLY=( $(compgen -W "${cmds}" -- "${cur}") )

        # restore wordbreaks before returning
        COMP_WORDBREAKS="$_OLD_WB"
        return 0
    fi

    # 2) Completing flags for a leaf command: scrape leaf -h
    if [[ "${cur}" == -* ]]; then
        local helps opts
        helps="$(${COMP_WORDS[0]} ${COMP_WORDS[1]} -h 2>/dev/null)"
        # Pull out flag tokens and split comma-separated forms
        # Keep underscores intact in the tokens.
        opts="$(printf '%s\n' "${helps}" \
            | sed -n 's/^[[:space:]]\{0,\}\(-[-[:alnum:]_][-[:alnum:]_]*\)\(, *-[[:alnum:]_][-[:alnum:]_]*\)\{0,\}.*/\1/p' \
            | sed 's/, / /g')"
        COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )

        COMP_WORDBREAKS="$_OLD_WB"
        return 0
    fi

    # 3) Otherwise, fall back to filename completion for positional args
    COMPREPLY=( $(compgen -f -- "${cur}") )

    # restore original word breaks
    COMP_WORDBREAKS="$_OLD_WB"
    return 0
}

complete -F _pmotools_python_complete pmotools-python

Developer Setup

To contribute to pmotools, follow these steps:

  1. Clone the repository and switch to the develop branch:
git clone git@github.com:your-org/pmotools.git
cd pmotools
git checkout develop
  1. Create your feature branch:
git checkout -b feature/my-feature
  1. Install and set up UV. This creates .venv/ and installs everything from pyproject.toml:
pip install -U uv
uv sync --dev
  1. Install pre-commit hooks (for formatting & linting):
uv run pre-commit install
  1. Run pre-commit manually on all files (first time):
uv run pre-commit run --all-files
  1. Develop your code. Pre-commit will automatically run on staged files before each commit, checking:
  • Formatting (Ruff)
  • Linting (Ruff)
  • Trailing whitespace, YAML syntax, large files
  1. Run tests:
uv run pytest
  1. Commit and push your changes:
git add .
git commit -m "Your message"
git push origin feature/my-feature

About

Toolkit for working with Portable Microhaplotype Objects (PMOs)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages