def test1_encrypt(self): cmn.sam2bam(self.RESOURCE_PATH + 'encrypt/input.sam', self.RESOURCE_PATH + 'encrypt/input.bam') pysam.index(self.RESOURCE_PATH + 'encrypt/input.bam') Vac.text2vac(self.RESOURCE_PATH + 'encrypt/input.vac.txt', self.RESOURCE_PATH + 'encrypt/input.vac') with open(self.RESOURCE_PATH + 'admin', 'r') as key_file, \ open(self.RESOURCE_PATH + 'admin.pub', 'r') as pub_key_file: rsa_key = RSA.importKey(key_file.read(), passphrase=self.KEY_PASS) rsa_pub_key = RSA.importKey(pub_key_file.read()) # creates DIFF with secret self.locker.encrypt( rsa_sign_key=rsa_key, rsa_enc_key=rsa_pub_key, bam_filename=self.RESOURCE_PATH + 'encrypt/input.bam', vac_filename=self.RESOURCE_PATH + 'encrypt/input.vac', out_bam_filename=self.RESOURCE_PATH + 'encrypt/output.mut.bam', out_enc_diff_filename=self.RESOURCE_PATH + 'encrypt/output.diff.enc', mut_p=0) pysam.index(self.RESOURCE_PATH + 'encrypt/output.mut.bam') cmn.bam2sam(self.RESOURCE_PATH + 'encrypt/output.mut.bam', self.RESOURCE_PATH + 'encrypt/output.mut.sam')
def test_mutate_02(self): # EOF VAC case Vac.text2vac(self.RESOURCE_PATH + 'input_02.vac.txt', self.RESOURCE_PATH + 'input_02.vac') bdiff_file = self._mut.mutate( vac_filename=self.RESOURCE_PATH + 'input_02.vac', mut_bam_filename=self.RESOURCE_PATH + 'output_02.bam', secret=self.SECRET, mut_p=0, rng=self._rnd ) self.assertEqual(21, self._mut.stat(BamMutator.STAT_ALIGNMENT_COUNT)) self.assertEqual(13, self._mut.stat(BamMutator.STAT_COVERING_COUNT)) self.assertEqual(7, self._mut.stat(BamMutator.STAT_VAC_COUNT)) self.assertEqual(6, self._mut.stat(BamMutator.STAT_MUT_COUNT)) self.assertEqual(4, self._mut.stat(BamMutator.STAT_DIFF_COUNT)) self.assertEqual(6, self._mut.stat(BamMutator.STAT_ALIGNMENT_MUT_COUNT)) cmn.bam2sam(self.RESOURCE_PATH + 'output_02.bam', self.RESOURCE_PATH + 'output_02.sam') self.assertTrue(filecmp.cmp( self.RESOURCE_PATH + 'desired_02.sam', self.RESOURCE_PATH + 'output_02.sam' )) BdiffIO.to_text_file(bdiff_file, self.RESOURCE_PATH + 'output_02.diff.txt') is_equal = filecmp.cmp(self.RESOURCE_PATH + 'desired_02.diff.txt', self.RESOURCE_PATH + 'output_02.diff.txt') self.assertTrue(is_equal)
def test_unmutate_01(self): # all mapped with BdiffIO.from_text_file(self.RESOURCE_PATH + 'input.diff.txt') as bdiff_file: self.mut.unmutate(bdiff_file=bdiff_file, out_bam_filename=self.RESOURCE_PATH + 'output_01.bam') self.assertEqual(17, self.mut.stat(BamMutator.STAT_ALIGNMENT_COUNT)) self.assertEqual(11, self.mut.stat(BamMutator.STAT_COVERING_COUNT)) self.assertEqual(8, self.mut.stat(BamMutator.STAT_MUT_COUNT)) self.assertEqual(5, self.mut.stat(BamMutator.STAT_DIFF_COUNT)) self.assertEqual(8, self.mut.stat(BamMutator.STAT_ALIGNMENT_MUT_COUNT)) bam2sam(self.RESOURCE_PATH + 'output_01.bam', self.RESOURCE_PATH + 'output_01.sam') is_equal = filecmp.cmp(self.RESOURCE_PATH + 'desired_01.sam', self.RESOURCE_PATH + 'output_01.sam') self.assertEqual(True, is_equal)
def test_unmutate_05(self): # include unmapped with BdiffIO.from_text_file(self.RESOURCE_PATH + 'input.diff.txt') as bdiff_file: self.mut.unmutate(bdiff_file=bdiff_file, out_bam_filename=self.RESOURCE_PATH + 'output_05.bam', include_unmapped=True) self.assertEqual(21, self.mut.stat(BamMutator.STAT_ALIGNMENT_COUNT)) # one synonymous mutation is present self.assertEqual(11, self.mut.stat(BamMutator.STAT_COVERING_COUNT)) self.assertEqual(8, self.mut.stat(BamMutator.STAT_MUT_COUNT)) self.assertEqual(5, self.mut.stat(BamMutator.STAT_DIFF_COUNT)) self.assertEqual(8, self.mut.stat(BamMutator.STAT_ALIGNMENT_MUT_COUNT)) bam2sam(self.RESOURCE_PATH + 'output_05.bam', self.RESOURCE_PATH + 'output_05.sam') self.assertTrue( filecmp.cmp(self.RESOURCE_PATH + 'desired_05.sam', self.RESOURCE_PATH + 'output_05.sam'))
def test_unmutate_07(self): # include unmapped with BdiffIO.from_text_file(self.RESOURCE_PATH + 'input.diff.txt') as bdiff_file: self.mut.unmutate(bdiff_file=bdiff_file, out_bam_filename=self.RESOURCE_PATH + 'output_07.bam', unmapped_only=True) self.assertEqual(4, self.mut.stat(BamMutator.STAT_ALIGNMENT_COUNT)) self.assertEqual(0, self.mut.stat(BamMutator.STAT_COVERING_COUNT)) self.assertEqual(0, self.mut.stat(BamMutator.STAT_MUT_COUNT)) # only the first diff record is read self.assertEqual(1, self.mut.stat(BamMutator.STAT_DIFF_COUNT)) self.assertEqual(0, self.mut.stat(BamMutator.STAT_ALIGNMENT_MUT_COUNT)) bam2sam(self.RESOURCE_PATH + 'output_07.bam', self.RESOURCE_PATH + 'output_07.sam') self.assertTrue( filecmp.cmp(self.RESOURCE_PATH + 'desired_07.sam', self.RESOURCE_PATH + 'output_07.sam'))
def test_mask(self): # EOF BAM case Vac.text2vac(self.RESOURCE_PATH + 'input.vac.txt', self.RESOURCE_PATH + 'input.vac') bdiff_file = self._mut.mutate( vac_filename=self.RESOURCE_PATH + 'input.vac', mut_bam_filename=self.RESOURCE_PATH + 'output.bam', secret=self.SECRET, mut_p=0, rng=self._rng) cmn.bam2sam(self.RESOURCE_PATH + 'output.bam', self.RESOURCE_PATH + 'output.sam') BdiffIO.to_text_file(bdiff_file, self.RESOURCE_PATH + 'output.diff.txt') self.assertTrue( filecmp.cmp(self.RESOURCE_PATH + 'desired.sam', self.RESOURCE_PATH + 'output.sam')) self.assertTrue( filecmp.cmp(self.RESOURCE_PATH + 'desired.diff.txt', self.RESOURCE_PATH + 'output.diff.txt'))
def test_unmutate_06(self): # include unmapped with range with BdiffIO.from_text_file(self.RESOURCE_PATH + 'input.diff.txt') as bdiff_file: self.mut.unmutate( bdiff_file=bdiff_file, out_bam_filename=self.RESOURCE_PATH + 'output_06.bam', start_ref_name='chr2', start_ref_pos=1015, # inclusive end_ref_name='chr2', end_ref_pos=1028, # non-inclusive include_unmapped=True) self.assertEqual(13, self.mut.stat(BamMutator.STAT_ALIGNMENT_COUNT)) self.assertEqual(3, self.mut.stat(BamMutator.STAT_COVERING_COUNT)) self.assertEqual(2, self.mut.stat(BamMutator.STAT_MUT_COUNT)) self.assertEqual(1, self.mut.stat(BamMutator.STAT_DIFF_COUNT)) self.assertEqual(2, self.mut.stat(BamMutator.STAT_ALIGNMENT_MUT_COUNT)) bam2sam(self.RESOURCE_PATH + 'output_06.bam', self.RESOURCE_PATH + 'output_06.sam') self.assertTrue( filecmp.cmp(self.RESOURCE_PATH + 'desired_06.sam', self.RESOURCE_PATH + 'output_06.sam'))