Example #1
0
    def test_uniqueness_filter(self):
        reads = Reads(self.sam1_file)

        reads.filter_non_unique(strict=True)
        for row in reads._reads._iter_visible_and_masked():
            if row['pos'] > 0:
                tags_str = reads._tags[row['ix']]
                try:
                    tags = pickle.loads(tags_str)
                except pickle.UnpackValueError:
                    tags = pickle.loads(tags_str + '\x00')
                tags = [(key.decode() if isinstance(key, bytes) else key,
                         value.decode() if isinstance(value, bytes) else value)
                        for key, value in tags]

                has_xs = False
                for tag in tags:
                    if tag[0] == 'XS':
                        has_xs = True
                        break
                if has_xs:
                    assert row[reads._reads._mask_field] == 2
            else:
                assert row[reads._reads._mask_field] == 0
        reads.close()
Example #2
0
    def test_select(self):
        reads = Reads(self.sam1_file)

        assert reads[0].qname == 'SRR038105.1'
        reads.filter_non_unique()
        assert reads[0].qname == 'SRR038105.10'
        reads.close()
Example #3
0
    def test_queue_filters(self):
        reads = Reads(self.sam1_file)

        l = len(reads)

        reads.filter_quality(30, queue=True)
        reads.filter_non_unique(strict=True, queue=True)

        assert len(reads) == l

        reads.run_queued_filters()

        assert len(reads) < l
        reads.close()
Example #4
0
    def test_iter(self):
        pairs = Reads(self.sam1_file)
        counter = 0
        for _ in pairs:
            counter += 1

        assert counter == 271

        pairs.filter_non_unique()
        after_counter = 0
        for _ in pairs:
            after_counter += 1

        assert after_counter < counter
        pairs.close()
Example #5
0
 def test_iterate_exclude_filters(self):
     reads = Reads(self.sam1_file)
     reads.filter_unmapped(queue=True)
     reads.filter_quality(35, queue=True)
     reads.filter_non_unique(strict=True, queue=True)
     reads.run_queued_filters()
     assert len(
         list(
             reads.reads(
                 excluded_filters=['unmapped', 'mapq', 'uniqueness'
                                   ]))) == 271
     assert len(
         list(reads.reads(
             excluded_filters=['unmapped', 'uniqueness']))) == 246
     assert len(list(
         reads.reads(excluded_filters=['unmapped', 'mapq']))) == 153
     assert len(list(
         reads.reads(excluded_filters=['mapq', 'uniqueness']))) == 271
     assert len(list(reads.reads(excluded_filters=['unmapped']))) == 153
     assert len(list(reads.reads(excluded_filters=['mapq']))) == 153
     assert len(list(reads.reads(excluded_filters=['uniqueness']))) == 246
     reads.close()