Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,50 @@ Then genome-wide association signals are added as black dots. The size of the do

Finally the `.png` file is saved (and `.svg` file if required).

### Step 3 - Generate gene arrow plot

The `plot-gene-arrow` command generates a gene structure diagram (arrow plot) for a specific gene, showing its exons, UTRs, and strand direction.

```bash
uv run plot-gene-arrow --gene TSPAN6 --data-folder data_folder/ --config config.json
```

help output:

```text
usage: plot_gene_arrow.py [-h] -g GENE -d DATA_FOLDER -c CONFIG [-o OUTPUT] [-w ARROW_WIDTH]

Generate an arrow plot (gene structure diagram) for a given gene.
See github: https://github.com/DSuveges/GenomePlotter

options:
-h, --help show this help message and exit
-g GENE, --gene GENE Gene name (e.g. BRCA1)
-d DATA_FOLDER, --data-folder DATA_FOLDER
Path to the data folder containing processed files
-c CONFIG, --config CONFIG
Path to config JSON file
-o OUTPUT, --output OUTPUT
Output file basename (defaults to {gene_name}_arrow)
-w ARROW_WIDTH, --arrow-width ARROW_WIDTH
Arrow height in pixels (default: 10)
```

The script reads the pre-processed GENCODE arrow file from the data folder (generated in Step 1), filters it for the requested gene, and renders the gene structure as an SVG and PNG. Both files are saved using the output basename.

**Examples:**

```bash
# Generate arrow plot for TSPAN6 using default output name (TSPAN6_arrow.svg / TSPAN6_arrow.png):
uv run plot-gene-arrow -g TSPAN6 -d data_folder/ -c config.json

# Specify a custom output basename:
uv run plot-gene-arrow -g BRCA1 -d data_folder/ -c config.json -o plots/BRCA1_structure

# Adjust arrow height:
uv run plot-gene-arrow -g TP53 -d data_folder/ -c config.json -w 15
```

### Gene sets

The `gene_sets/` folder contains a set of files that can be used as gene annotation:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies = [
"requests>=2.32.4",
"pyyaml>=6.0.2",
"cairosvg>=2.7.1",
"loguru>=0.7.0",
]

[project.optional-dependencies]
Expand All @@ -29,6 +30,7 @@ dev = [
[project.scripts]
prepare-data = "genome_plotter.prepare_data:main"
plot-chromosome = "genome_plotter.plot_chromosome:main"
plot-gene-arrow = "genome_plotter.plot_gene_arrow:main"

[build-system]
requires = ["hatchling"]
Expand Down
2 changes: 2 additions & 0 deletions src/genome_plotter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
from __future__ import annotations

__version__ = "0.1.0"

LOG_FORMAT = "{time:YYYY-MM-DD HH:mm:ss} {level} {module} - {function}: {message}"
4 changes: 2 additions & 2 deletions src/genome_plotter/assets/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"gwas_point": "#000000",
"arrow_colors": {
"line_color": "#6495ED",
"utr_color": "#FFE4B5",
"cds_color": "#ADD8E6"
"utr_color": "#CE93D8",
"cds_color": "#F4A460"
},
"cytoband_colors": {
"gneg": "#FFFFFF",
Expand Down
4 changes: 1 addition & 3 deletions src/genome_plotter/functions/ChromosomePlotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

from __future__ import annotations

import logging
import os

os.environ["DYLD_FALLBACK_LIBRARY_PATH"] = "/opt/homebrew/lib"

import cairosvg
import pandas as pd

logger = logging.getLogger(__name__)
from loguru import logger


class ChromosomePlotter:
Expand Down
23 changes: 13 additions & 10 deletions src/genome_plotter/functions/ColorFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from __future__ import annotations

import colorsys
import logging
import re

import numpy as np
import pandas as pd
from loguru import logger


def hex_to_rgb(hex_color: str) -> list[int]:
Expand Down Expand Up @@ -199,17 +199,20 @@ def __init__(
'All colors should be in hexadecimal format eg "#1ED5FA"'
)

# Checking dark max and the threshold:
for val in [dark_max, dark_threshold]:
if (not isinstance(val, float)) or (val >= 1) or (val <= 0):
# Validate darkening parameters only when they are provided:
if dark_max is not None or dark_threshold is not None:
for val in [dark_max, dark_threshold]:
if not isinstance(val, float) or (val >= 1) or (val <= 0):
raise ValueError(
f"dark_max and dark_threshold has to be float between 0 and 1 instead: {val}"
)
if not isinstance(width, int):
raise ValueError(
f"dark_max and dark_threshold has to be float between 0 and 1 instead: {val}"
f"width must be an integer when darkening is enabled. Got: {width}"
)

# Checking dark max and the threshold:
for val in [count, width]:
if not isinstance(val, int):
raise ValueError(f"Count and width have to be integers. Got: {val}")
if not isinstance(count, int):
raise ValueError(f"count has to be an integer. Got: {count}")

# Generating color gradients for a given length:
self.color_map = {
Expand Down Expand Up @@ -239,7 +242,7 @@ def map_color(self: ColorPicker, feature: str, gc_content: float | None) -> str:
try:
color = self.color_map[feature][int(gc_content * (self.count - 1))]
except KeyError:
logging.error(
logger.error(
f"Feature {feature} was not found in color mapper. Returning black."
)
color = "#000000"
Expand Down
Loading
Loading