Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation-related errors and warnings #878

Merged
merged 12 commits into from
Apr 11, 2024
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
26 changes: 13 additions & 13 deletions .github/workflows/tests-tox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ jobs:
fail-fast: false
matrix:
include:
# - {name: '3.11', python: '3.11', os: ubuntu-latest, tox: py311}
# - {name: '3.11-MacOS', python: '3.11', os: macos-latest, tox: py311}
# - {name: '3.11-min', python: '3.11', os: ubuntu-latest, tox: "py311-min"}
- {name: '3.12', python: '3.12', os: ubuntu-latest, tox: py312}
- {name: '3.12-MacOS', python: '3.12', os: macos-latest, tox: py312}
- {name: '3.11', python: '3.11', os: ubuntu-latest, tox: py311}
- {name: '3.11-min', python: '3.11', os: ubuntu-latest, tox: "py311-min"}
- {name: '3.10', python: '3.10', os: ubuntu-latest, tox: py310}
- {name: '3.10-MacOS', python: '3.10', os: macos-latest, tox: py310}
- {name: '3.9', python: '3.9', os: ubuntu-latest, tox: py39}
- {name: '3.9-min', python: '3.9', os: ubuntu-latest, tox: "py39-min"}
- {name: '3.8', python: '3.8', os: ubuntu-latest, tox: py38}
- {name: '3.8-min', python: '3.8', os: ubuntu-latest, tox: "py38-min"}
- {name: Typing, python: '3.10', os: ubuntu-latest, tox: typing}
- {name: '3.8-MacOS', python: '3.8', os: macos-latest, tox: py38}
- {name: Typing, python: '3.12', os: ubuntu-latest, tox: typing}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
cache: 'pip'
Expand All @@ -43,13 +44,12 @@ jobs:
- name: Install Linux dependencies
if: runner.os == 'Linux'
run: |
sudo apt update
sudo apt-get install -y liblzma-dev python3-dev python3-numpy python3-matplotlib r-bioc-dnacopy zlib1g-dev
sudo apt-get update
sudo apt-get install -y liblzma-dev python3-dev r-bioc-dnacopy zlib1g-dev
- name: Install Mac OS dependencies
if: runner.os == 'macOS'
run: |
brew install r
Rscript --no-environ -e "source('http://callr.org/install#DNAcopy')"
Rscript --no-environ -e "install.packages('BiocManager', repos='https://cloud.r-project.org'); BiocManager::install('DNAcopy')"
- name: Install test runner tools
run: pip install flake8 pytest tox
- name: Lint with flake8
Expand All @@ -58,7 +58,7 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- name: Cache mypy
if: matrix.tox == 'typing'
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ./.mypy_cache
key: mypy|${{ matrix.python }}|${{ hashFiles('pyproject.toml') }}
Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ You can easily run CNVkit on your own data without installing it by using our
A `Galaxy tool <https://testtoolshed.g2.bx.psu.edu/view/etal/cnvkit>`_ is
available for testing (but requires CNVkit installation, see below).

A `Docker container <https://registry.hub.docker.com/u/etal/cnvkit/>`_ is also
A `Docker container <https://registry.hub.docker.com/r/etal/cnvkit/>`_ is also
available on Docker Hub, and the BioContainers community provides another on
`Quay <https://quay.io/repository/biocontainers/cnvkit>`_.

Expand Down Expand Up @@ -170,15 +170,15 @@ Copy number segmentation currently depends on R packages, some of which are part
of Bioconductor and cannot be installed through CRAN directly. To install these
dependencies, do the following in R::

> library(BiocManager)
> install("DNAcopy")
> if (!require("BiocManager", quietly=TRUE)) install.packages("BiocManager")
> BiocManager::install("DNAcopy")

This will install the DNAcopy package, as well as its dependencies.

Alternatively, to do the same directly from the shell, e.g. for automated
installations, try this instead::

Rscript -e "source('http://callr.org/install#DNAcopy')"
Rscript -e "source('https://callr.org/install#DNAcopy')"


