コード例 #1
0
ファイル: test_base.py プロジェクト: RNAer/scikit-bio
    def test_custom_phred_offset(self):
        ascii_chars = "*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\"
        obs = _encode_phred_to_qual(list(range(51)), phred_offset=42)
        self.assertEqual(obs, ascii_chars)

        with self.assertRaises(ValueError) as cm:
            _encode_phred_to_qual([42, -1, 33], phred_offset=42)
        self.assertIn("-1", str(cm.exception))
        self.assertIn("[0, 84]", str(cm.exception))

        obs = npt.assert_warns(UserWarning, _encode_phred_to_qual, [42, 255, 33], phred_offset=42)
        self.assertEqual(obs, "T~K")
コード例 #2
0
ファイル: test_base.py プロジェクト: RNAer/scikit-bio
    def test_illumina13_variant(self):
        # test entire range of possible ascii chars for illumina1.3
        all_illumina13_ascii = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijk" "lmnopqrstuvwxyz{|}~"
        obs = _encode_phred_to_qual(list(range(63)), variant="illumina1.3")
        self.assertEqual(obs, all_illumina13_ascii)

        with self.assertRaises(ValueError) as cm:
            _encode_phred_to_qual([42, -1, 33], variant="illumina1.3")
        self.assertIn("-1", str(cm.exception))
        self.assertIn("[0, 62]", str(cm.exception))

        obs = npt.assert_warns(UserWarning, _encode_phred_to_qual, [42, 63, 33], variant="illumina1.3")
        self.assertEqual(obs, "j~a")
コード例 #3
0
ファイル: test_base.py プロジェクト: RNAer/scikit-bio
    def test_illumina18_variant(self):
        # test entire range of possible ascii chars for illumina1.8
        all_illumina18_ascii = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKL" "MNOPQRSTUVWXYZ[\\]^_"
        obs = _encode_phred_to_qual(list(range(63)), variant="illumina1.8")
        self.assertEqual(obs, all_illumina18_ascii)

        with self.assertRaises(ValueError) as cm:
            _encode_phred_to_qual([42, -1, 33], variant="illumina1.8")
        self.assertIn("-1", str(cm.exception))
        self.assertIn("[0, 62]", str(cm.exception))

        obs = npt.assert_warns(UserWarning, _encode_phred_to_qual, [42, 63, 33], variant="illumina1.8")
        self.assertEqual(obs, "K_B")
コード例 #4
0
ファイル: test_base.py プロジェクト: pamgaea/scikit-bio
    def test_custom_phred_offset(self):
        ascii_chars = '*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\'
        obs = _encode_phred_to_qual(list(range(51)), phred_offset=42)
        self.assertEqual(obs, ascii_chars)

        with self.assertRaises(ValueError) as cm:
            _encode_phred_to_qual([42, -1, 33], phred_offset=42)
        self.assertIn('-1', str(cm.exception))
        self.assertIn('[0, 84]', str(cm.exception))

        obs = npt.assert_warns(UserWarning,
                               _encode_phred_to_qual, [42, 255, 33],
                               phred_offset=42)
        self.assertEqual(obs, 'T~K')
コード例 #5
0
ファイル: test_base.py プロジェクト: RNAer/scikit-bio
    def test_sanger_variant(self):
        # test entire range of possible ascii chars for sanger
        all_sanger_ascii = (
            "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOP" "QRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
        )
        obs = _encode_phred_to_qual(list(range(94)), variant="sanger")
        self.assertEqual(obs, all_sanger_ascii)

        with self.assertRaises(ValueError) as cm:
            _encode_phred_to_qual([42, -1, 33], variant="sanger")
        self.assertIn("-1", str(cm.exception))
        self.assertIn("[0, 93]", str(cm.exception))

        obs = npt.assert_warns(UserWarning, _encode_phred_to_qual, [42, 94, 33], variant="sanger")
        self.assertEqual(obs, "K~B")
