Ejemplo n.º 1
0
    def test_call_correct_alignment(self):
        """CogentAligner: output expected alignment file
        """
        p = CogentAligner({'Module': self.muscle_module})
        log_fp = get_tmp_filename(\
         prefix='CogentAlignerTests_',suffix='.log')
        self._paths_to_clean_up.append(log_fp)

        actual = p(result_path=None, seq_path=self.input_fp, log_path=log_fp)
        expected = expected_muscle_alignment
        #note: lines in diff order w/ diff versions
        self.assertEqualItems(str(actual).splitlines(), expected.splitlines())
Ejemplo n.º 2
0
    def test_muscle_max_memory(self):
        """CogentAligner: muscle_max_memory should be passed to alignment fcn
        """
        p = CogentAligner({
            'Module': self.muscle_module,
            '-maxmb': '200',
        })
        self.assertEqual(p.Params["-maxmb"], "200")

        log_fp = get_tmp_filename(\
         prefix='CogentAlignerTests_',suffix='.log')
        self._paths_to_clean_up.append(log_fp)

        actual = p(result_path=None, seq_path=self.input_fp, log_path=log_fp)
        expected = expected_muscle_alignment
        #note: lines in diff order w/ diff versions
        self.assertEqualItems(str(actual).splitlines(), expected.splitlines())
Ejemplo n.º 3
0
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if opts.min_percent_id <= 1.0:
        opts.min_percent_id *= 100

    if not (1.0 <= opts.min_percent_id <= 100.0):
        option_parser.error('Minimum percent sequence identity must be' +
                            ' between 1.0 and 100.0: %2.2f' % opts.min_percent_id)

    if not opts.template_fp and opts.alignment_method == 'pynast':
        option_parser.error(
            'PyNAST requires a template alignment to be passed via -t')

    input_seqs_filepath = opts.input_fasta_fp
    alignment_method = opts.alignment_method
    output_dir = opts.output_dir or alignment_method + '_aligned'
    create_dir(output_dir, fail_on_exist=False)

    # compute the minimum alignment length if a negative value was
    # provided (the default)
    min_length = opts.min_length
    if min_length < 0:
        min_length = compute_min_alignment_length(
            open(input_seqs_filepath, 'U'))

    fpath, ext = splitext(input_seqs_filepath)
    input_dir, fname = split(fpath)

    result_path = output_dir + '/' + fname + "_aligned.fasta"
    log_path = output_dir + '/' + fname + "_log.txt"
    failure_path = output_dir + '/' + fname + "_failures.fasta"

    if alignment_method in alignment_method_constructors:
        # try/except was causing problems here, so replacing with
        # an explicit check
        # define the aligner params
        aligner_constructor =\
            alignment_method_constructors[alignment_method]
        aligner_type = alignment_method
        params = {'min_len': min_length,
                  'min_pct': opts.min_percent_id,
                  'template_filepath': opts.template_fp,
                  'blast_db': opts.blast_db,
                  'pairwise_alignment_method': opts.pairwise_alignment_method}
        # build the aligner object
        aligner = aligner_constructor(params)
        # apply the aligner
        aligner(input_seqs_filepath, result_path=result_path,
                log_path=log_path, failure_path=failure_path)
    else:
        # define the aligner params
        aligner = CogentAligner({
            'Module': alignment_module_names.get(alignment_method, 'Unknown'),
            'Method': alignment_method
        })
        if alignment_method == "muscle":
            if opts.muscle_max_memory is not None:
                aligner.Params["-maxmb"] = str(opts.muscle_max_memory)
        # build the aligner
        aligner_type = 'Cogent'
        # apply the aligner
        aligner(result_path, seq_path=input_seqs_filepath,
                log_path=log_path)
Ejemplo n.º 4
0
def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if opts.min_percent_id <= 1.0:
        opts.min_percent_id *= 100

    if not (1.0 <= opts.min_percent_id <= 100.0):
        option_parser.error('Minimum percent sequence identity must be' +
                            ' between 1.0 and 100.0: %2.2f' %
                            opts.min_percent_id)

    if not opts.template_fp and opts.alignment_method == 'pynast':
        option_parser.error(
            'PyNAST requires a template alignment to be passed via -t')

    input_seqs_filepath = opts.input_fasta_fp
    alignment_method = opts.alignment_method
    output_dir = opts.output_dir or alignment_method + '_aligned'
    create_dir(output_dir, fail_on_exist=False)

    # compute the minimum alignment length if a negative value was
    # provided (the default)
    min_length = opts.min_length
    if min_length < 0:
        min_length = compute_min_alignment_length(
            open(input_seqs_filepath, 'U'))

    fpath, ext = splitext(input_seqs_filepath)
    input_dir, fname = split(fpath)

    result_path = output_dir + '/' + fname + "_aligned.fasta"
    log_path = output_dir + '/' + fname + "_log.txt"
    failure_path = output_dir + '/' + fname + "_failures.fasta"

    if alignment_method in alignment_method_constructors:
        # try/except was causing problems here, so replacing with
        # an explicit check
        # define the aligner params
        aligner_constructor =\
            alignment_method_constructors[alignment_method]
        aligner_type = alignment_method
        params = {
            'min_len': min_length,
            'min_pct': opts.min_percent_id,
            'template_filepath': opts.template_fp,
            'blast_db': opts.blast_db,
            'pairwise_alignment_method': opts.pairwise_alignment_method
        }
        # build the aligner object
        aligner = aligner_constructor(params)
        # apply the aligner
        aligner(input_seqs_filepath,
                result_path=result_path,
                log_path=log_path,
                failure_path=failure_path)
    else:
        # define the aligner params
        aligner = CogentAligner({
            'Module':
            alignment_module_names.get(alignment_method, 'Unknown'),
            'Method':
            alignment_method
        })
        if alignment_method == "muscle":
            if opts.muscle_max_memory is not None:
                aligner.Params["-maxmb"] = str(opts.muscle_max_memory)
        # build the aligner
        aligner_type = 'Cogent'
        # apply the aligner
        aligner(result_path, seq_path=input_seqs_filepath, log_path=log_path)