Skip to content

Commit

Permalink
Merge branch 'remora_motif_expand' into 'master'
Browse files Browse the repository at this point in the history
Remora motif expand

See merge request algorithm/megalodon!88
  • Loading branch information
marcus1487 committed Jan 26, 2022
2 parents a693e9a + caed143 commit 16f9df2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 7 additions & 4 deletions megalodon/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,19 +1107,23 @@ def pyguppy_set_model_attributes(
)
self.is_flipflop = init_called_read.model_type == FF_GUPPY_NAME
self.is_crf = init_called_read.model_type == CRF_GUPPY_NAME
if self.is_crf:
LOGGER.info("CRF models are not fully supported.")

self.stride = init_called_read.model_stride
if remora_model_filename is not None or remora_model_spec is not None:
self.is_remora_mod = True
from remora import model_util

if remora_model_filename is not None:
LOGGER.debug(
f"Loading Remora model from file: {remora_model_filename}"
)
_, remora_metadata = model_util.load_model(
remora_model_filename, quiet=True
)
else:
LOGGER.debug(
f"Loading Remora model from specs: {remora_model_spec}"
)
_, remora_metadata = model_util.load_model(
pore=remora_model_spec[0],
basecall_model_type=remora_model_spec[1],
Expand All @@ -1130,8 +1134,7 @@ def pyguppy_set_model_attributes(
quiet=True,
)
self.ordered_mod_long_names = remora_metadata["mod_long_names"]
motif, motif_offset = remora_metadata["motif"]
can_idx = "ACGT".find(motif[motif_offset]) + 1
can_idx = "ACGT".find(remora_metadata["can_base"]) + 1
self.output_alphabet = (
"ACGT"[:can_idx]
+ remora_metadata["mod_bases"]
Expand Down
13 changes: 6 additions & 7 deletions megalodon/mods.py
Original file line number Diff line number Diff line change
Expand Up @@ -2298,12 +2298,11 @@ def __init__(
self.remora_RemoraRead = data_chunks.RemoraRead
self.load_remora_model()
self.mod_bases = self.remora_metadata["mod_bases"]
motif, motif_offset = self.remora_metadata["motif"]
can_base = motif[motif_offset]
can_base = self.remora_metadata["can_base"]
can_idx = "ACGT".find(can_base) + 1
if can_idx == 0:
raise mh.MegaError(
f"Invalid Remora model motif {motif}:{motif_offset}"
f"Invalid Remora model canonical base {can_base}"
)
self.alphabet = "ACGT"
self.output_alphabet = (
Expand All @@ -2322,12 +2321,12 @@ def __init__(
for mod_b, mln in self.mod_long_names
)
LOGGER.info(f"Loaded Remora model calls modified bases: {mod_str}")
if all_mod_motifs_raw is None:
if all_mod_motifs_raw is not None:
LOGGER.info(
f'Setting --mod-motif to "{motif} {motif_offset}" loaded '
"from Remora model"
"Modified base motifs derived from Remora model. "
"Ignoring --mod-motif."
)
all_mod_motifs_raw = [(self.mod_bases, motif, motif_offset)]
all_mod_motifs_raw = None
# only applicable to flip-flop modbases
self.can_mods_offsets = None
self.str_to_int_mod_labels = None
Expand Down

0 comments on commit 16f9df2

Please sign in to comment.