コード例 #1
0
    def _build_repr(self, include_name):
        lines = ElasticLines()

        if include_name:
            name_line = self.__class__.__name__
            if len(self.name) > 0:
                name_line += ' (%s)' % self.name
            lines.add_line(name_line)
            lines.add_separator()

        lines.add_line('  AAs  = %s' % str(self._amino_acids))
        lines.add_line('Starts = %s' % str(self._starts))
        base1 = 'U' * 16 + 'C' * 16 + 'A' * 16 + 'G' * 16
        lines.add_line('Base1  = %s' % base1)
        base2 = ('U' * 4 + 'C' * 4 + 'A' * 4 + 'G' * 4) * 4
        lines.add_line('Base2  = %s' % base2)
        base3 = 'UCAG' * 16
        lines.add_line('Base3  = %s' % base3)

        return lines.to_str()
コード例 #2
0
    def _build_repr(self, include_name):
        lines = ElasticLines()

        if include_name:
            name_line = self.__class__.__name__
            if len(self.name) > 0:
                name_line += ' (%s)' % self.name
            lines.add_line(name_line)
            lines.add_separator()

        lines.add_line('  AAs  = %s' % str(self._amino_acids))
        lines.add_line('Starts = %s' % str(self._starts))
        base1 = 'U' * 16 + 'C' * 16 + 'A' * 16 + 'G' * 16
        lines.add_line('Base1  = %s' % base1)
        base2 = ('U' * 4 + 'C' * 4 + 'A' * 4 + 'G' * 4) * 4
        lines.add_line('Base2  = %s' % base2)
        base3 = 'UCAG' * 16
        lines.add_line('Base3  = %s' % base3)

        return lines.to_str()
コード例 #3
0
ファイル: test_base.py プロジェクト: liupfskygre/scikit-bio
 def test_add_lines(self):
     self.el = ElasticLines()
     self.el.add_lines(['alice', 'bob', 'carol'])
     self.assertEqual(self.el.to_str(), 'alice\nbob\ncarol')
コード例 #4
0
ファイル: test_base.py プロジェクト: liupfskygre/scikit-bio
 def setUp(self):
     self.el = ElasticLines()
コード例 #5
0
ファイル: test_base.py プロジェクト: liupfskygre/scikit-bio
class TestElasticLines(unittest.TestCase):
    def setUp(self):
        self.el = ElasticLines()

    def test_empty(self):
        self.assertEqual(self.el.to_str(), '')

    def test_add_line(self):
        self.el.add_line('foo')
        self.assertEqual(self.el.to_str(), 'foo')

    def test_add_lines(self):
        self.el = ElasticLines()
        self.el.add_lines(['alice', 'bob', 'carol'])
        self.assertEqual(self.el.to_str(), 'alice\nbob\ncarol')

    def test_add_separator(self):
        self.el.add_separator()
        self.assertEqual(self.el.to_str(), '')

        self.el.add_line('foo')
        self.assertEqual(self.el.to_str(), '---\nfoo')

        self.el.add_separator()
        self.el.add_lines(['bar', 'bazzzz'])
        self.el.add_separator()

        self.assertEqual(self.el.to_str(),
                         '------\nfoo\n------\nbar\nbazzzz\n------')
コード例 #6
0
ファイル: _repr.py プロジェクト: liupfskygre/scikit-bio
    def build(self):
        lines = ElasticLines()

        cls_name = self._seq.__class__.__name__
        lines.add_line(cls_name)
        lines.add_separator()

        if self._seq.has_metadata():
            lines.add_line('Metadata:')
            # Python 3 doesn't allow sorting of mixed types so we can't just
            # use sorted() on the metadata keys. Sort first by type then sort
            # by value within each type.
            for key in self._sorted_keys_grouped_by_type(self._seq.metadata):
                value = self._seq.metadata[key]
                lines.add_lines(self._format_metadata_key_value(key, value))

        if self._seq.has_positional_metadata():
            lines.add_line('Positional metadata:')
            for key in self._seq.positional_metadata.columns.values.tolist():
                dtype = self._seq.positional_metadata[key].dtype
                lines.add_lines(
                    self._format_positional_metadata_column(key, dtype))

        lines.add_line('Stats:')
        for label, value in self._seq._repr_stats():
            lines.add_line('%s%s: %s' % (self._indent, label, value))
        lines.add_separator()

        num_lines, num_chars, column_width = self._find_optimal_seq_chunking()

        # display entire sequence if we can, else display the first two and
        # last two lines separated by ellipsis
        if num_lines <= 5:
            lines.add_lines(self._format_chunked_seq(
                range(num_lines), num_chars, column_width))
        else:
            lines.add_lines(self._format_chunked_seq(
                range(2), num_chars, column_width))
            lines.add_line('...')
            lines.add_lines(self._format_chunked_seq(
                range(num_lines - 2, num_lines), num_chars, column_width))

        return lines.to_str()