Exemple #1
0
 def testMaxSequenceLength(self):
     a = Alignment()
     a['1'] = 'A--CG--T'
     a['2'] = 'AC----GT'
     a['3'] = 'A-C-G-T-'
     a['4'] = 'ACGT---T'
     self.assertEqual(a.max_sequence_length(), 5)
Exemple #2
0
 def testMaxSequenceLength(self):
     a = Alignment()
     a['1'] = 'A--CG--T'
     a['2'] = 'AC----GT'
     a['3'] = 'A-C-G-T-'
     a['4'] = 'ACGT---T'
     self.assertEqual(a.max_sequence_length(), 5)
Exemple #3
0
 def setUp(self):
     self.ts = TempFS()
     self.ts.create_top_level_temp(prefix='treeEstimatorTest', parent=os.curdir)
     self.filename = data_source_path('mafft.anolis.fasta')
     self.alignment = Alignment()
     self.alignment.read_filepath(data_source_path('mafft.anolis.fasta'),
             'FASTA')
Exemple #4
0
 def testConcatenateAlignments(self):
     filename1 = data_source_path('small.fasta')
     filename2 = data_source_path('small.fasta')
     a = Alignment()
     b = Alignment()
     a.datatype = "DNA"
     b.datatype = "DNA"
     a.read_filepath(filename1, 'FASTA')
     b.read_filepath(filename2, 'FASTA')
Exemple #5
0
    def _impl_test_aligner(self, name, fn):
        filename = data_source_path(fn)
        alignment = Alignment()
        alignment.read_filepath(filename, 'FASTA')

        aln = self.get_aligner('%s' % name)
        if aln is None:
            _LOG.warn("test%s skipped" % name)
            return
        a = aln.run(alignment,
                    tmp_dir_par=self.ts.top_level_temp,
                    delete_temps=True)

        reference_fn = data_source_path('%s.%s' % (name, fn))
        reference_aln = Alignment()
        reference_aln.read_filepath(reference_fn, 'FASTA')
        _LOG.debug('Checking results from %s against %s' % (name, reference_fn))
        if reference_aln != a:
            i = 1
            while True:
                nrfn  = reference_fn + '.' + str(i)
                if os.path.exists(nrfn):
                    reference_aln = Alignment()
                    reference_aln.read_filepath(nrfn, 'FASTA')
                    _LOG.debug('Checking results from %s against %s' % (name, nrfn))
                    if reference_aln == a:
                        self.assertEquals(reference_aln, a)
                        return True
                    i += 1
                else:
                    self.assertEquals(reference_aln, a)
Exemple #6
0
 def testConcatenateAlignments(self):
     filename1 = data_source_path('small.fasta')
     filename2 = data_source_path('small.fasta')
     a = Alignment()
     b = Alignment()
     a.datatype = "DNA"
     b.datatype = "DNA"
     a.read_filepath(filename1, 'FASTA')
     b.read_filepath(filename2, 'FASTA')
Exemple #7
0
    def _impl_test_merger(self, name):
        filename = data_source_path('merger1.fasta')
        alignment1 = Alignment()
        alignment1.read_filepath(filename, 'FASTA')
        filename = data_source_path('merger2.fasta')
        alignment2 = Alignment()
        alignment2.read_filepath(filename, 'FASTA')

        aln = self.get_merger('%s merger' % name)
        if aln is None:
            _LOG.warn("test%s skipped" % name)
            return
        a = aln.run(alignment1,
                    alignment2,
                    tmp_dir_par=self.ts.top_level_temp,
                    delete_temps=True)

        reference_fn = data_source_path('merger_result.fasta')
        reference_aln = Alignment()
        reference_aln.read_filepath(reference_fn, 'FASTA')
        self.assertEquals(reference_aln, a)
Exemple #8
0
 def testAlignment(self):
     filename = data_source_path('small.fasta')
     alignment = Alignment()
     alignment.read_filepath(filename, 'FASTA')
     num_taxa = alignment.get_num_taxa()
     self.assertEqual(num_taxa, 32)
     alignment.write_filepath(filename + '.phy', 'PHYLIP')
     alignment.write_unaligned_fasta(filename + '.raw')
     alignment.sub_alignment(list(
         alignment.keys())[0:2]).write_unaligned_fasta(filename +
                                                       '.partial.raw')