コード例 #6
0
ファイル: test_base.py プロジェクト: pamgaea/scikit-bio
    def test_illumina13_variant(self):
        # test entire range of possible ascii chars for illumina1.3
        all_illumina13_ascii = ('@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijk'
                                'lmnopqrstuvwxyz{|}~')
        obs = _encode_phred_to_qual(list(range(63)), variant='illumina1.3')
        self.assertEqual(obs, all_illumina13_ascii)

        with self.assertRaises(ValueError) as cm:
            _encode_phred_to_qual([42, -1, 33], variant='illumina1.3')
        self.assertIn('-1', str(cm.exception))
        self.assertIn('[0, 62]', str(cm.exception))

        obs = npt.assert_warns(UserWarning,
                               _encode_phred_to_qual, [42, 63, 33],
                               variant='illumina1.3')
        self.assertEqual(obs, 'j~a')
コード例 #7
0
ファイル: test_base.py プロジェクト: pamgaea/scikit-bio
    def test_sanger_variant(self):
        # test entire range of possible ascii chars for sanger
        all_sanger_ascii = ('!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOP'
                            'QRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~')
        obs = _encode_phred_to_qual(list(range(94)), variant='sanger')
        self.assertEqual(obs, all_sanger_ascii)

        with self.assertRaises(ValueError) as cm:
            _encode_phred_to_qual([42, -1, 33], variant='sanger')
        self.assertIn('-1', str(cm.exception))
        self.assertIn('[0, 93]', str(cm.exception))

        obs = npt.assert_warns(UserWarning,
                               _encode_phred_to_qual, [42, 94, 33],
                               variant='sanger')
        self.assertEqual(obs, 'K~B')
コード例 #8
0
ファイル: test_base.py プロジェクト: pamgaea/scikit-bio
    def test_illumina18_variant(self):
        # test entire range of possible ascii chars for illumina1.8
        all_illumina18_ascii = ('!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKL'
                                'MNOPQRSTUVWXYZ[\\]^_')
        obs = _encode_phred_to_qual(list(range(63)), variant='illumina1.8')
        self.assertEqual(obs, all_illumina18_ascii)

        with self.assertRaises(ValueError) as cm:
            _encode_phred_to_qual([42, -1, 33], variant='illumina1.8')
        self.assertIn('-1', str(cm.exception))
        self.assertIn('[0, 62]', str(cm.exception))

        obs = npt.assert_warns(UserWarning,
                               _encode_phred_to_qual, [42, 63, 33],
                               variant='illumina1.8')
        self.assertEqual(obs, 'K_B')
コード例 #9
0
ファイル: fastq.py プロジェクト: sunhuaibo/scikit-bio
def _generator_to_fastq(obj, fh, variant=None, phred_offset=None,
                        id_whitespace_replacement='_',
                        description_newline_replacement=' ', lowercase=None):
    formatted_records = _format_fasta_like_records(
        obj, id_whitespace_replacement, description_newline_replacement, True,
        lowercase=lowercase)
    for header, seq_str, qual_scores in formatted_records:
        qual_str = _encode_phred_to_qual(qual_scores, variant=variant,
                                         phred_offset=phred_offset)
        fh.write('@')
        fh.write(header)
        fh.write('\n')
        fh.write(seq_str)
        fh.write('\n+\n')
        fh.write(qual_str)
        fh.write('\n')
コード例 #10
0
def _generator_to_fastq(obj, fh, variant=None, phred_offset=None,
                        id_whitespace_replacement='_',
                        description_newline_replacement=' ', lowercase=None):
    formatted_records = _format_fasta_like_records(
        obj, id_whitespace_replacement, description_newline_replacement, True,
        lowercase=lowercase)
    for header, seq_str, qual_scores in formatted_records:
        qual_str = _encode_phred_to_qual(qual_scores, variant=variant,
                                         phred_offset=phred_offset)
        fh.write('@')
        fh.write(header)
        fh.write('\n')
        fh.write(seq_str)
        fh.write('\n+\n')
        fh.write(qual_str)
        fh.write('\n')
