示例#1
0
 def test_handle_logsExclusions(self):
     #pylint: disable=no-member
     read = MockRead()
     mate_transform = MicroMock(filters=())
     mock_log = MockLog()
     handler = ExcludeNonMatchedReadHandler(log_method=mock_log.log)
     try:
         handler.handle(read, MicroMock(filters=("filterA")),
                        mate_transform)
     except StopIteration:
         pass
     try:
         handler.handle(read, MicroMock(filters=("filterA")),
                        mate_transform)
     except StopIteration:
         pass
     try:
         handler.handle(read, MicroMock(filters=("filterB")),
                        mate_transform)
     except StopIteration:
         pass
     self.assertEquals(2, len(handler._all_exclusions))
     self.assertEquals(2, handler._all_exclusions["filterA"])
     self.assertEquals(1, handler._all_exclusions["filterB"])
     handler.end()
     self.assertEquals(2, len(mock_log._log_calls))
示例#2
0
 def test_handle_noExceptionIfNoFilters(self):
     read = MockRead()
     transformation = MicroMock(filters=())
     mate_transformation = MicroMock(filters=())
     mock_log = MockLog()
     handler = ExcludeNonMatchedReadHandler(log_method=mock_log.log)
     handler.handle(read, transformation, mate_transformation)
     self.assertEquals(True, True)
示例#3
0
 def test_handle_raisesIfTransformHasFilter(self):
     #pylint: disable=no-member
     read = MockRead()
     transformation = MicroMock(filters=("filterA"))
     mate_transformation = MicroMock(filters=())
     mock_log = MockLog()
     handler = ExcludeNonMatchedReadHandler(log_method=mock_log.log)
     self.assertRaises(StopIteration, handler.handle, read, transformation,
                       mate_transformation)
示例#4
0
 def test_handle_unpairsReadIfMateHasFilter(self):
     #pylint: disable=no-member
     read = MockRead()
     transformation = MicroMock(filters=())
     mate_transformation = MicroMock(filters=("filterA"))
     mock_log = MockLog()
     handler = readhandler.ExcludeNonMatchedReadHandler(log_method=mock_log)
     handler.handle(read, transformation, mate_transformation)
     self.assertEquals(False, read.is_paired)
示例#5
0
 def test_filter_builder_multiple(self):
     transform = MicroMock(primer_pair=MockPrimerPair(is_unmatched=True),
                           is_unmapped=False,
                           is_cigar_valid=False)
     self.assertEquals(["UNMATCHED_PRIMER_PAIR", "INVALID_CIGAR"],
                       clipper._filter_builder(transform))
     transform = MicroMock(primer_pair=MockPrimerPair(is_unmatched=True),
                           is_unmapped=True,
                           is_cigar_valid=False)
     self.assertEquals(["UNMAPPED_ALIGNMENT"],
                       clipper._filter_builder(transform))
示例#6
0
    def test_cigar_factory_nullCigar(self):
        mock_read = MicroMock(reference_start=42, cigarstring="*")
        c = cigar.cigar_factory(mock_read)
        self.assertIsInstance(c, cigar.NullCigarUtil)
        self.assertEquals(42, c.reference_start)
        self.assertEquals("*", c.cigar)

        mock_read = MicroMock(reference_start=42, cigarstring="")
        c = cigar.cigar_factory(mock_read)
        self.assertIsInstance(c, cigar.NullCigarUtil)
        self.assertEquals(42, c.reference_start)
        self.assertEquals("*", c.cigar)
示例#7
0
    def test_peak_memory(self):
        resource_getrusage_orig = resource.getrusage
        sys_platform_orig = sys.platform
        try:
            sys.platform = "darwin"
            resource.getrusage = lambda x: MicroMock(ru_maxrss=4200000)
            self.assertEquals(4, clipper._peak_memory())

            sys.platform = "linux"
            resource.getrusage = lambda x: MicroMock(ru_maxrss=4200)
            self.assertEquals(4, clipper._peak_memory())
        finally:
            resource.getrusage = resource_getrusage_orig
            sys.platform = sys_platform_orig
示例#8
0
 def test_handle_doesNotResetNextStartIfMateUnmapped(self):
     #pylint: disable=no-member
     reference_start = 111
     original_next_reference_start = 333
     read = MockRead(reference_start=reference_start,
                     cigarstring="10M",
                     next_reference_start=original_next_reference_start,
                     is_paired=True)
     new_reference_start = 222
     transformation = MicroMock(reference_start=new_reference_start,
                                cigar="10M")
     mate_transformation = MicroMock(is_unmapped=True, reference_start=333)
     handler = readhandler.TransformReadHandler()
     handler.handle(read, transformation, mate_transformation)
     self.assertEquals(original_next_reference_start,
                       read.next_reference_start)
