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 nanomotif/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.1"
__version__ = "1.0.2"
21 changes: 15 additions & 6 deletions nanomotif/find_motifs_bin.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def worker_function(self, args):
if len(results) == 0:
log.info(f"No motifs found for bin {bin_name}")
return None

motifs = pl.concat(results, rechunk=True, parallel=False)
motifs = nm.motif.MotifSearchResult(motifs)
return motifs
Expand Down Expand Up @@ -266,8 +267,7 @@ def run(self):
self.counter.value += 1
results.append(r)
log.debug("Joining results")
results = [result for result in results if result is not None]
results = [result for result in results if not result.is_empty()]
results = [nm.motif.MotifSearchResult(result) for result in results if result is not None]
log.debug("Closing pool")
pool.close()
pool.join()
Expand Down Expand Up @@ -397,8 +397,8 @@ def process_subpileup(
high_meth_threshold=high_meth_threshold,
padding=padding,
min_kl=min_kl_divergence,
max_dead_ends=10,
max_rounds_since_new_best=15,
max_dead_ends=25,
max_rounds_since_new_best=30,
score_threshold=score_threshold
)
identified_motifs = nxgraph_to_dataframe(motif_graph) \
Expand Down Expand Up @@ -881,7 +881,7 @@ def run(self) -> tuple[MotifTree, Motif]:
priority_queue: list[tuple] = []
hq.heappush(
priority_queue,
(root_depth, 0, self.root_motif)
(0, root_depth, self.root_motif)
)

# Search loop
Expand All @@ -895,6 +895,15 @@ def run(self) -> tuple[MotifTree, Motif]:
current_model = current_attrs["model"]
current_depth = current_attrs.get("depth", 0)

current_n_mod, current_n_nomod = current_model.get_raw_counts()
if current_n_mod + current_n_nomod < 10:
log.debug(
f"{current_motif.string} expansion skipped due to low support ({current_n_mod} mod, {current_n_nomod} non-mod) | Model: {current_model} | "
f"Score: {current_attrs['score']:.2f} | "
f"Queue size: {len(priority_queue)} | "
f"Came from {', '.join(str(node) for node in list(self.motif_graph.predecessors(current_motif)))}"
)
continue
# Enforce motif length safely (current_model is defined)
if len(current_motif.strip()) > self.max_motif_length:
log.debug(
Expand Down Expand Up @@ -969,7 +978,7 @@ def run(self) -> tuple[MotifTree, Motif]:
attrs = self.motif_graph.nodes[next_motif]
hq.heappush(
priority_queue,
(attrs["depth"], -attrs["priority"], next_motif)
(-attrs["priority"], attrs["depth"], next_motif)
)

# Track best
Expand Down
1 change: 1 addition & 0 deletions nanomotif/motif.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ class MotifSearchResult(pl.DataFrame):

COMPLEMENTARY_COLUMNS = {
"motif_complement": pl.Utf8,
"mod_position_complement": pl.Int64,
"score_complement": pl.Float64,
"model_complement": pl.Object,
"n_mod_complement": pl.Int64,
Expand Down