コード例 #11
0
ファイル: test_base.py プロジェクト: pamgaea/scikit-bio
 def test_no_phred_scores(self):
     self.assertEqual(_encode_phred_to_qual([], variant='sanger'), '')
コード例 #12
0
ファイル: test_base.py プロジェクト: pamgaea/scikit-bio
 def test_unrecognized_variant(self):
     with self.assertRaises(ValueError) as cm:
         _encode_phred_to_qual([1, 2, 3], variant='illumina')
     self.assertIn('variant', str(cm.exception))
     self.assertIn("'illumina'", str(cm.exception))
コード例 #13
0
ファイル: test_base.py プロジェクト: pamgaea/scikit-bio
 def test_solexa_variant(self):
     with self.assertRaises(ValueError) as cm:
         _encode_phred_to_qual([1, 2, 3], variant='solexa')
     self.assertIn('719', str(cm.exception))
コード例 #14
0
ファイル: test_base.py プロジェクト: pamgaea/scikit-bio
 def test_variant_and_phred_offset_provided(self):
     with self.assertRaises(ValueError) as cm:
         _encode_phred_to_qual([1, 2, 3], variant='sanger', phred_offset=64)
     self.assertIn('both', str(cm.exception))
     self.assertIn('`variant`', str(cm.exception))
     self.assertIn('`phred_offset`', str(cm.exception))
コード例 #15
0
ファイル: test_base.py プロジェクト: RNAer/scikit-bio
 def test_solexa_variant(self):
     with self.assertRaises(ValueError) as cm:
         _encode_phred_to_qual([1, 2, 3], variant="solexa")
     self.assertIn("719", str(cm.exception))
コード例 #16
0
ファイル: test_base.py プロジェクト: RNAer/scikit-bio
 def test_missing_variant_and_phred_offset(self):
     with self.assertRaises(ValueError) as cm:
         _encode_phred_to_qual([1, 2, 3])
     self.assertIn("`variant`", str(cm.exception))
     self.assertIn("`phred_offset`", str(cm.exception))
     self.assertIn("encode", str(cm.exception))
コード例 #17
0
ファイル: test_base.py プロジェクト: RNAer/scikit-bio
 def test_no_phred_scores(self):
     self.assertEqual(_encode_phred_to_qual([], variant="sanger"), "")
コード例 #18
0
ファイル: test_base.py プロジェクト: RNAer/scikit-bio
 def test_unrecognized_variant(self):
     with self.assertRaises(ValueError) as cm:
         _encode_phred_to_qual([1, 2, 3], variant="illumina")
     self.assertIn("variant", str(cm.exception))
     self.assertIn("'illumina'", str(cm.exception))
コード例 #19
0
ファイル: test_base.py プロジェクト: pamgaea/scikit-bio
 def test_missing_variant_and_phred_offset(self):
     with self.assertRaises(ValueError) as cm:
         _encode_phred_to_qual([1, 2, 3])
     self.assertIn('`variant`', str(cm.exception))
     self.assertIn('`phred_offset`', str(cm.exception))
     self.assertIn('encode', str(cm.exception))
コード例 #20
0
ファイル: test_base.py プロジェクト: ebolyen/scikit-bio
 def test_solexa_variant(self):
     with self.assertRaises(NotImplementedError) as cm:
         _encode_phred_to_qual([1, 2, 3], variant='solexa')
     self.assertIn('719', str(cm.exception))
コード例 #21
0
ファイル: test_base.py プロジェクト: RNAer/scikit-bio
 def test_variant_and_phred_offset_provided(self):
     with self.assertRaises(ValueError) as cm:
         _encode_phred_to_qual([1, 2, 3], variant="sanger", phred_offset=64)
     self.assertIn("both", str(cm.exception))
     self.assertIn("`variant`", str(cm.exception))
     self.assertIn("`phred_offset`", str(cm.exception))