class TestIndexedBam(_IndexedAlnFileReaderTests):

    READER_CONSTRUCTOR = IndexedBamReader
    CONSTRUCTOR_ARGS = (data.getAlignedBam(), data.getLambdaFasta())

    def test_empty_bam(self):
        fn = data.getEmptyBam()
        bam = IndexedBamReader(fn)
        assert len(bam) == 0

    def test_alignment_identity(self):
        """
        Check that the values of the 'identity' property are consistent
        between IndexedBamReader (numpy array) and BamAlignment (float)
        """
        fn = data.getAlignedBam()
        with IndexedBamReader(fn) as bam_in:
            i1 = bam_in.identity
            i2 = np.array([rec.identity for rec in bam_in])
            assert (i2 == i1).all()

    def test_alignment_identity_unindexed(self):
        """
        Check that the value of the 'identity' property is the same whether
        or not the .pbi index was used to calculate it.
        """
        fn1 = data.getAlignedBam()
        fn2 = tempfile.NamedTemporaryFile(suffix=".bam").name
        shutil.copyfile(fn1, fn2)
        with IndexedBamReader(fn1) as bam_pbi:
            with BamReader(fn2) as bam_noindex:
                i1 = np.array([rec.identity for rec in bam_pbi])
                i2 = np.array([rec.identity for rec in bam_noindex])
                assert (i2 == i1).all()
class TestIndexedBam(_IndexedAlnFileReaderTests):
    READER_CONSTRUCTOR = IndexedBamReader
    CONSTRUCTOR_ARGS   = (data.getBamAndCmpH5()[0], data.getLambdaFasta())

    def test_empty_bam(self):
        fn = data.getEmptyBam()
        bam = IndexedBamReader(fn)
        EQ(len(bam), 0)
Пример #3
0
class TestBasicBam(_BasicAlnFileReaderTests):
    READER_CONSTRUCTOR = BamReader
    CONSTRUCTOR_ARGS = (data.getBamAndCmpH5()[0], data.getLambdaFasta())

    def testSpecVersion(self):
        EQ("3.0.1", self.f.version)

    def testReadScore(self):
        EQISH(0.904, self.fwdAln.readScore, 3)
class TestBasicBam(_BasicAlnFileReaderTests):

    READER_CONSTRUCTOR = BamReader
    CONSTRUCTOR_ARGS = (data.getAlignedBam(), data.getLambdaFasta())

    def testSpecVersion(self):
        assert "3.0.1" == self.f.version

    def testReadScore(self):
        assert 0.904 == pytest.approx(self.fwdAln.readScore)

    def test_sample_name_default(self):
        assert "UnnamedSample" == self.f.readGroupTable[0].SampleName
 def test_merged_contigset(self):
     fn = tempfile.NamedTemporaryFile(suffix=".contigset.xml").name
     with ContigSet(upstreamData.getLambdaFasta(),
             upstreamData.getFasta()) as cset:
         self.assertEqual(len(list(cset)), 49)
         self.assertEqual(len(cset), 49)
         cset.consolidate()
         cset.write(fn)
         log.debug("Writing to {f}".format(f=fn))
         self.assertEqual(len(list(cset)), 49)
         self.assertEqual(len(cset), 49)
     with ContigSet(fn) as cset:
         self.assertEqual(len(list(cset)), 49)
         self.assertEqual(len(cset), 49)
Пример #6
0
 def test_merged_contigset(self):
     fn = tempfile.NamedTemporaryFile(suffix=".contigset.xml").name
     with ContigSet(upstreamData.getLambdaFasta(),
                    upstreamData.getFasta()) as cset:
         assert len(list(cset)) == 49
         assert len(cset) == 49
         cset.consolidate()
         cset.write(fn)
         log.debug("Writing to {f}".format(f=fn))
         assert len(list(cset)) == 49
         assert len(cset) == 49
     with ContigSet(fn) as cset:
         assert len(list(cset)) == 49
         assert len(cset) == 49
Пример #7
0
 def test_contigset_write(self):
     fasta = upstreamData.getLambdaFasta()
     ds = ContigSet(fasta)
     assert isinstance(ds.resourceReaders()[0], IndexedFastaReader)
     outdir = tempfile.mkdtemp(suffix="dataset-unittest")
     outfn = os.path.join(outdir, 'test.fasta')
     w = FastaWriter(outfn)
     for rec in ds:
         w.writeRecord(rec)
     w.close()
     fas = FastaReader(outfn)
     for rec in fas:
         # make sure a __repr__ didn't slip through:
         assert not rec.sequence.startswith('<')
 def test_contigset_write(self):
     fasta = upstreamData.getLambdaFasta()
     ds = ContigSet(fasta)
     self.assertTrue(isinstance(ds.resourceReaders()[0],
                                IndexedFastaReader))
     outdir = tempfile.mkdtemp(suffix="dataset-unittest")
     outfn = os.path.join(outdir, 'test.fasta')
     w = FastaWriter(outfn)
     for rec in ds:
         w.writeRecord(rec)
     w.close()
     fas = FastaReader(outfn)
     for rec in fas:
         # make sure a __repr__ didn't slip through:
         self.assertFalse(rec.sequence.startswith('<'))
Пример #9
0
    def __init__(self):
        bamFname, cmpFname = D.getBamAndCmpH5()
        lambdaFasta = D.getLambdaFasta()

        self.b = PacBioBamReader(bamFname, lambdaFasta)
        self.c = CmpH5Reader(cmpFname)
        self.bBasic = BamReader(bamFname)

        # Note that sorting orders are not generally the same... BAM
        # sorts + alns before - alns, when there is a tie on tStart;
        # we don't do this in cmp.h5 (we next sort on tEnd).  However
        # in this file there are no ties on tStart.
        self.bAlns = list(self.b)
        self.bFwd = self.bAlns[0]
        self.bRev = self.bAlns[1]

        self.cAlns = list(self.c)
        self.cFwd = self.cAlns[0]
        self.cRev = self.cAlns[1]

        self.cFwdClipped = self.cFwd.clippedTo(10, 60)
        self.bFwdClipped = self.bFwd.clippedTo(10, 60)
        self.cRevClipped = self.cRev.clippedTo(310, 360)
        self.bRevClipped = self.bRev.clippedTo(310, 360)
 def test_contigset_index(self):
     fasta = upstreamData.getLambdaFasta()
     ds = ContigSet(fasta)
     self.assertEqual(ds[0].name, "lambda_NEB3011")
class TestIndexedBam(_IndexedAlnFileReaderTests):
    READER_CONSTRUCTOR = IndexedBamReader
    CONSTRUCTOR_ARGS   = (data.getBamAndCmpH5()[0], data.getLambdaFasta())
class TestBasicBam(_BasicAlnFileReaderTests):
    READER_CONSTRUCTOR = BamReader
    CONSTRUCTOR_ARGS   = (data.getBamAndCmpH5()[0], data.getLambdaFasta())

    def testSpecVersion(self):
        EQ("3.0b7",     self.f.version)
Пример #13
0
 def test_contigset_index(self):
     fasta = upstreamData.getLambdaFasta()
     ds = ContigSet(fasta)
     assert ds[0].name == "lambda_NEB3011"
Пример #14
0
 def test_contigset_index(self):
     fasta = upstreamData.getLambdaFasta()
     ds = ContigSet(fasta)
     self.assertEqual(ds[0].name, "lambda_NEB3011")