### Install pre-commit hooks Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Install pre-commit hooks to run code quality checks automatically before each commit. ```bash pre-commit install ``` -------------------------------- ### Type hints example Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Example of a function with type hints, required for all new code. The function calculates layout coordinates for a phylogenetic tree. ```python def calculate_tree_layout(tree: Tree, width: float) -> dict[str, Any]: """Calculate layout coordinates for phylogenetic tree.""" ... ``` -------------------------------- ### Install package in development mode Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Install the package with dev dependencies using pip. This is required for local development. ```bash pip install -e ".[dev]" ``` -------------------------------- ### Install Phylustrator with pip Source: https://github.com/aadavin/phylustrator/blob/main/README.md Installs the Phylustrator package directly from the GitHub repository. SVG output requires no extra dependencies; PDF and PNG output additionally require cairosvg. ```bash pip install git+https://github.com/AADavin/Phylustrator ``` -------------------------------- ### Docstring example in Google style Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Example of a function with a Google-style docstring, required for all public functions, classes, and modules. The function renders a phylogenetic tree to SVG format. ```python def render_tree(tree: Tree, output_file: str = None) -> str: """Render a phylogenetic tree to SVG format. Args: tree: The phylogenetic tree to render. output_file: Optional path to write SVG output. If not provided, returns the SVG string. Returns: SVG representation of the tree as a string. Raises: ValueError: If the tree is empty or invalid. """ ... ``` -------------------------------- ### Clone the Phylustrator repository Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Clone the repository and navigate into the project directory. This is the first step in the local development setup. ```bash git clone https://github.com/AADavin/Phylustrator.git cd Phylustrator ``` -------------------------------- ### Bug Report Example with Unicode Error Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Example bug report format for Phylustrator issues, including version, OS, and a minimal reproduction. The reproduction uses the Tree class to create a tree, set a node name to a Unicode character, and render it, which triggers a UnicodeEncodeError. ```markdown Version: 0.0.1 OS: Ubuntu 22.04, Python 3.10 When rendering a tree with Unicode characters in node names, I get the following error: UnicodeEncodeError: 'ascii' codec can't encode character... Minimal reproduction: ```python from phylustrator import Tree tree = Tree("(A:1,B:1)C;") tree["A"].name = "α" tree.render() ``` ``` -------------------------------- ### Plot a phylogenetic tree with layers Source: https://github.com/aadavin/phylustrator/blob/main/README.md Creates a tree plot from a Newick string, adds layers for branch colouring, tip labels, a colourbar, and a time axis, then saves the figure as a PNG. The example uses a dictionary mapping node names to brain sizes for colouring branches. ```python import phylustrator as ph tree = ph.trees.loads("((((Human:6,Chimp:6)a:2,Gorilla:8)b:3,Orang:11)c:5,Gibbon:16)root;") brain = {"Human": 1350, "Chimp": 400, "Gorilla": 500, "Orang": 400, "Gibbon": 100, "a": 650, "b": 560, "c": 500, "root": 470} (ph.trees.plot(tree) + ph.trees.color_branches(brain) + ph.trees.tip_labels() + ph.trees.colorbar("brain size (cc)") + ph.trees.time_axis("million years")).save("tree.png") ``` -------------------------------- ### Commit changes with descriptive message Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Commits changes with a clear, descriptive message. Example message: "Add tree rotation feature". ```bash git commit -m "Add tree rotation feature" ``` -------------------------------- ### Render Newick tree to PDF and open Source: https://github.com/aadavin/phylustrator/blob/main/README.md Basic usage of the `phyl` command-line tool: pass a Newick file to render it to a temporary PDF and open it. ```bash phyl tree.nwk # render to a temporary PDF and open it ``` -------------------------------- ### Create a virtual environment Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Create a Python virtual environment and activate it. On Windows, use 'venv\Scripts\activate' instead of 'source venv/bin/activate'. ```bash python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate ``` -------------------------------- ### Run tests and lint locally Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Runs the test suite and ruff linter to ensure everything passes before pushing. ```bash pytest tests/ ruff check . ``` -------------------------------- ### Run ruff linting and formatting Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Run ruff checks and formatting to ensure code style compliance. Your code must pass these checks before being merged. ```bash ruff check . ruff format . ``` -------------------------------- ### Run test suite with pytest Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Runs the full test suite using pytest. Use this to verify all tests pass before submitting changes. ```bash pytest tests/ ``` -------------------------------- ### Read ZOMBI2 output with ph.zombi Source: https://github.com/aadavin/phylustrator/blob/main/README.md Loads ZOMBI2 simulation results into the core data models: genomes, copy-number profiles, an alignment for a specific family, and the species tree. This layer keeps the core format-agnostic. ```python import phylustrator as ph G = ph.zombi.read_genomes("run/genomes") # {lineage: Genome} M = ph.zombi.read_profiles("run") # family x genome copy-number Matrix aln = ph.zombi.read_alignment("run", family=0) # Alignment keyed by genome tree = ph.zombi.read_species_tree("run") # a Tree ``` -------------------------------- ### Save tree to SVG/PDF/PNG with -o Source: https://github.com/aadavin/phylustrator/blob/main/README.md Use the `-o` flag to save the output to a file; the format is inferred from the file extension (.svg, .pdf, .png). ```bash phyl tree.nwk -o fig.svg # save instead (format from the extension: .svg / .pdf / .png) ``` -------------------------------- ### Render radial tree without labels Source: https://github.com/aadavin/phylustrator/blob/main/README.md Use `--radial` to switch to a radial layout and `--no-labels` to hide tip labels. ```bash phyl tree.nwk --radial --no-labels ``` -------------------------------- ### Bump version, tag, and push to trigger release Source: https://github.com/aadavin/phylustrator/blob/main/RELEASING.md Commands to cut a release for version X.Y.Z. First bump the version in pyproject.toml, then commit, tag, and push. Pushing the tag triggers the Release workflow that builds and publishes to PyPI. ```bash # 1. bump the version in pyproject.toml: version = "X.Y.Z" git commit -am "release: X.Y.Z" # 2. tag and push — pushing the tag is what triggers build + publish git tag vX.Y.Z git push && git push --tags ``` -------------------------------- ### Create a feature branch Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Creates a new feature branch from the main branch. Use descriptive names like feature/svg-exports, fix/rendering-bug, or docs/api-guide. ```bash git checkout -b feature/your-feature-name ``` -------------------------------- ### Run tests with coverage report Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Runs tests with coverage measurement for the phylustrator package and generates an HTML coverage report. ```bash pytest tests/ --cov=phylustrator --cov-report=html ``` -------------------------------- ### Push feature branch to fork Source: https://github.com/aadavin/phylustrator/blob/main/CONTRIBUTING.md Pushes the feature branch to your fork on GitHub. ```bash git push origin feature/your-feature-name ``` -------------------------------- ### Create a multi-figure page with ph.page Source: https://github.com/aadavin/phylustrator/blob/main/README.md Nests whole figures as vectors, such as two trees side by side, with a single centered title and optional panel letters. The `width` and `units` parameters give the page a physical size to match a journal's column width. ```python ph.page([[ph.trees.plot(t1) + ph.trees.tip_labels(), ph.trees.plot(t2) + ph.trees.tip_labels()]], width=482, units="pt", title="The same tree under two analyses", letters=True).save("figure1.pdf") ``` -------------------------------- ### Plot a genome map with ph.genomes Source: https://github.com/aadavin/phylustrator/blob/main/README.md Reads a GFF file into a dictionary of Genome objects, then plots the first genome in a circular layout with genes colored by strand and a position axis. The result is saved as a PNG. ```python import phylustrator as ph G = ph.genomes.read_gff("genome.gff") # {name: Genome} genome = next(iter(G.values())) (ph.genomes.plot(genome, layout="circular", coordinates="nucleotide") + ph.genomes.genes(by="strand") + ph.genomes.position_axis()).save("ring.png") ```