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 ufunc attribute error from numpy.log #125

Merged
merged 5 commits into from
Mar 6, 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
20 changes: 0 additions & 20 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,6 @@ jobs:
auto-activate-base: false
auto-update-conda: true

- name: Lint
# NOTE: must specify the shell so that conda init updates bashrc see:
# https://github.com/conda-incubator/setup-miniconda#IMPORTANT
shell: bash -l {0}
run: make lint

- name: Check format with black
shell: bash -l {0}
run: black --check gctree

- name: Test
shell: bash -l {0}
run: make test

- name: Test docs build
# NOTE: only run on ubuntu-latest to save on compute usage
if: matrix.os == 'ubuntu-latest'
shell: bash -l {0}
run: |
make docs
env:
QT_QPA_PLATFORM: offscreen
MPLBACKEND: agg
46 changes: 46 additions & 0 deletions .github/workflows/format-and-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: format and lint

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
format-and-lint:
runs-on: ubuntu-latest

steps:
- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Install Pandoc
uses: r-lib/actions/setup-pandoc@v2

- name: Install miniconda and create environment
uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: gctree
environment-file: environment.yml
python-version: "3.10"
auto-activate-base: false
auto-update-conda: true

- name: Lint
# NOTE: must specify the shell so that conda init updates bashrc see:
# https://github.com/conda-incubator/setup-miniconda#IMPORTANT
shell: bash -l {0}
run: make lint

- name: Check format with black
shell: bash -l {0}
run: black --check gctree

- name: Test docs build
# NOTE: only run on ubuntu-latest to save on compute usage
shell: bash -l {0}
run: |
make docs
env:
QT_QPA_PLATFORM: offscreen
MPLBACKEND: agg
35 changes: 20 additions & 15 deletions gctree/branching_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import matplotlib.pyplot as plt
from typing import Tuple, Dict, List, Union, Set, Callable, Mapping, Sequence, Optional
from decimal import Decimal
import math

sequence_resolutions = hdag.parsimony_utils.standard_nt_ambiguity_map_gap_as_char.get_sequence_resolution_func(
"sequence"
Expand Down Expand Up @@ -490,9 +491,11 @@ def my_layout(node):
C = ete3.CircleFace(
radius=node_size2,
color=circle_color,
label={"text": str(node.abundance), "color": text_color}
if node.abundance > 0
else None,
label=(
{"text": str(node.abundance), "color": text_color}
if node.abundance > 0
else None
),
)
C.rotation = -90
C.hz_align = 1
Expand Down Expand Up @@ -609,9 +612,11 @@ def my_layout(node):
node.add_face(
T,
0,
position="branch-bottom"
if start == 0
else "branch-top",
position=(
"branch-bottom"
if start == 0
else "branch-top"
),
)
if "*" in aa:
nstyle["hz_line_color"] = "red"
Expand Down Expand Up @@ -891,9 +896,9 @@ def local_branching(
for node in self.tree.traverse(strategy="postorder"):
if node.is_leaf():
node.LB_down = {
node: node.abundance * clone_contribution
if node.abundance > 1
else 0
node: (
node.abundance * clone_contribution if node.abundance > 1 else 0
)
}
else:
node.LB_down = {node: node.abundance * clone_contribution}
Expand Down Expand Up @@ -1100,9 +1105,11 @@ def to_tuple(mset):
)
grad_l.append(grad_ls[i_prime, j] + res)
# count_ls shouldn't have any zeros in it...
return (-np.log(count_ls.sum()) + scs.logsumexp(ls, b=count_ls)), np.array(
grad_l
)
# using math.log instead of np.log is essential because np.log
# doesn't work on large integers > 2**64 :eyeroll:
return (
-math.log(count_ls.sum()) + scs.logsumexp(ls, b=count_ls)
), np.array(grad_l)
else:
return (ls * count_ls).sum(), np.array(
[(grad_ls[:, 0] * count_ls).sum(), (grad_ls[:, 1] * count_ls).sum()]
Expand Down Expand Up @@ -1769,9 +1776,7 @@ def trees_to_dag(trees):
"original_ids": (
n.original_ids
if "original_ids" in n.features
else {n.name}
if n.is_leaf()
else set()
else {n.name} if n.is_leaf() else set()
),
"isotype": frozendict(),
},
Expand Down
1 change: 1 addition & 0 deletions gctree/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def isotype_add(forest):

if args.verbose:
print("number of trees with integer branch lengths:", forest.n_trees)

forest.mle(marginal=True)
# Add isotypes to forest
if args.isotype_mapfile:
Expand Down
6 changes: 3 additions & 3 deletions gctree/deduplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ def fasta_parse(aln_file, root, frame=None, aln_file2=None, id_abundances=False)
if seq.id == root:
root_seq = seqstr
if seqstr not in seqs_unique_counts:
seqs_unique_counts[
seqstr
] = [] # no observed root unless we see it elsewhere
seqs_unique_counts[seqstr] = (
[]
) # no observed root unless we see it elsewhere
elif seq.id.isdigit() and id_abundances:
seqs_unique_counts[seqstr] = [seq.id for _ in range(int(seq.id))]
else:
Expand Down
10 changes: 5 additions & 5 deletions gctree/isotyping.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ def __init__(
if weight_matrix is None:
weight_matrix = [
[
0.0
if target == origin
else 1.0
if target > origin
else float("inf")
(
0.0
if target == origin
else 1.0 if target > origin else float("inf")
)
for target in range(n)
]
for origin in range(n)
Expand Down
6 changes: 3 additions & 3 deletions gctree/mutation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ def mutate(
+ str(trials)
+ " consecutive attempts"
)
sequence_list[
mut_pos
] = original_base # <-- we only get here if we are retrying
sequence_list[mut_pos] = (
original_base # <-- we only get here if we are retrying
)

return sequence

Expand Down
1 change: 1 addition & 0 deletions gctree/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
r"""Utility functions."""

from functools import wraps, reduce
import Bio.Data.IUPACData
import operator
Expand Down
Loading