Example workflow
Expand Down
2 changes: 1 addition & 1 deletion cnvlib/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def interval_coverages_pileup(bed_fname, bam_fname, min_mapq, procs=1, fasta=Non
# User-supplied bins might be zero-width or reversed -- skip those
spans = table.end - table.start
ok_idx = spans > 0
table = table.assign(depth=0, log2=NULL_LOG2_COVERAGE)
table = table.assign(depth=0.0, log2=NULL_LOG2_COVERAGE)
table.loc[ok_idx, "depth"] = table.loc[ok_idx, "basecount"] / spans[ok_idx]
ok_idx = table["depth"] > 0
table.loc[ok_idx, "log2"] = np.log2(table.loc[ok_idx, "depth"])
Expand Down
2 changes: 1 addition & 1 deletion cnvlib/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def export_theta(tumor_segs, normal_cn):

# Convert chromosome names to 1-based integer indices
chr2idx = {c: i + 1 for i, c in enumerate(tumor_segs.chromosome.drop_duplicates())}
table["chrm"] = tumor_segs.chromosome.replace(chr2idx)
table["chrm"] = tumor_segs.chromosome.map(chr2idx)
# Unique string identifier for each row, e.g. "start_1_93709:end_1_19208166"
table["#ID"] = [
f"start_{row.chrm}_{row.start}:end_{row.chrm}_{row.end}"
Expand Down
5 changes: 3 additions & 2 deletions cnvlib/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def combine_probes(
False,
fix_rmask,
)
ref_df = pd.concat([ref_df, anti_ref_df], ignore_index=True)
if not anti_ref_df.empty:
ref_df = pd.concat([ref_df, anti_ref_df], ignore_index=True)
all_logr = np.hstack([all_logr, anti_logr])
all_depths = np.hstack([all_depths, anti_depths])

Expand Down Expand Up @@ -259,7 +260,7 @@ def load_sample_block(
# Load coverage from target/antitarget files
logging.info("Loading %s", filenames[0])
cnarr1 = read_cna(filenames[0])
if not len(cnarr1):
if len(cnarr1) == 0:
# Just create an empty array with the right columns
col_names = ["chromosome", "start", "end", "gene", "log2", "depth"]
if "gc" in cnarr1 or fa_fname:
Expand Down
5 changes: 3 additions & 2 deletions cnvlib/segfilters.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def squash_by_groups(cnarr, levels, by_arm=False):
else:
# Enumerate chromosomes
chrom_names = cnarr["chromosome"].unique()
chrom_col = cnarr["chromosome"].replace(
chrom_names, np.arange(len(chrom_names))
chrom_col = cnarr["chromosome"].map(
pd.Series(np.arange(len(chrom_names)), index=chrom_names)
)
change_levels += chrom_col
data = cnarr.data.assign(_group=change_levels)
Expand All @@ -69,6 +69,7 @@ def squash_by_groups(cnarr, levels, by_arm=False):
groupkey.extend(["_g1", "_g2"])
data = (
data.groupby(groupkey, as_index=False, group_keys=False, sort=False)
[data.columns]
.apply(squash_region)
.reset_index(drop=True)
)
Expand Down
29 changes: 29 additions & 0 deletions conda-env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Usage:
# conda env create -f conda-env.yaml
# or:
# conda env update -v -n [base] -f conda-env.yml [--prune]
# This does not install CNVkit itself. Use pip to install either a stable release from
# PyPI (pip install cnvkit), or this local repo (pip install -e .).
name: cnvkit
channels:
- conda-forge
- bioconda
- defaults
dependencies:
- python>=3.8
- atlas # [not osx]
- bioconductor-dnacopy
- biopython >=1.80
- matplotlib >=3.5.2
- numpy >=1.24.2
- pandas >=1.5.3
- pomegranate >=0.14.8, <=0.14.9
- pyfaidx >=0.7.1
- pysam >=0.20.0
- pytest
- reportlab >=3.6.12
- ruff
- scikit-learn >=1.1.0
- scipy >=1.10.1
- tox

23 changes: 10 additions & 13 deletions devtools/conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@ requirements:
run:
- python
- atlas # [not osx]
- biopython >=1.79
- matplotlib >=3.5.1
- numpy >=1.21.6
- pandas >=1.3.5
- pomegranate ==0.14.8
- python-dateutil >=2.5.0
- pyfaidx >=0.6.4
- pysam >=0.17.0
- reportlab >=3.6.8
- scikit-learn
- scipy >=1.7.3
- networkx >=2.4
- bioconductor-dnacopy
# - joblib <1.0
- biopython >=1.80
- matplotlib >=3.5.2
- numpy >=1.24.2
- pandas >=1.5.3
- pomegranate >=0.14.8, <=0.14.9
- pyfaidx >=0.7.1
- pysam >=0.20.0
- reportlab >=3.6.12
- scikit-learn >=1.1.0
- scipy >=1.10.1

test:
imports:
Expand Down
26 changes: 6 additions & 20 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
FROM ubuntu:rolling
FROM continuumio/miniconda3:23.10.0-1
MAINTAINER Eric Talevich <[email protected]>

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
liblzma-dev \
python3-biopython \
python3-dev \
python3-matplotlib \
python3-numpy \
python3-pip \
python3-reportlab \
python3-scipy \
python3-pandas \
python3-tk \
r-base-core \
r-bioc-dnacopy \
zlib1g-dev
#RUN Rscript --no-environ -e "source('http://callr.org/install#DNAcopy')"
RUN pip3 install -U pip
RUN pip3 install cnvkit==0.9.10
# Install directly into 'base' conda environment
COPY conda-env.yml ./conda-env.yml
RUN conda env update -v -n base -f conda-env.yml
RUN conda clean --all --verbose
RUN pip3 install cnvkit==0.9.10 --no-cache
# Let matplotlib build its font cache
#RUN head `which cnvkit.py`
RUN cnvkit.py version

## USER CONFIGURATION, containers should not run as root
Expand Down
20 changes: 10 additions & 10 deletions requirements/core.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
biopython >= 1.79
matplotlib >= 3.5.1
numpy >= 1.21.6
pandas >= 1.3.5
pomegranate == 0.14.9
pyfaidx >= 0.6.4
pysam >= 0.17.0
reportlab >= 3.6.8
scikit-learn >= 1.0.2
scipy >= 1.7.3
biopython >= 1.80
matplotlib >= 3.5.2
numpy >= 1.24.2
pandas >= 1.5.3
pomegranate >=0.14.8, <=0.14.9
pyfaidx >= 0.7.1
pysam >= 0.20.0
reportlab >= 3.6.12
scikit-learn >= 1.1.0
scipy >= 1.10.1
23 changes: 10 additions & 13 deletions requirements/min.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
biopython == 1.79
matplotlib == 3.5.1
numpy == 1.22.0
pandas == 1.3.5
pomegranate == 0.14.9
pyfaidx == 0.6.4
pysam == 0.17.0
reportlab == 3.6.13
scikit-learn == 1.0.2
scipy == 1.10.0

## py310-min installed:
#numpy==1.22.4
biopython == 1.80
matplotlib == 3.5.2
numpy == 1.24.2
pandas == 1.5.3
pomegranate == 0.14.8
pyfaidx == 0.7.1
pysam == 0.20.0
reportlab == 3.6.12
scikit-learn == 1.2.1
scipy == 1.10.1
2 changes: 1 addition & 1 deletion requirements/typing.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mypy
mypy >= 1.1.0
types-contextvars
types-dataclasses
types-setuptools
Expand Down
7 changes: 5 additions & 2 deletions skgenome/gary.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def from_rows(
"""Create a new instance from a list of rows, as tuples or arrays."""
if columns is None:
columns = cls._required_columns
table = pd.DataFrame.from_records(rows, columns=columns)
if isinstance(rows, pd.DataFrame):
table = rows[columns].reset_index(drop=True)
else:
table = pd.DataFrame.from_records(rows, columns=columns)
return cls(table, meta_dict)

def as_columns(self, **columns):
Expand Down Expand Up @@ -712,7 +715,7 @@ def resize_ranges(self, bp: int, chrom_sizes: Optional[Mapping[str, Numeric]] =
table = self.data
limits = {"lower": 0}
if chrom_sizes:
limits["upper"] = self.chromosome.replace(chrom_sizes)
limits["upper"] = self.chromosome.map(chrom_sizes)
table = table.assign(
start=(table["start"] - bp).clip(**limits),
end=(table["end"] + bp).clip(**limits),
Expand Down
8 changes: 5 additions & 3 deletions skgenome/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def flatten(
split_columns: Optional[Iterable[str]] = None,
):
"""Combine overlapping regions into single rows, similar to bedtools merge."""
if not len(table):
if table.empty:
return table
if (table.start.values[1:] >= table.end.cummax().values[:-1]).all():
return table
Expand All @@ -31,6 +31,7 @@ def flatten(
cmb = get_combiners(table, False, combine)
out = (
table.groupby(by="chromosome", as_index=False, group_keys=False, sort=False)
[table.columns]
.apply(_flatten_overlapping, cmb, split_columns)
.reset_index(drop=True)
)
Expand Down Expand Up @@ -144,7 +145,7 @@ def merge(
combine: Optional[Dict[str, Callable]] = None,
):
"""Merge overlapping rows in a DataFrame."""
if not len(table):
if table.empty:
return table
gap_sizes = table.start.values[1:] - table.end.cummax().values[:-1]
if (gap_sizes > -bp).all():
Expand All @@ -158,6 +159,7 @@ def merge(
cmb = get_combiners(table, stranded, combine)
out = (
table.groupby(by=groupkey, as_index=False, group_keys=False, sort=False)
[table.columns]
.apply(_merge_overlapping, bp, cmb)
.reset_index(drop=True)
)
Expand Down Expand Up @@ -227,7 +229,7 @@ def _squash_tuples(keyed_rows, combine: Dict[str, Callable]):
if len(rows) == 1:
return firsttup
newfields = {
key: combiner([getattr(r, key) for r in rows])
key: combiner(pd.Series([getattr(r, key) for r in rows]))
for key, combiner in combine.items()
}
return firsttup._replace(**newfields)
2 changes: 1 addition & 1 deletion skgenome/tabio/picard.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def read_interval(infile):
comment="@", # Skip the SAM header
names=["chromosome", "start", "end", "strand", "gene"],
)
dframe["gene"].fillna("-", inplace=True)
dframe.fillna({"gene": "-"}, inplace=True)
dframe["start"] -= 1
return dframe

Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tox]
envlist =
py3{11,10,9,8}
py3{12,11,10,9,8}
py311-min
py38-min
py39-min
lint
typing
doc
Expand Down Expand Up @@ -39,7 +39,7 @@ commands = coverage run -m pytest test
package = wheel
wheel_build_env = .pkg
deps = -r requirements/typing.txt
commands = mypy -p skgenome -p cnvlib
commands = mypy -p skgenome -p cnvlib --disable-error-code=method-assign

[testenv:doc]
package = wheel
Expand Down