Пример #1
0
    def test_constructor_is_none(self):
        lrf = LabeledRecordFinder(lambda x: x.strip().startswith('>'),
                                  constructor=None)
        lines = '  \t   >abc  \n \t   def\n  // \t\n\t\t >efg \n//'.split('\n')

        obs = list(lrf(lines))
        exp = [['  \t   >abc  ', ' \t   def', '  // \t'], ['\t\t >efg ', '//']]
        self.assertEqual(obs, exp)
Пример #2
0
    def test_parsers_ignore(self):
        def never(line):
            return False

        def ignore_labels(line):
            return (not line) or line.isspace() or line.startswith('#')

        def is_start(line):
            return line.startswith('>')

        lines = ['>abc', '\n', '1', '>def', '#ignore', '2']
        self.assertEqual(list(LabeledRecordFinder(is_start)(lines)),
                         [['>abc', '1'], ['>def', '#ignore', '2']])
        self.assertEqual(
            list(LabeledRecordFinder(is_start, ignore=never)(lines)),
            [['>abc', '', '1'], ['>def', '#ignore', '2']])
        self.assertEqual(
            list(LabeledRecordFinder(is_start, ignore=ignore_labels)(lines)),
            [['>abc', '1'], ['>def', '2']])
Пример #3
0
def is_fasta_label(x):
    """Checks if x looks like a FASTA label line."""
    return x.startswith('>')


def is_blank_or_comment(x):
    """Checks if x is blank or a FASTA comment line."""
    return (not x) or x.startswith('#') or x.isspace()


def is_blank(x):
    """Checks if x is blank."""
    return (not x) or x.isspace()


FastaFinder = LabeledRecordFinder(is_fasta_label, ignore=is_blank_or_comment)


def parse_fasta(infile,
                strict=True,
                label_to_name=str,
                finder=FastaFinder,
                is_label=None,
                label_characters='>'):
    r"""yields label and seq from a fasta file.


    Parameters
    ----------
    data : open file object or str
        An open fasta file or a path to it.
Пример #4
0
 def setUp(self):
     """Define a standard LabeledRecordFinder"""
     self.FastaLike = LabeledRecordFinder(lambda x: x.startswith('>'))
Пример #5
0
 def setUp(self):
     self.FastaLike = LabeledRecordFinder(lambda x: x.startswith('>'))