def main(args): logging.basicConfig(level=logging.getLevelName(args.logging)) logging.info('User args: %s' % pformat(args)) config = load_config_from_json_file( args.config, ['gap', 'same', 'diff', 'max_number_of_paths', 'max_sequence_length']) logging.info('Config is: \n%s' % pformat(config)) seq1 = load_fasta_file(args.input1) seq2 = load_fasta_file(args.input2) if config['max_sequence_length'] != 0 and max( len(seq1), len(seq2)) > config['max_sequence_length']: raise ValueError('Sequence exceeded max_sequence_length ') score_matrix, nodes_mapping = solve(seq1, seq2, config['gap'], config['diff'], config['same']) logging.debug('Score matrix: \n%s' % pformat(score_matrix)) logging.debug('Nodes mapping: (target_node): [(parent_node),...]\n%s' % pformat(nodes_mapping)) logging.info('Alignments score: %s' % score_matrix[len(seq1), len(seq2)]) paths = PathResolver(nodes_mapping).resolve_paths( len(seq1), len(seq2), config['max_number_of_paths']) allignments = [get_allignments(path, seq1, seq2) for path in paths] for (allignment_1, allignment_2), i in zip(allignments, range(len(allignments))): logging.info('[A%04d] %s' % (i, allignment_1)) logging.info('[A%04d] %s' % (i, allignment_2)) if args.output: save_output( args.output, { 'seq1': seq1, 'seq2': seq2, 'config': config, 'allignments': allignments, 'score_matrix': score_matrix.tolist() }) logging.info('Saved output to %s' % args.output)
def test_path_resolving_from_bottom_right(self): nodes_mapping = PathResolvingTest.get_nodes_mapping() path_resolver = PathResolver(nodes_mapping) paths = path_resolver.resolve_paths(4, 5) self.assertEqual(len(paths), 2)
def test_path_resolving_from_bottom_right_with_restrictions(self): max_number_of_paths = 1 nodes_mapping = PathResolvingTest.get_nodes_mapping() path_resolver = PathResolver(nodes_mapping) paths = path_resolver.resolve_paths(4, 5, max_number_of_paths) self.assertEqual(len(paths), max_number_of_paths)
def test_path_resolving_from_top_left(self): nodes_mapping = PathResolvingTest.get_nodes_mapping() path_resolver = PathResolver(nodes_mapping) paths = path_resolver.resolve_paths(0, 0) self.assertEqual(len(paths), 1)