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")
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")
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)
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)
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)
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)
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")
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")
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)
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)])
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)])
def testEmptyFileVCFFromPath(self): with get_temp_context("tmp_testEmptyFile.vcf") as fn: with open(fn, "w"): pass self.assertRaises(ValueError, pysam.VariantFile, Path(fn))
def testEmptyFileVCFFromPath(self): with get_temp_context("tmp_testEmptyFile.vcf") as fn: with open(fn, "w"): pass self.assertRaises(ValueError, pysam.VariantFile, Path(fn))