Exemple #9
0
    def _impl_test_aligner(self, name, fn):
        filename = data_source_path(fn)
        alignment = Alignment()
        alignment.read_filepath(filename, 'FASTA')

        aln = self.get_aligner('%s' % name)
        if aln is None:
            _LOG.warn("test%s skipped" % name)
            return
        a = aln.run(alignment,
                    tmp_dir_par=self.ts.top_level_temp,
                    delete_temps=True)

        reference_fn = data_source_path('%s.%s' % (name, fn))
        reference_aln = Alignment()
        reference_aln.read_filepath(reference_fn, 'FASTA')
        _LOG.debug('Checking results from %s against %s' %
                   (name, reference_fn))
        if reference_aln != a:
            i = 1
            while True:
                nrfn = reference_fn + '.' + str(i)
                if os.path.exists(nrfn):
                    reference_aln = Alignment()
                    reference_aln.read_filepath(nrfn, 'FASTA')
                    _LOG.debug('Checking results from %s against %s' %
                               (name, nrfn))
                    if reference_aln == a:
                        self.assertEquals(reference_aln, a)
                        return True
                    i += 1
                else:
                    self.assertEquals(reference_aln, a)
Exemple #10
0
 def testAlignment(self):
     filename = data_source_path('small.fasta')
     alignment = Alignment()
     alignment.read_filepath(filename, 'FASTA')
     num_taxa = alignment.get_num_taxa()
     self.assertEqual(num_taxa, 32)
     alignment.write_filepath(filename+'.phy', 'PHYLIP')
     alignment.write_unaligned_fasta(filename+'.raw')
     alignment.sub_alignment( alignment.keys()[0:2] ).write_unaligned_fasta(filename+'.partial.raw')
Exemple #11
0
class TreeEstimatorTest(unittest.TestCase):
    def setUp(self):
        self.ts = TempFS()
        self.ts.create_top_level_temp(prefix='treeEstimatorTest', parent=os.curdir)
        self.filename = data_source_path('mafft.anolis.fasta')
        self.alignment = Alignment()
        self.alignment.read_filepath(data_source_path('mafft.anolis.fasta'),
                'FASTA')

    def tearDown(self):
        dir_list = self.ts.get_remaining_directories()
        for dir in dir_list:
            try:
                self.ts.remove_dir(dir)
            except ValueError:
                pass

    def get_tree_estimator(self, name):
        try:
            return config.create_tree_estimator(name=name, temp_fs=self.ts)
        except RuntimeError:
            log_exception(_LOG)
            _LOG.warn("""Could not create an aligner of type %s !

This could indicate a bug in create_tree_estimator_using_config() or could mean that
your installation is not configured to run this tool.
""" % name)
            return None

    def _impl_test_tree_estimator(self, name, datatype, partitions, **kwargs):
        num_cpus = kwargs.get('num_cpus', None)
        filename = data_source_path('anolis.fasta')

        md = MultiLocusDataset()
        md.read_files(seq_filename_list=[filename],
                datatype=datatype)
        md.relabel_for_pasta()
        # alignment = Alignment()
        # alignment.read_filepath(filename, 'FASTA')
        te = self.get_tree_estimator(name)
        if te is None:
            _LOG.warn("test%s skipped" % name)
            return
        # alignment.datatype = datatype
        if num_cpus:
            a = te.run(alignment=md,
                       partitions=partitions,
                       tmp_dir_par=self.ts.top_level_temp,
                       delete_temps=True,
                       num_cpus=num_cpus)
        else:
            a = te.run(alignment=md,
                       partitions=partitions,
                       tmp_dir_par=self.ts.top_level_temp,
                       delete_temps=True)

    def testRaxml(self):
        # if is_test_enabled(TestLevel.SLOW, _LOG):
        self._impl_test_tree_estimator('raxml', datatype="DNA",
                partitions=[("DNA", 1, 1456)])

    def testFastTree(self):
        config.fasttree.add_option('options', StringUserSetting(
                name='options',
                default='', 
                short_name=None,
                help='Options to be passed to FastTree.',
                subcategory=None))
        self._impl_test_tree_estimator('fasttree', datatype="DNA",
                partitions=[("DNA", 1, 1456)])

    def testFastTreeMP(self):
        config.fasttree.add_option('options', StringUserSetting(
                name='options',
                default='',
                short_name=None,
                help='Options to be passed to FastTree.',
                subcategory=None))
        self._impl_test_tree_estimator('fasttree', datatype="DNA",
                partitions=[("DNA", 1, 1456)], num_cpus=2)
Exemple #12
0
    def _impl_test_merger(self, name):
        filename = data_source_path('merger1.fasta')
        alignment1 = Alignment()
        alignment1.read_filepath(filename, 'FASTA')
        filename = data_source_path('merger2.fasta')
        alignment2 = Alignment()
        alignment2.read_filepath(filename, 'FASTA')

        aln = self.get_merger('%s merger' % name)
        if aln is None:
            _LOG.warn("test%s skipped" % name)
            return
        a = aln.run(alignment1,
                    alignment2,
                    tmp_dir_par=self.ts.top_level_temp,
                    delete_temps=True)

        reference_fn = data_source_path('merger_result.fasta')
        reference_aln = Alignment()
        reference_aln.read_filepath(reference_fn, 'FASTA')
        self.assertEquals(reference_aln, a)