Пример #1
0
    def testEmptyFileVCFGZWithoutIndex(self):
        with get_temp_context("tmp_testEmptyFileWithoutIndex.vcf") as fn:
            with open(fn, "w"):
                pass

            pysam.tabix_compress(fn, fn + ".gz", force=True)

            self.assertRaises(ValueError, pysam.VariantFile, fn + ".gz")
Пример #2
0
    def testEmptyFileVCFGZWithIndex(self):
        with get_temp_context("tmp_testEmptyFile.vcf") as fn:
            with open(fn, "w"):
                pass
            # tabix_index will automatically compress
            pysam.tabix_index(fn, preset="vcf", force=True)

            self.assertRaises(ValueError, pysam.VariantFile, fn + ".gz")
Пример #3
0
    def test_vcf_with_tbi_index(self):
        with get_temp_context("tmp_fn.vcf") as fn:
            shutil.copyfile(self.vcf_filename, fn)
            pysam.tabix_index(fn, preset="vcf", force=True)
            self.assertTrue(os.path.exists(fn + ".gz" + ".tbi"))
            self.assertFalse(os.path.exists(fn + ".gz" + ".csi"))

            with pysam.VariantFile(fn + ".gz") as inf:
                self.assertEqual(len(list(inf.fetch("20"))), 3)
Пример #4
0
 def test_vcf_with_tbi_index(self):
     with get_temp_context("tmp_fn.vcf") as fn:
         shutil.copyfile(self.vcf_filename, fn)
         pysam.tabix_index(fn, preset="vcf", force=True)
         self.assertTrue(os.path.exists(fn + ".gz" + ".tbi"))
         self.assertFalse(os.path.exists(fn + ".gz" + ".csi"))
         
         with pysam.VariantFile(fn + ".gz") as inf:
             self.assertEqual(len(list(inf.fetch("20"))), 3)
Пример #5
0
    def test_bcf_with_prebuilt_csi(self):
        with get_temp_context("tmp_fn.bcf") as fn:
            shutil.copyfile(self.bcf_filename, fn)
            shutil.copyfile(self.bcf_filename + ".csi", fn + ".csi")

            self.assertTrue(os.path.exists(fn + ".csi"))
            self.assertFalse(os.path.exists(fn + ".tbi"))

            with pysam.VariantFile(fn) as inf:
                self.assertEqual(len(list(inf.fetch("20"))), 3)
Пример #6
0
    def test_bcf_with_prebuilt_csi(self):
        with get_temp_context("tmp_fn.bcf") as fn:
            shutil.copyfile(self.bcf_filename, fn)
            shutil.copyfile(self.bcf_filename + ".csi", fn + ".csi")

            self.assertTrue(os.path.exists(fn + ".csi"))
            self.assertFalse(os.path.exists(fn + ".tbi"))
            
            with pysam.VariantFile(fn) as inf:
                self.assertEqual(len(list(inf.fetch("20"))), 3)
Пример #7
0
    def testEmptyFileVCFGZWithoutIndex(self):
        with get_temp_context("tmp_testEmptyFileWithoutIndex.vcf") as fn:
            with open(fn, "w"):
                pass

            pysam.tabix_compress(fn,
                                 fn + ".gz",
                                 force=True)

            self.assertRaises(ValueError, pysam.VariantFile, fn + ".gz")
Пример #8
0
    def testEmptyFileVCFGZWithIndex(self):
        with get_temp_context("tmp_testEmptyFile.vcf") as fn:
            with open(fn, "w"):
                pass
            # tabix_index will automatically compress
            pysam.tabix_index(fn,
                              preset="vcf",
                              force=True)

            self.assertRaises(ValueError, pysam.VariantFile, fn + ".gz")
Пример #9
0
    def test_bcf_with_tbi_index_will_produce_csi(self):
        with get_temp_context("tmp_fn.bcf") as fn:
            shutil.copyfile(self.bcf_filename, fn)

            pysam.tabix_index(fn, preset="bcf", force=True, csi=False)
            self.assertTrue(os.path.exists(fn + ".csi"))
            self.assertEqual(read_index_header(fn + ".csi"), b"CSI\1")
            self.assertFalse(os.path.exists(fn + ".tbi"))

            with pysam.VariantFile(fn) as inf:
                self.assertEqual(len(list(inf.fetch("20"))), 3)
Пример #10
0
 def testNegativeIntegersWrittenToFile(self):
     r = self.build_read()
     x = -2
     r.tags = [("XD", x)]
     with get_temp_context("negative_integers.bam") as fn:
         with pysam.AlignmentFile(fn,
                                  "wb",
                                  referencenames=("chr1", ),
                                  referencelengths=(1000, )) as outf:
             outf.write(r)
         with pysam.AlignmentFile(fn) as inf:
             r = next(inf)
         self.assertEqual(r.tags, [("XD", x)])
Пример #11
0
 def testNegativeIntegersWrittenToFile(self):
     r = self.build_read()
     x = -2
     r.tags = [("XD", x)]
     with get_temp_context("negative_integers.bam") as fn:
         with pysam.AlignmentFile(fn,
                                  "wb",
                                  referencenames=("chr1",),
                                  referencelengths=(1000,)) as outf:
             outf.write(r)
         with pysam.AlignmentFile(fn) as inf:
             r = next(inf)
         self.assertEqual(r.tags, [("XD", x)])
Пример #12
0
 def testEmptyFileVCFFromPath(self):
     with get_temp_context("tmp_testEmptyFile.vcf") as fn:
         with open(fn, "w"):
             pass
         self.assertRaises(ValueError, pysam.VariantFile, Path(fn))
Пример #13
0
 def testEmptyFileVCFFromPath(self):
     with get_temp_context("tmp_testEmptyFile.vcf") as fn:
         with open(fn, "w"):
             pass
         self.assertRaises(ValueError, pysam.VariantFile,
                           Path(fn))