Exemplo n.º 1
0
    def test_end_sortsAndIndexes(self):
        #pylint: disable=no-member
        with TempDirectory() as input_dir, TempDirectory() as output_dir:
            input_bam_filename = os.path.join(input_dir.path, "input.bam")
            make_bam_file(input_bam_filename, [build_read()])
            output_bam_filename = os.path.join(output_dir.path, "output.bam")
            mock_log = MockLog()
            handler = readhandler.WriteReadHandler(input_bam_filename,
                                                   output_bam_filename,
                                                   log_method=mock_log.log)
            read1 = build_read(query_name="read1",
                               reference_id=0,
                               reference_start=20)
            read2 = build_read(query_name="read2",
                               reference_id=0,
                               reference_start=10)

            handler.begin()
            handler.handle(read1, None, None)
            handler.handle(read2, None, None)
            handler.end()

            actual_files = sorted(os.listdir(output_dir.path))
            self.assertEquals(["output.bam", "output.bam.bai"], actual_files)
            actual_bam = pysam.AlignmentFile(output_bam_filename, "rb")
            actual_reads = [read for read in actual_bam.fetch()]
            actual_bam.close()

        self.assertEquals(2, len(actual_reads))
        self.assertEquals("read2", actual_reads[0].query_name)
        self.assertEquals("read1", actual_reads[1].query_name)
Exemplo n.º 2
0
    def test_end_sortsAndIndexes(self):
        #pylint: disable=no-member
        with TempDirectory() as input_dir, TempDirectory() as output_dir:
            input_bam_filename = os.path.join(input_dir.path, "input.bam")
            make_bam_file(input_bam_filename, [build_read()])
            output_bam_filename = os.path.join(output_dir.path, "output.bam")
            mock_log = MockLog()
            handler = readhandler.WriteReadHandler(input_bam_filename,
                                                    output_bam_filename,
                                                    log_method=mock_log.log)
            read1 = build_read(query_name="read1",
                               reference_id=0,
                               reference_start=20)
            read2 = build_read(query_name="read2",
                               reference_id=0,
                               reference_start=10)

            handler.begin()
            handler.handle(read1, None, None)
            handler.handle(read2, None, None)
            handler.end()

            actual_files = sorted(os.listdir(output_dir.path))
            self.assertEquals(["output.bam", "output.bam.bai"], actual_files)
            actual_bam = pysam.AlignmentFile(output_bam_filename, "rb")
            actual_reads = [read for read in actual_bam.fetch()]
            actual_bam.close()

        self.assertEquals(2, len(actual_reads))
        self.assertEquals("read2", actual_reads[0].query_name)
        self.assertEquals("read1", actual_reads[1].query_name)
Exemplo n.º 3
0
    def test_main(self):
        primer_file_content = \
'''Customer TargetID|Chr|Sense Start|Antisense Start|Sense Sequence|Antisense Sequence
primer1|1|101|200|AAGG|CCTT
primer2|2|501|600|CGCG|ATAT
'''.replace("|", "\t")
        CIGAR_10M = ((0,10),)
        readA1 = build_read(query_name = "readA",
                            query_sequence="AGCTTAGCTA",
                            flag = 99,
                            reference_id = 0,
                            reference_start = 100,
                            cigar = CIGAR_10M,
                            next_reference_id =0,
                            next_reference_start=190,
                            template_length=80)
        readA2 = build_read(query_name = "readA",
                            query_sequence="AGCTTAGCTA",
                            flag = 147,
                            reference_id = 0,
                            reference_start = 190,
                            cigar = CIGAR_10M,
                            next_reference_id = 0,
                            next_reference_start=100,
                            template_length=80)
        readB1 = build_read(query_name = "readB",
                            query_sequence="AGCTTAGCTA",
                            flag = 0,
                            reference_id = 1,
                            reference_start = 242,
                            cigar = CIGAR_10M,
                            next_reference_id = 0,
                            next_reference_start=0,
                            template_length=0)

        with TempDirectory() as input_dir, TempDirectory() as output_dir:
            input_bam_filename = os.path.join(input_dir.path, "input.bam")
            output_bam_filename = os.path.join(output_dir.path, "output.bam")
            input_primers_filename = self._create_file(input_dir.path,
                                                       'primers.txt',
                                                       primer_file_content)
            make_bam_file(input_bam_filename, [readA1, readA2, readB1])

            clipper.main(["katana",
                          input_primers_filename,
                          input_bam_filename,
                          output_bam_filename])

            actual = self._bam_to_sam(output_bam_filename)

        self.assertRegexpMatches(actual[0], "readA.*chr1.*105.*4S6M.*191")
        self.assertRegexpMatches(actual[1], "readA.*chr1.*191.*6M4S.*105")
        self.assertEquals(2, len(actual))
Exemplo n.º 4
0
    def test_main(self):
        primer_file_content = \
'''Customer TargetID|Chr|Sense Start|Antisense Start|Sense Sequence|Antisense Sequence
primer1|1|101|200|AAGG|CCTT
primer2|2|501|600|CGCG|ATAT
'''.replace("|", "\t")
        CIGAR_10M = ((0, 10), )
        readA1 = build_read(query_name="readA",
                            query_sequence="AGCTTAGCTA",
                            flag=99,
                            reference_id=0,
                            reference_start=100,
                            cigar=CIGAR_10M,
                            next_reference_id=0,
                            next_reference_start=190,
                            template_length=80)
        readA2 = build_read(query_name="readA",
                            query_sequence="AGCTTAGCTA",
                            flag=147,
                            reference_id=0,
                            reference_start=190,
                            cigar=CIGAR_10M,
                            next_reference_id=0,
                            next_reference_start=100,
                            template_length=80)
        readB1 = build_read(query_name="readB",
                            query_sequence="AGCTTAGCTA",
                            flag=0,
                            reference_id=1,
                            reference_start=242,
                            cigar=CIGAR_10M,
                            next_reference_id=0,
                            next_reference_start=0,
                            template_length=0)

        with TempDirectory() as input_dir, TempDirectory() as output_dir:
            input_bam_filename = os.path.join(input_dir.path, "input.bam")
            output_bam_filename = os.path.join(output_dir.path, "output.bam")
            input_primers_filename = self._create_file(input_dir.path,
                                                       'primers.txt',
                                                       primer_file_content)
            make_bam_file(input_bam_filename, [readA1, readA2, readB1])

            clipper.main([
                "katana", input_primers_filename, input_bam_filename,
                output_bam_filename
            ])

            actual = self._bam_to_sam(output_bam_filename)

        self.assertRegexpMatches(actual[0], "readA.*chr1.*105.*4S6M.*191")
        self.assertRegexpMatches(actual[1], "readA.*chr1.*191.*6M4S.*105")
        self.assertEquals(2, len(actual))