예제 #1
0
 def test_write_soft_clipped_to_file(self):
     '''test _write_soft_clipped_to_file'''
     tmp_file = 'tmp.soft_clipped'
     bam = os.path.join(data_dir, 'dummy.bam')
     bp = bam_parse.Parser(bam,
                           {'x': pyfastaq.sequences.Fasta('x', 'ACGT')})
     soft_clipped = {'ref1': {42: [142, 242], 43: [44, 45]}}
     bp.soft_clipped = soft_clipped
     bp._write_soft_clipped_to_file(tmp_file)
     expected_lines = ['ref1\t43\t142\t242', 'ref1\t44\t44\t45']
     got_lines = file_to_lines(tmp_file)
     self.assertEqual(got_lines, expected_lines)
     os.unlink(tmp_file)
예제 #2
0
    def test_sam_to_soft_clipped(self):
        '''test _sam_to_soft_clipped'''
        bam = os.path.join(data_dir, 'bam_parse_test_sam_to_soft_clipped.bam')
        bp = bam_parse.Parser(bam,
                              {'x': pyfastaq.sequences.Fasta('x', 'ACGT')})
        sam_reader = pysam.Samfile(bam, "rb")
        i = 0
        expected = [
            None, (False, False), (True, False), (False, True), (True, True)
        ]

        for sam in sam_reader.fetch(until_eof=True):
            if i == 0:
                with self.assertRaises(bam_parse.Error):
                    bp._sam_to_soft_clipped(sam)
            else:
                self.assertEqual(expected[i], bp._sam_to_soft_clipped(sam))

            i += 1
예제 #3
0
 def test_parse(self):
     '''test parse'''
     ref_seqs = {}
     ref_fasta = os.path.join(data_dir, 'bam_parse_test_parse.ref.fa')
     bam = os.path.join(data_dir, 'bam_parse_test_parse.bam')
     pyfastaq.tasks.file_to_dict(ref_fasta, ref_seqs)
     bp = bam_parse.Parser(bam, ref_seqs)
     bp.parse()
     expected_soft_clipped = {'ref1': {2: [1, 0], 58: [0, 1]}}
     expected_unmapped_mates = {'ref1': {2: 1}}
     l = link.Link(
         None,
         None,
         None,
         s='\t'.join(['ref1', '500', 'R', '240', 'ref2', '500', 'L',
                      '299']))
     expected_link_keys = [('ref1', 'ref2')]
     self.assertEqual(expected_soft_clipped, bp.soft_clipped)
     self.assertEqual(expected_unmapped_mates, bp.unmapped_mates)
     self.assertEqual(list(bp.scaff_graph.links.keys()), expected_link_keys)
     self.assertEqual(len(bp.scaff_graph.links[expected_link_keys[0]]), 1)
     self.assertEqual(bp.scaff_graph.links[expected_link_keys[0]][0], l)