コード例 #1
0
ファイル: test_fasta.py プロジェクト: johnchase/scikit-bio
    def test_fasta_to_generator_valid_files(self):
        test_cases = (self.empty, self.single, self.multi,
                      self.odd_labels_different_type,
                      self.sequence_collection_different_type,
                      self.lowercase_seqs)

        # Strategy:
        #   for each fasta file, read it without its corresponding qual file,
        #   and ensure observed vs. expected match, ignoring quality scores in
        #   expected. next, parse the current fasta file with each
        #   corresponding quality file and ensure that observed vs. expected
        #   match, this time taking quality scores into account. this
        #   sufficiently exercises parsing a standalone fasta file and paired
        #   fasta/qual files
        for exp, kwargs, fasta_fps, qual_fps in test_cases:
            for fasta_fp in fasta_fps:
                obs = list(_fasta_to_generator(fasta_fp, **kwargs))
                self.assertEqual(len(obs), len(exp))
                for o, e in zip(obs, exp):
                    e = e.copy()
                    del e.positional_metadata['quality']
                    self.assertEqual(o, e)

                for qual_fp in qual_fps:
                    obs = list(_fasta_to_generator(fasta_fp, qual=qual_fp,
                                                   **kwargs))

                    self.assertEqual(len(obs), len(exp))
                    for o, e in zip(obs, exp):
                        self.assertEqual(o, e)
コード例 #2
0
ファイル: test_fasta.py プロジェクト: johnchase/scikit-bio
    def test_roundtrip_generators(self):
        # test that fasta and qual files can be streamed into memory and back
        # out to disk using generator reader and writer
        fps = list(map(lambda e: list(map(get_data_path, e)),
                       [('empty', 'empty'),
                        ('fasta_multi_seq_roundtrip',
                         'qual_multi_seq_roundtrip')]))

        for fasta_fp, qual_fp in fps:
            with open(fasta_fp, 'U') as fh:
                exp_fasta = fh.read()
            with open(qual_fp, 'U') as fh:
                exp_qual = fh.read()

            fasta_fh = StringIO()
            qual_fh = StringIO()
            _generator_to_fasta(_fasta_to_generator(fasta_fp, qual=qual_fp),
                                fasta_fh, qual=qual_fh)
            obs_fasta = fasta_fh.getvalue()
            obs_qual = qual_fh.getvalue()
            fasta_fh.close()
            qual_fh.close()

            self.assertEqual(obs_fasta, exp_fasta)
            self.assertEqual(obs_qual, exp_qual)
コード例 #3
0
ファイル: test_fasta.py プロジェクト: nathanxma/scikit-bio
    def test_fasta_to_generator_valid_files(self):
        for exp, kwargs, fps in (self.empty, self.single, self.multi,
                                 self.odd_labels_different_type,
                                 self.sequence_collection_different_type):
            for fp in fps:
                obs = list(_fasta_to_generator(fp, **kwargs))

                self.assertEqual(len(obs), len(exp))
                for o, e in zip(obs, exp):
                    self.assertTrue(o.equals(e))
コード例 #4
0
ファイル: test_fasta.py プロジェクト: nathanxma/scikit-bio
    def test_roundtrip_generators(self):
        # test that a file can be streamed into memory and back out to disk
        # using generator reader and writer
        for fp in map(get_data_path, ['empty', 'fasta_multi_seq_roundtrip']):
            with open(fp, 'U') as fh:
                exp = fh.read()

            fh = StringIO()
            _generator_to_fasta(_fasta_to_generator(fp), fh)
            obs = fh.getvalue()
            fh.close()

            self.assertEqual(obs, exp)
コード例 #5
0
ファイル: test_fasta.py プロジェクト: johnchase/scikit-bio
 def test_fasta_to_generator_invalid_files(self):
     for fp, kwargs, error_type, error_msg_regex in self.invalid_fps:
         with self.assertRaisesRegexp(error_type, error_msg_regex):
             list(_fasta_to_generator(fp, **kwargs))
コード例 #6
0
ファイル: test_fasta.py プロジェクト: nathanxma/scikit-bio
 def test_fasta_to_generator_invalid_files(self):
     for fp, error_msg_regex in self.invalid_fps:
         with self.assertRaisesRegexp(FASTAFormatError, error_msg_regex):
             list(_fasta_to_generator(fp))