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

Housekeeping #738

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions env_osx64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ dependencies:
- wand # Python bindings for ImageMagick
- pip
- pip:
- black
- hatch
- mock
- pytest
- pytest-benchmark
- pytest-cov
- PyYAML
7 changes: 6 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ dependencies:
- wand # Python bindings for ImageMagick
- pip
- pip:
- pytest
- black
- hatch
- mock
- pytest
- pytest-benchmark
- pytest-cov
- PyYAML
19 changes: 18 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ classifiers = [

dependencies = [
"biopython",
"bitarray",
"boto3",
"brewer2mpl",
"CrossMap",
Expand All @@ -50,18 +51,34 @@ dependencies = [
"more-itertools",
"natsort",
"networkx",
"numpy<2",
"numpy",
"ortools",
"pybedtools",
"pyefd",
"pyfasta",
#"pygraphviz",
"pyliftover",
"pypdf",
"pysam",
"pytesseract",
"rich",
"scikit-image",
"scipy",
"seaborn",
"segment_anything",
"Wand",
"webcolors",
#"BCBio",
#"BeautifulSoup",
#"cyvcf2",
#"gurobipy",
#"hmmlearn",
#"holoviews",
#"hvplot",
#"matplotlib_venn",
#"sklearn",
#"xlrd",
#"xlwt",
]

dynamic = ["version"]
Expand Down
6 changes: 3 additions & 3 deletions src/jcvi/algorithms/lpsolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ def has_ortools() -> bool:
Returns:
bool: True if installed
"""
try:
from ortools.linear_solver import pywraplp
import importlib.util

if importlib.util.find_spec("ortools.linear_solver.pywraplp") is not None:
return True
except ImportError:
else:
return False


Expand Down
2 changes: 1 addition & 1 deletion src/jcvi/annotation/pasa.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def consolidate(args):
gene = "gene_{0:0{pad}}".format(i, pad=6) if mode == "coords" else None

for elem in locus:
if type(elem) == tuple:
if isinstance(elem, tuple):
_gene, dbn = elem
if gene is None:
gene = _gene
Expand Down
13 changes: 5 additions & 8 deletions src/jcvi/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@
from socket import gethostname
from subprocess import CalledProcessError, PIPE, call, check_output
from time import ctime
from typing import Any, Collection, List, Optional, Tuple, Union
from typing import Collection, List, Optional, Tuple, Union
from urllib.parse import urlencode

# from optparse import OptionParser as OptionP, OptionGroup, SUPPRESS_HELP


from natsort import natsorted
from rich.console import Console
from rich.logging import RichHandler
Expand Down Expand Up @@ -122,7 +119,7 @@ def dispatch(self, globals):

action = sys.argv[1]

if not action in self.valid_actions:
if action not in self.valid_actions:
print("[error] {0} not a valid {1}\n".format(action, meta), file=sys.stderr)
alt = get_close_matches(action, self.valid_actions)
print(
Expand Down Expand Up @@ -1000,7 +997,7 @@ def set_home(self, prog, default=None):
if default is None: # Last attempt at guessing the path
try:
default = op.dirname(which(prog))
except:
except Exception:
default = None
else:
default = op.expanduser(default)
Expand Down Expand Up @@ -1029,7 +1026,7 @@ def ConfigSectionMap(Config, section):
cfg[option] = Config.get(section, option)
if cfg[option] == -1:
logger.debug("Skip: %s", option)
except:
except Exception:
logger.error("Exception on %s", option)
cfg[option] = None
return cfg
Expand Down Expand Up @@ -1318,7 +1315,7 @@ def mkdir(dirname, overwrite=False):
else:
try:
os.mkdir(dirname)
except:
except Exception:
os.makedirs(dirname)
logger.debug("`%s` not found. Creating new.", dirname)

Expand Down
10 changes: 5 additions & 5 deletions src/jcvi/apps/phylo.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def smart_reroot(treefile, outgroupfile, outfile, format=0):
try:
tree.set_outgroup(tree.get_common_ancestor(*outgroup))
except ValueError:
assert type(outgroup) == list
assert isinstance(outgroup, list)
outgroup = outgroup[0]
tree.set_outgroup(outgroup)
tree.write(outfile=outfile, format=format)
Expand Down Expand Up @@ -481,7 +481,7 @@ def SH_raxml(reftree, querytree, phy_file, shout="SH_out.txt"):
# hard coded
try:
pval = re.search("(Significantly.*:.*)", o).group(0)
except:
except Exception:
print("SH test failed.", file=sys.stderr)
else:
pval = pval.strip().replace("\t", " ").replace("%", "\%")
Expand Down Expand Up @@ -946,7 +946,7 @@ def build(args):
outfile, phy_file = build_nj_phylip(
alignment, outfile=out_file, outgroup=outgroup, work_dir=treedir
)
except:
except Exception:
print("NJ tree cannot be built for {0}".format(dna_file))

if opts.SH:
Expand All @@ -964,15 +964,15 @@ def build(args):
outfile, phy_file = build_ml_phyml(
alignment, outfile=out_file, work_dir=treedir
)
except:
except Exception:
print("ML tree cannot be built for {0}".format(dna_file))

elif opts.ml == "raxml":
try:
outfile, phy_file = build_ml_raxml(
alignment, outfile=out_file, work_dir=treedir
)
except:
except Exception:
print("ML tree cannot be built for {0}".format(dna_file))

if outgroup:
Expand Down
1 change: 1 addition & 0 deletions src/jcvi/apps/uclust.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ def consensus(args):
RAD = stack(S)

if len(data) == 1: # No computation needed
# TODO: seq is not defined!
output.append((fname, seq))
bins.extend(RAD)
start = end
Expand Down
5 changes: 0 additions & 5 deletions src/jcvi/apps/wga2ribbon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@

from collections import namedtuple
from jcvi.graphics.base import AbstractLayout
from operator import attrgetter
import argparse
import glob
import os
import shutil
import sys


def mainArgs():
Expand Down
1 change: 0 additions & 1 deletion src/jcvi/assembly/hic.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ def generate_groups(groupsfile):
Args:
groupsfile (str): Path to the groups file
"""
data = []
with open(groupsfile) as fp:
for row in fp:
seqids, color = row.split()
Expand Down
2 changes: 1 addition & 1 deletion src/jcvi/compara/fractionation.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def gaps(args):
not_in_gaps = popen(cmd).read()
not_in_gaps = int(not_in_gaps)
in_gaps = total - not_in_gaps
print("Ids in gaps: {1}".format(total, percentage(in_gaps, total)), file=sys.stderr)
print("Ids in gaps: {0}".format(percentage(in_gaps, total)), file=sys.stderr)


def get_tags(idsfile):
Expand Down
2 changes: 1 addition & 1 deletion src/jcvi/compara/quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def create_data_model(nodes, constraints_x, qa, constraints_y, qb):
num_constraints = len(constraints_x)

# non-self
if not (constraints_x is constraints_y):
if constraints_x is not constraints_y:
for c in constraints_y:
constraint_coeffs.append({x: 1 for x in c})
bounds.append(qb)
Expand Down
1 change: 1 addition & 0 deletions src/jcvi/compara/reconstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def fuse(args):

Fuse gene orders based on anchors file.
"""
# TODO: BiGraph is not used
from jcvi.algorithms.graph import BiGraph

p = OptionParser(fuse.__doc__)
Expand Down
1 change: 0 additions & 1 deletion src/jcvi/compara/synteny.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ def assemble(args):
Contents after the 3rd field (end gene) are ignored. Using the example
above, the final .blocks file will contain 5 columns, one column for each line.
"""
import shutil
from tempfile import mkdtemp, mkstemp

from jcvi.apps.align import last
Expand Down
6 changes: 3 additions & 3 deletions src/jcvi/formats/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1257,9 +1257,9 @@ def fix(args):
ntotal += 1

if nfixed:
logger.debug("Total fixed: %s".format(percentage(nfixed, ntotal)))
logger.debug("Total fixed: %s", percentage(nfixed, ntotal))
if nfiltered:
logger.debug("Total filtered: %s".format(percentage(nfiltered, ntotal)))
logger.debug("Total filtered: %s", percentage(nfiltered, ntotal))


def some(args):
Expand Down Expand Up @@ -1307,7 +1307,7 @@ def some(args):
print(b, file=fw)

fw.close()
logger.debug("Stats: %s features kept.".format(percentage(nkeep, ntotal)))
logger.debug(f"Stats: {percentage(nkeep, ntotal)} features kept.")


def uniq(args):
Expand Down
2 changes: 1 addition & 1 deletion src/jcvi/formats/fasta.py
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,7 @@ def diff(args):
printf("[green]Two sequence size match ({})".format(asize))
else:
printf(
"[red]Two sequence size do not match ({}, {}})".format(asize, bsize)
"[red]Two sequence size do not match ({}, {})".format(asize, bsize)
)

# print out the first place the two sequences diff
Expand Down
1 change: 1 addition & 0 deletions src/jcvi/formats/gff.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ def gb(args):
<http://www.biostars.org/p/2492/>
"""
try:
# TODO: remove this dependency. Could maybe substitute with BioPython
from BCBio import GFF
except ImportError:
print(
Expand Down
4 changes: 2 additions & 2 deletions src/jcvi/formats/obo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from collections import deque
from functools import partial
from typing import IO, Optional
from typing import IO, Optional, Tuple

from goatools.obo_parser import GODag

Expand All @@ -22,7 +22,7 @@
)


def load_GODag(obo_url: str, prt: Optional[IO] = None) -> (GODag, str):
def load_GODag(obo_url: str, prt: Optional[IO] = None) -> Tuple[GODag, str]:
"""
Load given obo url and returns GODag object.

Expand Down
20 changes: 1 addition & 19 deletions src/jcvi/graphics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,24 +322,6 @@ def update_figname(figname: str, format: str) -> str:
return figname + "." + format


def update_figname(figname: str, format: str) -> str:
"""Update the name of a figure to include the format.

Args:
figname (str): Path to the figure
format (str): Figure format, must be one of GRAPHIC_FORMATS

Returns:
str: New file path
"""
_, ext = op.splitext(figname)
if ext.strip(".") in GRAPHIC_FORMATS: # User suffix has precedence
return figname
# When the user has not supplied a format in the filename, use the requested format
assert format in GRAPHIC_FORMATS, "Invalid format"
return figname + "." + format


def savefig(figname, dpi=150, iopts=None, cleanup=True, transparent=False):
try:
format = figname.rsplit(".", 1)[-1].lower()
Expand Down Expand Up @@ -507,7 +489,7 @@ def asciiplot(x, y, digit=1, width=50, title=None, char="="):
ay = np.array(y)

if title:
print("[bold white]".format(title), file=sys.stderr)
print("[bold white]{}".format(title), file=sys.stderr)

az = ay * width // ay.max()
tx = [asciiaxis(x, digit=digit) for x in ax]
Expand Down
2 changes: 1 addition & 1 deletion src/jcvi/graphics/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def cv(x):
# Neogene and Cretaceous as these are more relevant for most phylogeny
if contrast_epochs:
for era, start, end in Geo:
if not era in ("Neogene", "Cretaceous"):
if era not in ("Neogene", "Cretaceous"):
continue

# Make a beige patch
Expand Down
2 changes: 1 addition & 1 deletion src/jcvi/utils/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def seqid_parse(seqid, sep=["-"], stdpf=True):

if sep is None:
sep = [""]
elif type(sep) == str:
elif isinstance(sep, str):
sep = [sep]

prefix = seqid[:lastnumi]
Expand Down
1 change: 0 additions & 1 deletion src/jcvi/variation/cnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""
Helper functions for Copy Number Variations (CNV).
"""
import logging
import os.path as op
import sys

Expand Down
Loading