示例#9
0
    def test_handle(self):
        read1 = MockRead(is_positive_strand=True)
        read2 = MockRead(is_positive_strand=True)
        primer_pair = MockPrimerPair(target_id="target_1",
                                     chrom="chr1",
                                     sense_start=242)
        new_reference_start = 102
        new_cigar_string = "2S8M"
        transformation = MicroMock(primer_pair=primer_pair,
                                   reference_start=new_reference_start,
                                   cigar=new_cigar_string)
        mate_transformation = None
        mock_primer_stats = MockPrimerStats()
        mock_primer_stats_dumper = MockPrimerStatsDumper()
        handler = readhandler.StatsHandler(mock_primer_stats,
                                           mock_primer_stats_dumper)

        handler.handle(read1, transformation, mate_transformation)
        handler.handle(read2, transformation, mate_transformation)
        expected_calls = [(read1, primer_pair), (read2, primer_pair)]
        self.assertEquals(expected_calls,
                          mock_primer_stats._add_read_primer_calls)

        handler.end()
        self.assertEquals([mock_primer_stats],
                          mock_primer_stats_dumper._dump_calls)
示例#10
0
 def test_handle(self):
     #pylint: disable=no-member
     read = MockRead(reference_start=100,
                     cigarstring="10M",
                     next_reference_start=150,
                     is_paired=True)
     new_reference_start = 102
     new_cigar_string = "2S8M"
     new_next_ref_start = 200
     transformation = MicroMock(primer_pair=None,
                                reference_start=new_reference_start,
                                cigar=new_cigar_string)
     mate_transformation = MicroMock(primer_pair=None,
                                     reference_start=new_next_ref_start,
                                     ciagr="",
                                     is_unmapped=False)
     handler = readhandler.TransformReadHandler()
     handler.handle(read, transformation, mate_transformation)
     self.assertEquals(new_reference_start, read.reference_start)
     self.assertEquals(new_cigar_string, read.cigarstring)
     self.assertEquals(new_next_ref_start, read.next_reference_start)
示例#11
0
    def test_handle_addsFiltersWhenPresent(self):
        #pylint: disable=no-member
        read = MockRead(reference_start=100,
                        reference_end=110,
                        cigarstring="10M")
        primer_pair_target = "target_1"
        primer_pair = MockPrimerPair(target_id=primer_pair_target)

        transformation = MicroMock(primer_pair=primer_pair,
                                   filters=("filter1", "filter2"))
        mate_transformation = None
        handler = readhandler.AddTagsReadHandler()

        handler.handle(read, transformation, mate_transformation)

        self.assertEquals("X4:Z:" + "filter1,filter2", read._tags["X4"])
示例#12
0
 def test_handle_ignoresMateIfUnpaired(self):
     #pylint: disable=no-member
     reference_start = 150
     read = MockRead(reference_start=100,
                     cigarstring="10M",
                     next_reference_start=reference_start,
                     is_paired=False)
     new_reference_start = 102
     new_cigar_string = "2S8M"
     transformation = MicroMock(primer_pair=None,
                                reference_start=new_reference_start,
                                cigar=new_cigar_string)
     mate_transformation = None
     handler = readhandler.TransformReadHandler()
     handler.handle(read, transformation, mate_transformation)
     self.assertEquals(reference_start, read.next_reference_start)
示例#13
0
    def test_handle(self):
        #pylint: disable=no-member
        original_reference_start = 100
        original_reference_end = 110
        original_cigar_string = "10M"
        read = MockRead(reference_start=original_reference_start,
                        reference_end=original_reference_end,
                        cigarstring=original_cigar_string)
        primer_pair_target = "target_1"
        primer_pair = MockPrimerPair(target_id=primer_pair_target)

        transformation = MicroMock(primer_pair=primer_pair, filters=())
        mate_transformation = None
        handler = readhandler.AddTagsReadHandler()

        handler.handle(read, transformation, mate_transformation)

        self.assertEquals("X0:Z:" + primer_pair_target, read._tags["X0"])
        self.assertEquals("X1:Z:" + original_cigar_string, read._tags["X1"])
        self.assertEquals("X2:i:" + str(original_reference_start),
                          read._tags["X2"])
        self.assertEquals("X3:i:" + str(original_reference_end),
                          read._tags["X3"])
示例#14
0
 def test_filter_builder_unmatchedPrimerPair(self):
     transform = MicroMock(primer_pair=MockPrimerPair(is_unmatched=True),
                           is_unmapped=False,
                           is_cigar_valid=True)
     self.assertEquals(["UNMATCHED_PRIMER_PAIR"],
                       clipper._filter_builder(transform))
示例#15
0
 def test_filter_builder_unmappedAlignment(self):
     transform = MicroMock(primer_pair=MockPrimerPair(is_unmatched=False),
                           is_unmapped=True,
                           is_cigar_valid=True)
     self.assertEquals(["UNMAPPED_ALIGNMENT"],
                       clipper._filter_builder(transform))
示例#16
0
 def test_filter_builder_invalidCigar(self):
     transform = MicroMock(primer_pair=MockPrimerPair(is_unmatched=False),
                           is_unmapped=False,
                           is_cigar_valid=False)
     self.assertEquals(["INVALID_CIGAR"],
                       clipper._filter_builder(transform))
示例#17
0
 def test_filter_builder_noFilters(self):
     transform = MicroMock(primer_pair=MockPrimerPair(is_unmatched=False),
                           is_unmapped=False,
                           is_cigar_valid=True)
     self.assertEquals([], clipper._filter_builder(transform))