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
37 changes: 37 additions & 0 deletions metagraph/integration_tests/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,43 @@ def test_simple_align_edit_distance_all_graphs(self, representation):
self.assertEqual(a, b)


def test_align_chain_requires_coordinates(self):
def build(mode):
graph = self.tempdir.name + f'/genome.MT.{mode}'
self._build_graph(input=TEST_DATA_DIR + '/genome.MT.fa',
output=graph, k=11, repr='succinct', mode=mode)
return graph + '.dbg'

def annotate(graph, anno_repr):
prefix = graph[:-len('.dbg')]
self._annotate_graph(TEST_DATA_DIR + '/genome.MT.fa', graph, prefix, anno_repr)
return f'{prefix}.{anno_repr}.annodbg'

def align(graph, anno):
command = f'{METAGRAPH} align --align-chain -i {graph} -a {anno} '\
f'{TEST_DATA_DIR}/genome_MT1.fq'
return subprocess.run(command.split(), stdout=PIPE, stderr=PIPE)

basic = build('basic')
canonical = build('canonical')

# no coordinates in the annotation
res = align(basic, annotate(basic, 'column'))
self.assertNotEqual(res.returncode, 0)
self.assertIn('--align-chain requires', res.stderr.decode())
self.assertEqual(res.stdout, b'')

# coordinates are not used on CANONICAL graphs
res = align(canonical, annotate(canonical, 'column_coord'))
self.assertNotEqual(res.returncode, 0)
self.assertIn('--align-chain requires', res.stderr.decode())

# a BASIC graph with coordinates is accepted
res = align(basic, annotate(basic, 'column_coord'))
self.assertEqual(res.returncode, 0)
self.assertEqual(len(res.stdout.decode().rstrip().split('\n')), 7)


@unittest.skipUnless(PROTEIN_MODE, "These alignment tests are only for the Protein alphabet")
class TestProteinAlign(TestingBase):
def setUp(self):
Expand Down
13 changes: 13 additions & 0 deletions metagraph/src/cli/align.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "graph/alignment/dbg_aligner.hpp"
#include "graph/alignment/aligner_labeled.hpp"
#include "graph/annotated_dbg.hpp"
#include "annotation/int_matrix/base/int_matrix.hpp"
#include "graph/graph_extensions/node_first_cache.hpp"
#include "seq_io/sequence_io.hpp"
#include "config/config.hpp"
Expand Down Expand Up @@ -382,6 +383,18 @@ int align_to_graph(Config *config) {
if (anno_dbg_future.valid())
anno_dbg = anno_dbg_future.get();

// Chaining needs the coordinates of the seeds, which the aligner uses only
// with an annotation with coordinates on a BASIC-mode graph.
if (config->alignment_chain
&& (graph->get_mode() != DeBruijnGraph::BASIC || !anno_dbg
|| !dynamic_cast<const annot::matrix::MultiIntMatrix*>(
&anno_dbg->get_annotator().get_matrix()))) {
logger->error("--align-chain requires a BASIC-mode graph and an annotation "
"with coordinates (e.g., annotate --coordinates, then "
"transform_anno --anno-type column_coord)");
return 1;
}

auto wrap_graph = [&](auto graph) {
if (graph->get_mode() == DeBruijnGraph::PRIMARY) {
graph = std::make_shared<CanonicalDBG>(graph);
Expand Down
2 changes: 1 addition & 1 deletion metagraph/src/graph/alignment/dbg_aligner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ ::align_both_directions(std::string_view forward,

if (config_.chain_alignments) {
if (!has_coordinates()) {
logger->error("Chaining only supported for seeds with coordinates. Skipping seed chaining.");
logger->error("Chaining requires seeds with coordinates");
exit(1);
}

Expand Down
Loading