Skip to content

Commit

Permalink
Merge pull request #42 from moshi4/develop
Browse files Browse the repository at this point in the history
Bump to v1.1.0
  • Loading branch information
moshi4 authored May 26, 2024
2 parents 1eaebc0 + 55fdd64 commit aee65af
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 38 deletions.
11 changes: 6 additions & 5 deletions docs/example_gallery.ipynb

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions docs/getting_started.ipynb

Large diffs are not rendered by default.

Binary file modified docs/images/pgv-gui_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/pygenomeviz_gallery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pygenomeviz"
version = "1.0.0"
version = "1.1.0"
description = "A genome visualization python package for comparative genomics"
authors = ["moshi4"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/pygenomeviz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pygenomeviz.genomeviz import GenomeViz

__version__ = "1.0.0"
__version__ = "1.1.0"

__all__ = [
"GenomeViz",
Expand Down
7 changes: 3 additions & 4 deletions src/pygenomeviz/align/tool/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import shlex
import shutil
import subprocess as sp
import sys
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Sequence
Expand Down Expand Up @@ -121,13 +120,13 @@ def run_cmd(
if len(stdout_lines) > 0:
logger.error("STDOUT:")
for line in stdout_lines:
logger.error(line)
logger.error(f"> {line}")
stderr_lines = cmd_res.stderr.splitlines()
if len(stderr_lines) > 0:
logger.error("STDERR:")
for line in stderr_lines:
logger.error(line)
sys.exit(1)
logger.error(f"> {line}")
raise RuntimeError(f"Failed to run '{self.get_tool_name()}' aligner!!")

def _parse_input_gbk_seqs(
self, seqs: Sequence[str | Path | Genbank]
Expand Down
8 changes: 7 additions & 1 deletion src/pygenomeviz/genomeviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ def savefig(
DPI
pad_inches : float, optional
Padding inches
Warnings
--------
To plot a figure that settings a user-defined legend, subtracks, or annotations,
call `fig.savefig()` instead of `gv.savefig()`.
"""
fig = self.plotfig(dpi=dpi)
fig.savefig(
Expand All @@ -575,7 +580,8 @@ def savefig_html(
html_outfile : str | Path | StringIO | BytesIO
Output HTML file (*.html)
figure : Figure | None, optional
If Figure set, plot html viewer using user customized figure
If Figure is set, plot html viewer using user customized figure.
Set to output figure including user-specified legend, subtracks, etc.
"""
# Load SVG contents
fig = self.plotfig(fast_render=False) if figure is None else figure
Expand Down
22 changes: 16 additions & 6 deletions src/pygenomeviz/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,10 @@

with genome_info_container.form(key="form"):
title_col, form_col = st.columns([4, 1])
title_col.markdown("**Genome Min-Max Range Option**")
title_col.markdown("**Genome Min-Max Range & Reverse Option**")
form_col.form_submit_button(
label="Update Figure",
help="Apply min-max range option changes to figure",
help="Apply min-max range & reverse option changes to figure",
)

name2seqid2range: dict[str, dict[str, tuple[int, int]]] = {}
Expand All @@ -401,7 +401,7 @@
with st.expander(expander_label, expanded=False):
seqid2range = {}
seqid2features = gbk.get_seqid2features(None)
for seqid, size in gbk.get_seqid2size().items():
for idx, (seqid, size) in enumerate(gbk.get_seqid2size().items()):
range_cols = st.columns([3, 3, 1])
min_range = range_cols[0].number_input(
label=f"**{seqid}** ({size:,} bp)",
Expand All @@ -427,9 +427,19 @@
if min_range > max_range:
st.error(f"**{max_range=}** must be larger than **{min_range=}**")
st.stop()
if min_range == max_range:
continue
seqid2range[seqid] = (min_range, max_range)
if min_range != max_range:
seqid2range[seqid] = (min_range, max_range)
reverse = range_cols[2].selectbox(
label="Reverse",
options=[True, False],
index=1,
format_func=lambda b: "Yes" if b else "No",
key=f"{gbk.name} {seqid} reverse",
)
if reverse is True:
gbk.records[idx] = gbk.records[idx].reverse_complement(
id=True, name=True, description=True
)
name2seqid2range[gbk.name] = seqid2range


Expand Down
10 changes: 6 additions & 4 deletions src/pygenomeviz/gui/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ def plot_by_gui_cfg(
Returns
-------
gv, align_coords : tuple[GenomeViz, list[AlignCoord]]
GenomeViz instance, AlignCoord list
gv : GenomeViz
GenomeViz instance
align_coords : list[AlignCoord]
AlignCoord list
"""
# Create genomeviz instance
gv = GenomeViz(
Expand Down Expand Up @@ -92,8 +94,8 @@ def plot_by_gui_cfg(
utils.remove_old_files(gui_cache_dir)

# Create md5 hash unique filename to enable cache alignment result
md5_hash_source = "\n".join([str(gbk) for gbk in gbk_list]).encode()
md5_hash_value = hashlib.md5(md5_hash_source).hexdigest()
md5_hash_source = "\n".join([f"{gbk} {gbk.full_genome_seq}" for gbk in gbk_list])
md5_hash_value = hashlib.md5(md5_hash_source.encode()).hexdigest()
aln_coords_filename = f"{md5_hash_value}_{cfg.aln.method}.tsv"
aln_coords_file = gui_cache_dir / aln_coords_filename.replace(" ", "")

Expand Down
12 changes: 8 additions & 4 deletions src/pygenomeviz/parser/genbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ def calc_gc_skew(
Returns
-------
gc_skew_result_tuple : tuple[NDArray[np.int64], NDArray[np.float64]]
Position list & GC skew list
pos_list : NDArray[np.int64]
Position list
gc_skew_list : NDArray[np.float64]
GC skew list
"""
pos_list, gc_skew_list = [], []
seq = self.genome_seq if seq is None else seq
Expand Down Expand Up @@ -185,8 +187,10 @@ def calc_gc_content(
Returns
-------
gc_content_result_tuple : tuple[NDArray[np.int64], NDArray[np.float64]]
Position list & GC content list
pos_list : NDArray[np.int64]
Position list
gc_content_list : NDArray[np.float64]
GC content list
"""
pos_list, gc_content_list = [], []
seq = self.genome_seq if seq is None else seq
Expand Down
16 changes: 12 additions & 4 deletions src/pygenomeviz/parser/gff.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,12 @@ def _parse_gff(
Returns
-------
gff_records, start, end : tuple[list[GffRecord], int, int]
GFF record list, start, end
gff_records : list[GffRecord]
GFF record list
start : int
Start position of target_seqid record
end : int
End position of target_seqid record
"""
gff_file = Path(gff_file)
if gff_file.suffix == ".gz":
Expand Down Expand Up @@ -296,8 +300,12 @@ def _parse_gff_textio(
Returns
-------
gff_records, start, end : tuple[list[GffRecord], int, int]
GFF record list, start, end
gff_records : list[GffRecord]
GFF record list
start : int
Start position of target_seqid record
end : int
End position of target_seqid record
"""
# Parse GFF lines
gff_all_lines = handle.read().splitlines()
Expand Down
6 changes: 4 additions & 2 deletions src/pygenomeviz/track/feature.py
Original file line number Diff line number Diff line change
Expand Up @@ -833,8 +833,10 @@ def _extract_exon_intron_locs(
Returns
-------
exon_locs, intron_locs : tuple[list[tuple[int, int]], list[tuple[int, int]]]
Exon & intron locations
exon_locs : list[tuple[int, int]]
Exon locations
intron_locs : list[tuple[int, int]]
Intron locations
"""
exon_locs: list[tuple[int, int]] = []
intron_locs: list[tuple[int, int]] = []
Expand Down
4 changes: 2 additions & 2 deletions src/pygenomeviz/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def load_example_genbank_dataset(
) -> list[Path]:
"""Load pygenomeviz example genbank dataset
Load genbank datasets from https://github.com/moshi4/pygenomeviz-data-v1
Load genbank datasets from <https://github.com/moshi4/pygenomeviz-data-v1>
and cache datasets in local directory (Default: `~/.cache/pygenomeviz/`).
List of dataset name
Expand Down Expand Up @@ -137,7 +137,7 @@ def load_example_gff_file(
) -> Path:
"""Load pygenomeviz example GFF file
Load example GFF file from https://github.com/moshi4/pygenomeviz-data-v1/
Load example GFF file from <https://github.com/moshi4/pygenomeviz-data-v1/>
and cache GFF file in local directory (Default: `~/.cache/pygenomeviz/`).
List of example GFF filename
Expand Down

0 comments on commit aee65af

Please sign in to comment.