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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ readme = "README.md"
license = { file = "license.txt" }
requires-python = ">=3.10,<3.14"
dependencies = ["click",
"cogent3",
"cogent3>=2025.7.10a3",
"kaleido",
"numpy",
"scipy",
Expand Down
4 changes: 2 additions & 2 deletions src/mutation_motif/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""mutation_motif, software for naalyses of point mutations, see https://www.ncbi.nlm.nih.gov/pubmed/27974498"""
"""mutation_motif, software for analyses of point mutations, see https://www.ncbi.nlm.nih.gov/pubmed/27974498"""

from warnings import filterwarnings

filterwarnings("ignore", "Attempting to set identical bottom==top")
filterwarnings("ignore", "invalid value encountered.*")

__license__ = "BSD-3"
__version__ = "2025.01.28"
__version__ = "2025.7.17"
6 changes: 4 additions & 2 deletions src/mutation_motif/aln_to_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import os
import re

import cogent3

from mutation_motif import motif_count, profile
from mutation_motif.util import just_nucs, load_from_fasta, makedirs
from mutation_motif.util import just_nucs, makedirs

fn_suffixes = re.compile(r"\.(fa|fasta)\.*(gz|gzip|bz2)*$")

Expand Down Expand Up @@ -44,7 +46,7 @@ def align_to_counts(

direction = tuple(direction.split("to"))
chosen_base = direction[0]
orig_seqs = load_from_fasta(os.path.abspath(align_path))
orig_seqs = cogent3.load_aligned_seqs(os.path.abspath(align_path), moltype="dna")
seqs = orig_seqs.array_seqs
seqs = just_nucs(seqs)
if not randomise:
Expand Down
2 changes: 1 addition & 1 deletion src/mutation_motif/complement.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _reverse_complement(table):
rows = table.to_list()
for row in rows:
# we use the cogent3 DnaSeq object to do reverse complementing
seq = DNA.make_seq("".join(row[i] for i in pos_indices))
seq = DNA.make_seq(seq="".join(row[i] for i in pos_indices))
seq = list(seq.rc())
for i, index in enumerate(pos_indices):
row[index] = seq[i]
Expand Down
2 changes: 1 addition & 1 deletion src/mutation_motif/log_lin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pandas
import statsmodels.api as sm
import statsmodels.formula.api as smf
from cogent3.util.table import Table
from cogent3.core.table import Table
from scipy.stats import chi2

_poisson = sm.families.Poisson()
Expand Down
4 changes: 3 additions & 1 deletion src/mutation_motif/motif_count.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from collections import Counter
from itertools import product

from cogent3 import make_table
from cogent3 import get_moltype, make_table

from mutation_motif.util import array_to_str

dna_alpha = get_moltype("DNA").most_degen_alphabet()


def profile_to_seq_counts(data, flank_size):
"""converts data to seqs and returns sequence counts"""
Expand Down
8 changes: 1 addition & 7 deletions src/mutation_motif/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

import numpy
from cogent3 import DNA, load_table, make_table, open_
from cogent3.core.alignment import ArrayAlignment
from cogent3.parse.fasta import iter_fasta_records
from cogent3.util.union_dict import UnionDict
from pandas import read_json

Expand Down Expand Up @@ -151,13 +149,9 @@ def is_valid(data):
return (data >= 0).all() and (data < 4).all()


def load_from_fasta(filename):
seqs = list(iter_fasta_records(filename))
return ArrayAlignment(data=seqs, moltype=DNA)


def array_to_str(data):
"""convert numpy array back to DNA sequence"""
data = data.astype(numpy.uint8)
return ["".join(DNA.alphabet.from_indices(v)) for v in data]


Expand Down
2 changes: 1 addition & 1 deletion tests/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_get_random_indices(self):
class TestAlignSnpAnnotation(TestCase):
seqs = [("seq_0", "ATCAACATATAAAAAGGAAAT")]

d_aln = make_aligned_seqs(data=seqs, array_align=True, moltype=DNA).array_seqs
d_aln = make_aligned_seqs(seqs, moltype=DNA).array_seqs
step = 3
slice_side = 7
direction = "AtoC"
Expand Down
9 changes: 3 additions & 6 deletions tests/test_entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,39 @@
def ref_aln(DATA_DIR):
return load_aligned_seqs(
DATA_DIR / "entropy/ref.fasta",
array_align=True,
moltype=DNA,
)


@pytest.fixture(scope="session")
def ref_data(ref_aln):
return ref_aln.seq_data
return ref_aln.array_seqs


@pytest.fixture(scope="session")
def ctl_aln(DATA_DIR):
return load_aligned_seqs(
DATA_DIR / "entropy/control.fasta",
array_align=True,
moltype=DNA,
)


@pytest.fixture(scope="session")
def ctl_data(ctl_aln):
return ctl_aln.seq_data
return ctl_aln.array_seqs


@pytest.fixture(scope="session")
def gap_aln(DATA_DIR):
return load_aligned_seqs(
DATA_DIR / "entropy/gap.fasta",
array_align=True,
moltype=DNA,
)


@pytest.fixture(scope="session")
def gap_data(gap_aln):
return gap_aln.seq_data
return gap_aln.array_seqs


def test_validity(ref_data, gap_data):
Expand Down
5 changes: 2 additions & 3 deletions tests/test_motif_count.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest import TestCase, main

from cogent3 import DNA
from cogent3.core.alignment import ArrayAlignment
from cogent3 import DNA, make_aligned_seqs

from mutation_motif.motif_count import (
get_combined_counts,
Expand Down Expand Up @@ -36,7 +35,7 @@

def _get_seq_array(data):
"""returns [(n, seq), ...] as DenseArray"""
return ArrayAlignment(data=data, moltype=DNA).array_seqs
return make_aligned_seqs(data, moltype=DNA).array_seqs


class TestMotifCount(TestCase):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
def aln(DATA_DIR):
return load_aligned_seqs(
DATA_DIR / "just_nuc.fasta",
array_align=True,
moltype=DNA,
)

Expand Down Expand Up @@ -49,7 +48,6 @@ def test_just_nucs(aln):
def d_aln(DATA_DIR):
return load_aligned_seqs(
DATA_DIR / "load_seqs_to_array.fasta",
array_align=True,
moltype=DNA,
)

Expand Down
Loading