def test_productionSubreadsToOriginal(self): # stitch virtual polymerase record subreadsBam = self.data.directory + "/polymerase/production.subreads.bam" scrapsBam = self.data.directory + "/polymerase/production.scraps.bam" vpr = PacBioBam.VirtualPolymeraseReader(subreadsBam, scrapsBam) self.assertTrue(vpr.HasNext()) virtualRecord = vpr.Next() # fetch original polymerase record polyBam = PacBioBam.DataSet(self.data.directory + "/polymerase/production.polymerase.bam") polyQuery = PacBioBam.EntireFileQuery(polyBam) polyIter = polyQuery.begin() polyEnd = polyQuery.end() self.assertTrue(polyIter != polyEnd) polyRecord = polyIter.value() # compare self.assertEqual(polyRecord.FullName(), virtualRecord.FullName()); self.assertEqual(polyRecord.HoleNumber(), virtualRecord.HoleNumber()); self.assertEqual(polyRecord.NumPasses(), virtualRecord.NumPasses()); self.assertEqual(polyRecord.Sequence(), virtualRecord.Sequence()); self.assertEqual(polyRecord.DeletionTag(), virtualRecord.DeletionTag()); self.assertEqual(polyRecord.SubstitutionTag(), virtualRecord.SubstitutionTag()); self.assertEqual(polyRecord.IPD(), virtualRecord.IPDV1Frames()); self.assertEqual(polyRecord.ReadGroup(), virtualRecord.ReadGroup()); self.assertAlmostEqual(float(polyRecord.ReadAccuracy()), float(virtualRecord.ReadAccuracy())); self.assertEqual(polyRecord.Qualities().Fastq(), virtualRecord.Qualities().Fastq()); self.assertEqual(polyRecord.DeletionQV().Fastq(), virtualRecord.DeletionQV().Fastq()); self.assertEqual(polyRecord.InsertionQV().Fastq(), virtualRecord.InsertionQV().Fastq()); self.assertEqual(polyRecord.MergeQV().Fastq(), virtualRecord.MergeQV().Fastq()); self.assertEqual(polyRecord.SubstitutionQV().Fastq(), virtualRecord.SubstitutionQV().Fastq());
def generatedNames(self): try: # open dataset on generated BAM file, read in names dataset = PacBioBam.DataSet(self.generatedBamFn) entireFile = PacBioBam.EntireFileQuery(dataset) names_out = [] for record in PacBioBam.Iterate(entireFile): names_out.append(record.FullName()) return names_out except RuntimeError: self.assertTrue(False) # should not throw
def originalNames(self): # loop over original file, store names, write to generated file try: file = PacBioBam.BamFile(self.ex2BamFn) writer = PacBioBam.BamWriter(self.generatedBamFn, file.Header()) dataset = PacBioBam.DataSet(self.ex2BamFn) entireFile = PacBioBam.EntireFileQuery(dataset) names_in = [] for record in PacBioBam.Iterate(entireFile): names_in.append(record.FullName()) writer.Write(record) return names_in except RuntimeError: self.assertTrue(False) # should not throw
def test_internalHqToOriginal(self): # stitch virtual polymerase record hqRegionsBam = self.data.directory + "/polymerase/internal.hqregions.bam" lqRegionsBam = self.data.directory + "/polymerase/internal.lqregions.bam" vpr = PacBioBam.VirtualPolymeraseReader(hqRegionsBam, lqRegionsBam) self.assertTrue(vpr.HasNext()) virtualRecord = vpr.Next() # fetch original polymerase record polyBam = PacBioBam.DataSet(self.data.directory + "/polymerase/internal.polymerase.bam") polyQuery = PacBioBam.EntireFileQuery(polyBam) polyIter = polyQuery.begin() polyEnd = polyQuery.end() self.assertTrue(polyIter != polyEnd) polyRecord = polyIter.value() # # compare self.compare(polyRecord, virtualRecord)
def test_productionHqToOriginal(self): # stitch virtual polymerase record hqRegionsBam = self.data.directory + "/polymerase/production_hq.hqregion.bam" lqRegionsBam = self.data.directory + "/polymerase/production_hq.scraps.bam" vpr = PacBioBam.VirtualPolymeraseReader(hqRegionsBam, lqRegionsBam) self.assertTrue(vpr.HasNext()) virtualRecord = vpr.Next() # fetch original polymerase record polyBam = PacBioBam.DataSet(self.data.directory + "/polymerase/production.polymerase.bam") polyQuery = PacBioBam.EntireFileQuery(polyBam) polyIter = polyQuery.begin() polyEnd = polyQuery.end() self.assertTrue(polyIter != polyEnd) polyRecord = polyIter.value() # compare self.assertFalse(polyRecord.HasPulseCall()); self.assertFalse(virtualRecord.HasPulseCall()); self.assertEqual(polyRecord.FullName(), virtualRecord.FullName()); self.assertEqual(polyRecord.HoleNumber(), virtualRecord.HoleNumber()); self.assertEqual(polyRecord.NumPasses(), virtualRecord.NumPasses()); self.assertEqual(polyRecord.Sequence(), virtualRecord.Sequence()); self.assertEqual(polyRecord.DeletionTag(), virtualRecord.DeletionTag()); self.assertEqual(polyRecord.SubstitutionTag(), virtualRecord.SubstitutionTag()); self.assertEqual(polyRecord.IPD(), virtualRecord.IPDV1Frames()); self.assertEqual(polyRecord.ReadGroup(), virtualRecord.ReadGroup()); self.assertAlmostEqual(float(polyRecord.ReadAccuracy()), float(virtualRecord.ReadAccuracy())); self.assertEqual(polyRecord.Qualities().Fastq(), virtualRecord.Qualities().Fastq()); self.assertEqual(polyRecord.DeletionQV().Fastq(), virtualRecord.DeletionQV().Fastq()); self.assertEqual(polyRecord.InsertionQV().Fastq(), virtualRecord.InsertionQV().Fastq()); self.assertEqual(polyRecord.MergeQV().Fastq(), virtualRecord.MergeQV().Fastq()); self.assertEqual(polyRecord.SubstitutionQV().Fastq(), virtualRecord.SubstitutionQV().Fastq()); self.assertTrue(polyRecord.HasDeletionQV()); self.assertTrue(polyRecord.HasDeletionTag()); self.assertTrue(polyRecord.HasInsertionQV()); self.assertTrue(polyRecord.HasMergeQV()); self.assertTrue(polyRecord.HasSubstitutionQV()); self.assertTrue(polyRecord.HasSubstitutionTag()); self.assertTrue(polyRecord.HasIPD()); self.assertFalse(polyRecord.HasLabelQV()); self.assertFalse(polyRecord.HasAltLabelQV()); self.assertFalse(polyRecord.HasAltLabelTag()); self.assertFalse(polyRecord.HasPkmean()); self.assertFalse(polyRecord.HasPkmid()); self.assertFalse(polyRecord.HasPulseCall()); self.assertFalse(polyRecord.HasPulseWidth()); self.assertFalse(polyRecord.HasPrePulseFrames()); self.assertFalse(polyRecord.HasPulseCallWidth()); self.assertTrue(virtualRecord.HasDeletionQV()); self.assertTrue(virtualRecord.HasDeletionTag()); self.assertTrue(virtualRecord.HasInsertionQV()); self.assertTrue(virtualRecord.HasMergeQV()); self.assertTrue(virtualRecord.HasSubstitutionQV()); self.assertTrue(virtualRecord.HasSubstitutionTag()); self.assertTrue(virtualRecord.HasIPD()); self.assertFalse(virtualRecord.HasLabelQV()); self.assertFalse(virtualRecord.HasAltLabelQV()); self.assertFalse(virtualRecord.HasAltLabelTag()); self.assertFalse(virtualRecord.HasPkmean()); self.assertFalse(virtualRecord.HasPkmid()); self.assertFalse(virtualRecord.HasPulseCall()); self.assertFalse(virtualRecord.HasPulseWidth()); self.assertFalse(virtualRecord.HasPrePulseFrames()); self.assertFalse(virtualRecord.HasPulseCallWidth());