File: test_pbcore_io_unaligned_bam.py

package info (click to toggle)
python-pbcore 1.6.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 19,168 kB
  • sloc: python: 25,497; xml: 2,846; makefile: 251; sh: 24
file content (75 lines) | stat: -rw-r--r-- 3,002 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from numpy.testing import (assert_array_almost_equal as ASIM,
                           assert_array_equal        as AEQ)
from nose.tools import (nottest,
                        assert_raises,
                        assert_equal as EQ)
from nose import SkipTest

import numpy as np
import bisect
import h5py
from collections import Counter

from pbcore import data
from pbcore.io import BamReader, BaxH5Reader
from pbcore.io.align._BamSupport import UnavailableFeature

from pbcore.sequence import reverseComplement as RC

class TestUnalignedBam(object):

    def __init__(self):
        self.bam = BamReader  (data.getUnalignedBam())
        self.bax = BaxH5Reader(data.getBaxForBam())

        self.baxRead0 = next(self.bax.subreads())
        self.bamRead0 = next(iter(self.bam))

    def testInvalidOperations(self):

        # These kinds of things presently work.  Do we want them to
        # fail?

        # with assert_raises(UnavailableFeature):
        #     self.bamRead0.isForwardStrand
        # with assert_raises(UnavailableFeature):
        #     self.bamRead0.tStart

        # attempts to get read aligned or oriented
        with assert_raises(UnavailableFeature):
            self.bamRead0.read(aligned=True, orientation="native")
        with assert_raises(UnavailableFeature):
            self.bamRead0.read(aligned=False, orientation="genomic")
        with assert_raises(UnavailableFeature):
            self.bamRead0.read()
        with assert_raises(UnavailableFeature):
            self.bamRead0.InsertionQV(aligned=True, orientation="native")
        with assert_raises(UnavailableFeature):
            self.bamRead0.InsertionQV(aligned=False, orientation="genomic")
        with assert_raises(UnavailableFeature):
            self.bamRead0.InsertionQV()

    def testReadAccess(self):
        EQ(self.bamRead0.read(aligned=False, orientation="native"), self.baxRead0.basecalls())

    def testQvAccess(self):
        AEQ(self.bamRead0.SubstitutionQV(aligned=False, orientation="native"), self.baxRead0.SubstitutionQV())
        AEQ(self.bamRead0.InsertionQV(aligned=False, orientation="native"),    self.baxRead0.InsertionQV())
        AEQ(self.bamRead0.DeletionTag(aligned=False, orientation="native"),    self.baxRead0.DeletionTag())

    def testZmwInfo(self):
        # WAT.  Need to make these accessors more uniform.  This is
        # totally crazy.
        EQ(self.bamRead0.HoleNumber, self.baxRead0.holeNumber)
        EQ(self.bamRead0.qStart,     self.baxRead0.readStart)
        EQ(self.bamRead0.qEnd,       self.baxRead0.readEnd)

    def testNames(self):
        EQ(self.bamRead0.queryName, self.baxRead0.readName)

    def testIpd(self):
        """Check that 'Ipd' feature is recognized correctly."""
        pfa = self.bam.baseFeaturesAvailable()
        EQ(pfa, frozenset(['Ipd', 'DeletionTag', 'MergeQV', 'SubstitutionQV',
                           'InsertionQV', 'DeletionQV']))
        ipd = self.bamRead0.IPD(aligned=False, orientation="native")