Пример #1
0
    def test_overflow(self):
        tokens = [
            "ABCDEF",
            "HIGJKL",
            "MNOPQR",
            "STUVWX",
            "YZ",
        ]
        self.assertEqual(reprnator("$START$", tokens * 4, "#END#"),
                         '$START$ABCDEF, HIGJKL, MNOPQR, STUVWX, YZ, ABCDEF, H'
                         'IGJKL, MNOPQR, STUVWX, YZ, \n       ABCDEF, HIGJKL, '
                         'MNOPQR, STUVWX, YZ, ABCDEF, HIGJKL, MNOPQR, STUVWX, '
                         'YZ\n       #END#')

        self.assertEqual(reprnator("$START$", tokens * 3, "#END#"),
                         '$START$ABCDEF, HIGJKL, MNOPQR, STUVWX, YZ, ABCDEF, H'
                         'IGJKL, MNOPQR, STUVWX, YZ, \n       ABCDEF, HIGJKL, '
                         'MNOPQR, STUVWX, YZ#END#')
Пример #2
0
    def __repr__(self):
        """Return a string representation of the biological sequence object.

        Returns
        -------
        str
            String representation of the biological sequence object.

        Notes
        -----
        String representation contains the class name, the first six characters
        of the sequence, followed by ellipses, followed by the last six
        characters of the sequence (or the full sequence without
        ellipses, if the sequence is less than 21 characters long), followed by
        the sequence length, followed by flags indicating whether the sequence
        has metadata and/or positional metadata.

        Examples
        --------
        >>> from skbio import Sequence
        >>> s = Sequence('GGUCGUGAAGGA')
        >>> s # doctest: +NORMALIZE_WHITESPACE
        Sequence('GGUCGUGAAGGA', length=12, has_metadata=False,
                 has_positional_metadata=False)
        >>> t = Sequence('ACGT')
        >>> t # doctest: +NORMALIZE_WHITESPACE
        Sequence('ACGT', length=4, has_metadata=False,
                 has_positional_metadata=False)
        >>> t # doctest: +NORMALIZE_WHITESPACE
        Sequence('ACGT', length=4, has_metadata=False,
                 has_positional_metadata=False)
        >>> Sequence('GGUCGUGAAAAAAAAAAAAGGA') # doctest: +NORMALIZE_WHITESPACE
        Sequence('GGUCGU ... AAAGGA', length=22, has_metadata=False,
                 has_positional_metadata=False)
        >>> Sequence('ACGT',
        ...          metadata={id:'seq1'}) # doctest: +NORMALIZE_WHITESPACE
        Sequence('ACGT', length=4, has_metadata=True,
                 has_positional_metadata=False)
        """

        start = self.__class__.__name__ + "("
        end = ")"

        tokens = []

        tokens.append(self._format_str(self))
        tokens.append("length=%d" % len(self))
        tokens.append("has_metadata=%s" % self.has_metadata())
        tokens.append("has_positional_metadata=%s" %
                      self.has_positional_metadata())

        return reprnator(start, tokens, end)
Пример #3
0
    def __repr__(self):
        """Return a string representation of the biological sequence object.

        Returns
        -------
        str
            String representation of the biological sequence object.

        Notes
        -----
        String representation contains the class name, the first six characters
        of the sequence, followed by ellipses, followed by the last six
        characters of the sequence (or the full sequence without
        ellipses, if the sequence is less than 21 characters long), followed by
        the sequence length. If ID, description, or quality are present, they
        will be included after the sequence length (and truncated in a similar
        manner if they are too long).

        Examples
        --------
        >>> from skbio import Sequence
        >>> s = Sequence('GGUCGUGAAGGA')
        >>> repr(s)
        "Sequence('GGUCGUGAAGGA', length=12)"
        >>> t = Sequence('ACGT')
        >>> repr(t)
        "Sequence('ACGT', length=4)"
        >>> t
        Sequence('ACGT', length=4)
        >>> Sequence('GGUCGUGAAAAAAAAAAAAGGA')
        Sequence('GGUCGU ... AAAGGA', length=22)
        >>> Sequence('ACGT', id='seq1')
        Sequence('ACGT', length=4, id='seq1')

        """
        start = self.__class__.__name__ + "("
        end = ")"

        tokens = []

        tokens.append(self._format_str(self))
        tokens.append("length=%d" % len(self))
        if self.id:
            tokens.append("id=" + self._format_str(self.id))
        if self.description:
            tokens.append("description=" + self._format_str(self.description))
        if self._has_quality():
            tokens.append("quality=" + self._format_list(self.quality))

        return reprnator(start, tokens, end)
Пример #4
0
 def test_seperator(self):
     self.assertEqual(reprnator("", list("abc"), "", separator='|'),
                      "a|b|c")
Пример #5
0
    def test_one_line(self):
        self.assertEqual(reprnator("$START$", ["bill"], "#END#"),
                         "$START$bill#END#")

        self.assertEqual(reprnator("$START$", ["bill", "bob"], "#END#"),
                         "$START$bill, bob#END#")
Пример #6
0
 def test_no_tokens(self):
     self.assertEqual(reprnator("$START$", [], "#END#"), "$START$#END#")