This file is indexed.

/usr/include/pbbam/PbiLookupData.h is in libpbbam-dev 0.7.4+ds-1build2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
// Copyright (c) 2014-2015, Pacific Biosciences of California, Inc.
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted (subject to the limitations in the
// disclaimer below) provided that the following conditions are met:
//
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//
//  * Redistributions in binary form must reproduce the above
//    copyright notice, this list of conditions and the following
//    disclaimer in the documentation and/or other materials provided
//    with the distribution.
//
//  * Neither the name of Pacific Biosciences nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
// GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY PACIFIC
// BIOSCIENCES AND ITS CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL PACIFIC BIOSCIENCES OR ITS
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
// SUCH DAMAGE.
//
// File Description
/// \file PbiLookupData.h
/// \brief Defines the classes used for PBI data lookup.
//
// Author: Derek Barnett

#ifndef PBILOOKUPDATA_H
#define PBILOOKUPDATA_H

#include "pbbam/Config.h"
#include "pbbam/Compare.h"
#include "pbbam/PbiBasicTypes.h"
#include <deque>
#include <map>
#include <unordered_map>
#include <vector>

namespace PacBio {
namespace BAM {

class PbiRawBarcodeData;
class PbiRawBasicData;
class PbiRawMappedData;
class PbiRawReferenceData;

/// \brief The OrderedLookup class provides a quick lookup structure for
///        PBI index data, where key values are sorted.
///
/// The main, underlying lookup structure is essentailly a std::map, where the
/// key is some value (e.g. readAccuracy) and the value is the list of indices
/// (i-th record) in the %BAM file.
///
/// This lookup class is one of the main building blocks for the PBI index
/// lookup components.
///
/// \param T    type of key stored (Accuracy for readAccuracy, int32_t for ZMW,
///             etc.)
///
template<typename T>
class OrderedLookup
{
public:
    typedef T                                       key_type;
    typedef IndexList                               value_type;
    typedef std::map<key_type, value_type>          container_type;
    typedef typename container_type::iterator       iterator;
    typedef typename container_type::const_iterator const_iterator;

public:
    /// \name Constructors & Related Methods
    /// \{

    /// \brief Creates an empty OrderedLookup structure.
    ///
    OrderedLookup(void);

    /// \brief Creates an OrderedLookup struture, from another's underlying
    ///        lookup container.
    ///
    /// \param[in] data     lookup data container
    ///
    OrderedLookup(const container_type& data);

    /// \brief Creates an OrderedLookup struture, from another's underlying
    ///        lookup container.
    ///
    /// \param[in] data     lookup data container
    ///
    OrderedLookup(container_type&& data);

    /// \brief Creates an OrderedLookup struture, from raw data.
    ///
    /// \param[in] rawData  raw data values, where i is the index into the %BAM
    ///                     file, and rawData[i] is the key value
    ///
    OrderedLookup(const std::vector<T>& rawData);

    /// \brief Creates an OrderedLookup struture, from raw data.
    ///
    /// \param[in] rawData  raw data values, where i is the index into the %BAM
    ///                     file, and rawData[i] is the key value
    ///
    OrderedLookup(std::vector<T>&& rawData);

    /// \}

public:
    /// \name Operators
    /// \{

    /// \returns true if this lookup is same as \p other
    bool operator==(const OrderedLookup<T>& other) const;

    /// \returns true if this lookup is not the same as \p other
    bool operator!=(const OrderedLookup<T>& other) const;

    /// \}

public:
    /// \name STL-Compatibility Methods
    /// \{

    /// \returns an iterator to the first element in the underlying container
    iterator begin(void);

    /// \returns a const iterator to the first element in the underlying
    ///          container
    const_iterator begin(void) const;

    /// \returns a const iterator to the first element in the underlying
    ///
    const_iterator cbegin(void) const;

    /// \returns an iterator after the last element in the underlying container
    iterator end(void);

    /// \returns a const iterator after the last element in the underlying
    ///          container
    const_iterator end(void) const;

    /// \returns a const iterator after the last element in the underlying
    ///          container
    const_iterator cend(void) const;

    /// \returns true if underlying container is empty
    bool empty(void) const;

    /// \returns number of keys in the container
    size_t size(void) const;

    /// \}

public:
    /// \name Lookup Data
    /// \{

    /// \brief Performs a lookup into the underlying data.
    ///
    /// \param[in] key      key value to lookup
    /// \param[in] compare  compare type
    ///
    /// \returns sorted list of unique indices that satisfy the lookup key &
    ///          compare type
    ///
    IndexList LookupIndices(const key_type& key,
                            const Compare::Type& compare) const;

    /// \brief Converts the lookup structure back into its raw data.
    ///
    /// \returns raw data values, where i is the index into the %BAM file, and
    ///          rawData[i] is the key value
    ///
    std::vector<T> Unpack(void) const;

    /// \}

private:
    IndexList LookupInclusiveRange(const const_iterator& begin,
                                   const const_iterator& end) const;

    IndexList LookupExclusiveRange(const const_iterator& begin,
                                   const const_iterator& end,
                                   const key_type& key) const;

private:
    container_type data_;
};

/// \brief The UnorderedLookup class provides a quick lookup structure for
///        PBI index data, where key values are not sorted.
///
/// The main, underlying lookup structure is essentailly a std::unordered_map,
/// where the key is some value (e.g. read group ID) and the value is the list
/// of indices (i-th record) in the %BAM file.
///
/// This lookup class is one of the main building blocks for the PBI index
/// lookup components.
///
/// \param T    type of key stored (Accuracy for readAccuracy, int32_t for ZMW,
///             etc.)
///
template<typename T>
class UnorderedLookup
{
public:
    typedef T                                        key_type;
    typedef IndexList                                value_type;
    typedef std::unordered_map<key_type, value_type> container_type;
    typedef typename container_type::iterator        iterator;
    typedef typename container_type::const_iterator  const_iterator;

public:
    /// \name Constructors & Related Methods
    /// \{

    /// \brief Creates an empty UnorderedLookup structure.
    ///
    UnorderedLookup(void);

    /// \brief Creates an UnorderedLookup struture, from another's underlying
    ///        lookup container.
    ///
    /// \param[in] data     lookup data container
    ///
    UnorderedLookup(const container_type& data);

    /// \brief Creates an UnorderedLookup struture, from another's underlying
    ///        lookup container.
    ///
    /// \param[in] data     lookup data container
    ///
    UnorderedLookup(container_type&& data);

    /// \brief Creates an UnorderedLookup struture, from raw data.
    ///
    /// \param[in] rawData  raw data values, where i is the index into the %BAM
    ///                     file, and rawData[i] is the key value
    ///
    UnorderedLookup(const std::vector<T>& rawData);

    /// \brief Creates an UnorderedLookup struture, from raw data.
    ///
    /// \param[in] rawData  raw data values, where i is the index into the %BAM
    ///                     file, and rawData[i] is the key value
    ///
    UnorderedLookup(std::vector<T>&& rawData);

    /// \}

public:
    /// \name Operators
    /// \{

    /// \returns true if this lookup is same as \p other
    bool operator==(const UnorderedLookup<T>& other) const;

    /// \returns true if this lookup is not the same as \p other
    bool operator!=(const UnorderedLookup<T>& other) const;

    /// \}

public:
    /// \name STL-Compatibility Methods
    /// \{

    /// \returns an iterator to the first element in the underlying container
    iterator begin(void);

    /// \returns a const iterator to the first element in the underlying
    ///          container
    const_iterator begin(void) const;

    /// \returns a const iterator to the first element in the underlying
    ///
    const_iterator cbegin(void) const;

    /// \returns an iterator after the last element in the underlying container
    iterator end(void);

    /// \returns a const iterator after the last element in the underlying
    ///          container
    const_iterator end(void) const;

    /// \returns a const iterator after the last element in the underlying
    ///          container
    const_iterator cend(void) const;

    /// \returns true if underlying container is empty
    bool empty(void) const;

    /// \returns number of keys in the container
    size_t size(void) const;

    /// \}

public:
    /// \name Lookup Data
    /// \{

    /// \brief Performs a lookup into the underlying data.
    ///
    /// \param[in] key      key value to lookup
    /// \param[in] compare  compare type
    ///
    /// \returns sorted list of unique indices that satisfy the lookup key &
    ///          compare type
    ///
    IndexList LookupIndices(const key_type& key,
                            const Compare::Type& compare) const;

    /// \brief Converts the lookup structure back into its raw data.
    ///
    /// \returns raw data values, where i is the index into the %BAM file, and
    ///          rawData[i] is the key value
    ///
    std::vector<T> Unpack(void) const;

    /// \}

private:
    template<typename Compare>
    IndexList LookupHelper(const key_type& key,
                           const Compare& cmp) const;

private:
    container_type data_;
};

/// \brief The BasicLookupData class provides quick lookup access to the
///        "BasicData" section of the PBI index.
///
class PBBAM_EXPORT BasicLookupData
{
public:
    /// \brief This enum describes the component fields of the BasicData
    ///        section.
    enum Field
    {
        RG_ID
      , Q_START
      , Q_END
      , ZMW
      , READ_QUALITY
      , CONTEXT_FLAG
      , VIRTUAL_OFFSET
    };

public:
    /// \name Constructors & Related Methods
    /// \{

    /// \brief Creates an empty lookup data object.
    BasicLookupData(void);

    /// \brief Creates a lookup data object from the corresponding raw data.
    ///
    /// \param[in] rawData  raw data loaded from a PBI file
    ///
    BasicLookupData(const PbiRawBasicData& rawData);

    /// \}

public:
    /// \name Lookup Data Methods
    /// \{

    /// \brief Adds \b virtual file offset data to the index lookup result
    ///        blocks.
    ///
    /// A PBI lookup will result in a number of index lists, depending on the
    /// complexity of the PbiFilter involved. These index lists are then merged
    /// down into blocks of contiguous values, where each block describes a
    /// particular record index and the number of subsequent, contiguous reads
    /// that immediately follow it. In this manner, we need only perform seeks
    /// to the first record of each block.
    ///
    /// This method takes such blocks and annotates them with the corresponding
    /// \b virtual file offset. Subsequent %BAM readers can use this information
    /// to control file seeks.
    ///
    /// \param[in,out] blocks
    ///
    /// \throws std::out_of_range if a block has an invalid index value
    ///
    void ApplyOffsets(IndexResultBlocks& blocks) const;

    /// \brief This method dispatches a single-value lookup query to the proper
    ///         data member.
    ///
    /// Client code, such as custom filters, should use this when possible, only
    /// touching the raw fields for more complex operations (e.g. when unpacking
    /// is necessary).
    ///
    /// \param[in] field            section field to lookup
    /// \param[in] value            value to lookup
    /// \param[in] compareType      compare type
    ///
    /// \returns sorted list of unique indices that satisfy the lookup
    ///
    template<typename T>
    IndexList Indices(const BasicLookupData::Field& field,
                      const T& value,
                      const Compare::Type& compareType = Compare::EQUAL) const;

    /// \brief This method dispatches a multi-value lookup query to the proper
    ///        data member.
    ///
    /// Client code, such as custom filters, should use this when possible, only
    /// touching the raw fields for more complex operations (e.g. when unpacking
    /// is necessary).
    ///
    /// \note There is no compare type parameter here, it is always
    ///       Compare::EQUAL. Results will correspond to an exact match on at
    ///       least one value in the list.
    ///
    /// \param[in] field        section field to lookup
    /// \param[in] values       values to lookup
    ///
    /// \returns sorted list of unique indices that satisfy the lookup
    ///
    template<typename T>
    IndexList IndicesMulti(const BasicLookupData::Field& field,
                           const std::vector<T>& values) const;

    /// \returns the \b virtual file offsets for all records
    ///
    const std::vector<int64_t>& VirtualFileOffsets(void) const;

    /// \}

public:
    /// \brief Lookup Data Members
    /// \{

    // map ordering doesn't make sense, optimize for direct lookup
    UnorderedLookup<int32_t> rgId_;

    // numeric comparisons make sense, keep key ordering preserved
    OrderedLookup<int32_t>  qStart_;
    OrderedLookup<int32_t>  qEnd_;
    OrderedLookup<int32_t>  holeNumber_;
    OrderedLookup<float>    readQual_;

    // see if this works, or if can use unordered, 'direct' query
    OrderedLookup<uint8_t> ctxtFlag_;

    // offsets
    std::vector<int64_t> fileOffset_;

    /// \}
};

/// \brief The MappedLookupData class provides quick lookup access to the
///        "MappedData" section of the PBI index.
///
class PBBAM_EXPORT MappedLookupData
{
public:
    /// \brief This enum describes the component fields of the MappedData
    ///        section.
    enum Field
    {
        T_ID
      , T_START
      , T_END
      , A_START
      , A_END
      , N_M
      , N_MM
      , N_INS
      , N_DEL
      , MAP_QUALITY
      , STRAND
    };

public:
    /// \name Constructors & Related Methods
    /// \{

    /// \brief Creates an empty lookup data object.
    MappedLookupData(void);

    /// \brief Creates a lookup data object from the corresponding raw data.
    ///
    /// \param[in] rawData  raw data loaded from a PBI file
    ///
    MappedLookupData(const PbiRawMappedData& rawData);

    /// \}

public:
    /// \name Lookup Data Methods
    /// \{

    /// \brief This method dispatches a single-value lookup query to the proper
    ///         data member.
    ///
    /// Client code, such as custom filters, should use this when possible, only
    /// touching the raw fields for more complex operations (e.g. when unpacking
    /// is necessary).
    ///
    /// \param[in] field            section field to lookup
    /// \param[in] value            value to lookup
    /// \param[in] compareType      compare type
    ///
    /// \returns sorted list of unique indices that satisfy the lookup
    ///
    template<typename T>
    IndexList Indices(const MappedLookupData::Field& field,
                      const T& value,
                      const Compare::Type& compareType = Compare::EQUAL) const;

    /// \brief This method dispatches a multi-value lookup query to the proper
    ///        data member.
    ///
    /// Client code, such as custom filters, should use this when possible, only
    /// touching the raw fields for more complex operations (e.g. when unpacking
    /// is necessary).
    ///
    /// \note There is no compare type parameter here, it is always
    ///       Compare::EQUAL. Results will correspond to an exact match on at
    ///       least one value in the list.
    ///
    /// \param[in] field        section field to lookup
    /// \param[in] values       values to lookup
    ///
    /// \returns sorted list of unique indices that satisfy the lookup
    ///
    template<typename T>
    IndexList IndicesMulti(const MappedLookupData::Field& field,
                           const std::vector<T>& values) const;

    /// \}

public:
    /// \name Lookup Data Members
    /// \{

    // numeric comparisons make sense, keep key ordering preserved
    OrderedLookup<int32_t>  tId_;
    OrderedLookup<uint32_t> tStart_;
    OrderedLookup<uint32_t> tEnd_;
    OrderedLookup<uint32_t> aStart_;
    OrderedLookup<uint32_t> aEnd_;
    OrderedLookup<uint32_t> nM_;
    OrderedLookup<uint32_t> nMM_;
    OrderedLookup<uint8_t>  mapQV_;

    // generated values, not stored directly in PBI file
    OrderedLookup<uint32_t> nIns_;
    OrderedLookup<uint32_t> nDel_;

    // no need for map overhead, just store direct indices
    IndexList reverseStrand_;
    IndexList forwardStrand_;

    /// \}
};

/// \brief The ReferenceLookupData class provides quick lookup access to the
///        "CoordinateSortedData" section of the PBI index.
///
class PBBAM_EXPORT ReferenceLookupData
{
public:
    /// \name Constructors & Related Methods
    /// \{

    /// \brief Creates an empty lookup data object.
    ///
    ReferenceLookupData(void);

    /// \brief Creates a lookup data object from the corresponding raw data.
    ///
    /// \param[in] rawData  raw data loaded from a PBI file
    ///
    ReferenceLookupData(const PbiRawReferenceData& rawData);

    /// \}

public:
    /// \name Lookup Data Methods
    /// \{

    /// \brief Retrieves the index range for all records that map to a
    ///        particular reference.
    ///
    /// Client code, such as custom filters, should use this when possible, only
    /// touching the raw fields for more complex operations (e.g. when unpacking
    /// is necessary).
    ///
    /// \param[in] tId      reference ID to lookup
    ///
    /// \returns resulting index range [begin, end). If \p tId is unknown,
    ///          will return IndexRange(-1,-1) .
    ///
    IndexRange Indices(const int32_t tId) const;

    /// \}

public:
    /// \name Lookup Data Members
    /// \{

    // references_[tId] = [begin, end) indices
    std::unordered_map<int32_t, IndexRange> references_;

    /// \}
};

/// \brief The BarcodeLookupData class provides quick lookup access to the
///        "BarcodeData" section of the PBI index.
///
class PBBAM_EXPORT BarcodeLookupData
{
public:
    /// \brief This enum describes the component fields of the BarcodeData
    ///        section.
    enum Field
    {
        BC_FORWARD
      , BC_REVERSE
      , BC_QUALITY
    };

public:
    /// \name Constructors & Related Methods
    /// \{

    /// \brief Creates an empty lookup data object.
    ///
    BarcodeLookupData(void);

    /// \brief Creates a lookup data object from the corresponding raw data.
    ///
    /// \param[in] rawData  raw data loaded from a PBI file
    ///
    BarcodeLookupData(const PbiRawBarcodeData& rawData);

    /// \}

public:
    /// \name Lookup Data Methods
    /// \{

    /// \brief This method dispatches a single-value lookup query to the proper
    ///         data member.
    ///
    /// Client code, such as custom filters, should use this when possible, only
    /// touching the raw fields for more complex operations (e.g. when unpacking
    /// is necessary).
    ///
    /// \param[in] field            section field to lookup
    /// \param[in] value            value to lookup
    /// \param[in] compareType      compare type
    ///
    /// \returns sorted list of unique indices that satisfy the lookup
    ///
    template<typename T>
    IndexList Indices(const BarcodeLookupData::Field& field,
                      const T& value,
                      const Compare::Type& compareType = Compare::EQUAL) const;

    /// \brief This method dispatches a multi-value lookup query to the proper
    ///        data member.
    ///
    /// Client code, such as custom filters, should use this when possible, only
    /// touching the raw fields for more complex operations (e.g. when unpacking
    /// is necessary).
    ///
    /// \note There is no compare type parameter here, it is always
    ///       Compare::EQUAL. Results will correspond to an exact match on at
    ///       least one value in the list.
    ///
    /// \param[in] field        section field to lookup
    /// \param[in] values       values to lookup
    ///
    /// \returns sorted list of unique indices that satisfy the lookup
    ///
    template<typename T>
    IndexList IndicesMulti(const BarcodeLookupData::Field& field,
                           const std::vector<T>& values) const;

    /// \}

public:
    /// \name Lookup Data Members
    /// \{

    // numeric comparisons make sense, keep key ordering preserved
    OrderedLookup<int16_t> bcForward_;
    OrderedLookup<int16_t> bcReverse_;
    OrderedLookup<int8_t>  bcQual_;

    /// \}
};

} // namespace BAM
} // namespace PacBio

#include "internal/PbiLookupData.inl"

#endif // PBILOOKUPDATA_H