Exemplo n.º 1
0
    def __str__(self):
        """Return a string representation of the ordination results.

        String representation lists ordination results attributes and indicates
        whether or not they are present. If an attribute is present, its
        dimensions are listed. A truncated list of species and site IDs are
        included (if they are present).

        Returns
        -------
        str
            String representation of the ordination results.

        """
        lines = ['Ordination results:']

        attrs = [(self.eigvals, 'Eigvals'),
                 (self.proportion_explained, 'Proportion explained'),
                 (self.species, 'Species'),
                 (self.site, 'Site'),
                 (self.biplot, 'Biplot'),
                 (self.site_constraints, 'Site constraints')]
        for attr, attr_label in attrs:
            def formatter(e):
                return 'x'.join(['%d' % s for s in e.shape])

            lines.append(self._format_attribute(attr, attr_label, formatter))

        lines.append(self._format_attribute(self.species_ids, 'Species IDs',
                                            lambda e: _pprint_strs(e)))
        lines.append(self._format_attribute(self.site_ids, 'Site IDs',
                                            lambda e: _pprint_strs(e)))

        return '\n'.join(lines)
Exemplo n.º 2
0
    def __str__(self):
        """Return a string representation of the ordination results.

        String representation lists ordination results attributes and indicates
        whether or not they are present. If an attribute is present, its
        dimensions are listed. A truncated list of species and site IDs are
        included (if they are present).

        Returns
        -------
        str
            String representation of the ordination results.

        .. shownumpydoc

        """
        lines = ['Ordination results:']

        attrs = [(self.eigvals, 'Eigvals'),
                 (self.proportion_explained, 'Proportion explained'),
                 (self.species, 'Species'), (self.site, 'Site'),
                 (self.biplot, 'Biplot'),
                 (self.site_constraints, 'Site constraints')]
        for attr, attr_label in attrs:
            formatter = lambda e: 'x'.join(['%d' % s for s in e.shape])
            lines.append(self._format_attribute(attr, attr_label, formatter))

        lines.append(
            self._format_attribute(self.species_ids, 'Species IDs',
                                   lambda e: _pprint_strs(e)))
        lines.append(
            self._format_attribute(self.site_ids, 'Site IDs',
                                   lambda e: _pprint_strs(e)))

        return '\n'.join(lines)
Exemplo n.º 3
0
    def test_no_truncation(self):
        exp = "'a'"
        obs = _pprint_strs(['a'], max_chars=3)
        self.assertEqual(obs, exp)

        exp = "'a', 'b', 'c'"
        obs = _pprint_strs(['a', 'b', 'c'])
        self.assertEqual(obs, exp)

        exp = "'a', 'b', 'c'"
        obs = _pprint_strs(['a', 'b', 'c'], max_chars=13)
        self.assertEqual(obs, exp)
Exemplo n.º 4
0
    def test_no_truncation(self):
        exp = "'a'"
        obs = _pprint_strs(['a'], max_chars=3)
        self.assertEqual(obs, exp)

        exp = "'a', 'b', 'c'"
        obs = _pprint_strs(['a', 'b', 'c'])
        self.assertEqual(obs, exp)

        exp = "'a', 'b', 'c'"
        obs = _pprint_strs(['a', 'b', 'c'], max_chars=13)
        self.assertEqual(obs, exp)
Exemplo n.º 5
0
 def test_non_default_delimiter_and_suffix(self):
     exp = "'abc','defg',...."
     obs = _pprint_strs(['abc', 'defg', 'hi', 'jklmno'],
                        max_chars=14,
                        delimiter=',',
                        suffix='....')
     self.assertEqual(obs, exp)
Exemplo n.º 6
0
    def test_truncation(self):
        # truncation between items (on comma)
        exp = "'a', ..."
        obs = _pprint_strs(['a', 'b', 'c'], max_chars=4)
        self.assertEqual(obs, exp)

        # truncation between items (on space)
        exp = "'a', ..."
        obs = _pprint_strs(['a', 'b', 'c'], max_chars=5)
        self.assertEqual(obs, exp)

        # truncation on item
        exp = "'a', ..."
        obs = _pprint_strs(['a', 'b', 'c'], max_chars=6)
        self.assertEqual(obs, exp)

        # truncation (no items)
        exp = "..."
        obs = _pprint_strs(['a', 'b', 'c'], max_chars=2)
        self.assertEqual(obs, exp)
Exemplo n.º 7
0
    def test_truncation(self):
        # truncation between items (on comma)
        exp = "'a', ..."
        obs = _pprint_strs(['a', 'b', 'c'], max_chars=4)
        self.assertEqual(obs, exp)

        # truncation between items (on space)
        exp = "'a', ..."
        obs = _pprint_strs(['a', 'b', 'c'], max_chars=5)
        self.assertEqual(obs, exp)

        # truncation on item
        exp = "'a', ..."
        obs = _pprint_strs(['a', 'b', 'c'], max_chars=6)
        self.assertEqual(obs, exp)

        # truncation (no items)
        exp = "..."
        obs = _pprint_strs(['a', 'b', 'c'], max_chars=2)
        self.assertEqual(obs, exp)
Exemplo n.º 8
0
    def __str__(self):
        """Return a string representation of the ordination results.

        String representation lists ordination results attributes and indicates
        whether or not they are present. If an attribute is present, its
        dimensions are listed. A truncated list of features and sample IDs are
        included (if they are present).

        Returns
        -------
        str
            String representation of the ordination results.

        .. shownumpydoc

        """
        lines = ['Ordination results:']
        method = '%s (%s)' % (self.long_method_name, self.short_method_name)
        lines.append(self._format_attribute(method, 'Method', str))

        attrs = [(self.eigvals, 'Eigvals'),
                 (self.proportion_explained, 'Proportion explained'),
                 (self.features, 'Features'),
                 (self.samples, 'Samples'),
                 (self.biplot_scores, 'Biplot Scores'),
                 (self.sample_constraints, 'Sample constraints')]
        for attr, attr_label in attrs:
            def formatter(e):
                return 'x'.join(['%d' % s for s in e.shape])

            lines.append(self._format_attribute(attr, attr_label, formatter))

        lines.append(self._format_attribute(
            self.features, 'Feature IDs',
            lambda e: _pprint_strs(e.index.tolist())))
        lines.append(self._format_attribute(
            self.samples, 'Sample IDs',
            lambda e: _pprint_strs(e.index.tolist())))

        return '\n'.join(lines)
Exemplo n.º 9
0
    def __str__(self):
        """Return a string representation of the ordination results.

        String representation lists ordination results attributes and indicates
        whether or not they are present. If an attribute is present, its
        dimensions are listed. A truncated list of features and sample IDs are
        included (if they are present).

        Returns
        -------
        str
            String representation of the ordination results.

        .. shownumpydoc

        """
        lines = ["Ordination results:"]
        method = "%s (%s)" % (self.long_method_name, self.short_method_name)
        lines.append(self._format_attribute(method, "Method", str))

        attrs = [
            (self.eigvals, "Eigvals"),
            (self.proportion_explained, "Proportion explained"),
            (self.features, "Features"),
            (self.samples, "Samples"),
            (self.biplot_scores, "Biplot Scores"),
            (self.sample_constraints, "Sample constraints"),
        ]
        for attr, attr_label in attrs:

            def formatter(e):
                return "x".join(["%d" % s for s in e.shape])

            lines.append(self._format_attribute(attr, attr_label, formatter))

        lines.append(self._format_attribute(self.features, "Feature IDs", lambda e: _pprint_strs(e.index.tolist())))
        lines.append(self._format_attribute(self.samples, "Sample IDs", lambda e: _pprint_strs(e.index.tolist())))

        return "\n".join(lines)
Exemplo n.º 10
0
    def __str__(self):
        """Return a string representation of the dissimilarity matrix.

        Summary includes matrix dimensions, a (truncated) list of IDs, and
        (truncated) array of dissimilarities.

        Returns
        -------
        str
            String representation of the dissimilarity matrix.

        """
        return '%dx%d %s matrix\nIDs:\n%s\nData:\n' % (
            self.shape[0], self.shape[1], self._matrix_element_name,
            _pprint_strs(self.ids)) + str(self.data)
Exemplo n.º 11
0
    def __str__(self):
        """Return a string representation of the dissimilarity matrix.

        Summary includes matrix dimensions, a (truncated) list of IDs, and
        (truncated) array of dissimilarities.

        Returns
        -------
        str
            String representation of the dissimilarity matrix.

        """
        return '%dx%d %s matrix\nIDs:\n%s\nData:\n' % (
            self.shape[0], self.shape[1], self._matrix_element_name,
            _pprint_strs(self.ids)) + str(self.data)
Exemplo n.º 12
0
 def test_non_default_delimiter_and_suffix(self):
     exp = "'abc','defg',...."
     obs = _pprint_strs(['abc', 'defg', 'hi', 'jklmno'], max_chars=14,
                        delimiter=',', suffix='....')
     self.assertEqual(obs, exp)
Exemplo n.º 13
0
 def test_non_default_delimiter_and_suffix(self):
     exp = "'abc','defg',...."
     obs = _pprint_strs(["abc", "defg", "hi", "jklmno"], max_chars=14, delimiter=",", suffix="....")
     self.assertEqual(obs, exp)