This file is indexed.

/usr/include/blasr/datastructures/alignment/AlignmentCandidate.hpp is in libblasr-dev 0~20151014+gitbe5d1bf-2.

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
#ifndef _ALIGNMENT_ALIGNMENT_CANDIDATE_HPP_
#define _ALIGNMENT_ALIGNMENT_CANDIDATE_HPP_

#include "Alignment.hpp"
#include "DNASequence.hpp"
#include "FASTQSequence.hpp"

template<typename T_TSequence=FASTASequence, typename T_QSequence=FASTASequence>
class AlignmentCandidate : public blasr::Alignment {

private:
    void ReassignSequence(DNASequence &curSeq, bool curIsSubstring,  DNASequence &newSeq) {
        //
        // If this sequence is in control of itself (it is not a substring
        // of anoter sequence), it should be freed here to avoid memory
        // leaks.
        //
        if (curIsSubstring == false) {
            curSeq.Free();
        }
        curSeq.seq = newSeq.seq;
        curSeq.length = newSeq.length;
    }

    void ReassignSequence(FASTQSequence &curSeq, bool curIsSubstring, FASTQSequence &newSeq) {
        //
        // Free the current sequence with the same rules as above.
        //
        if (curIsSubstring == false) {
            curSeq.Free();
        }
        curSeq.ReferenceSubstring(newSeq, 0, newSeq.length);
    }
    
    // TryReadingQVs is a helper function for ReadOptionalQVs. It checks if the
    // qvs that are supposed to be copied to a member of AlignmentCandidate are
    // in fact empty. If so, then don't substr or copy anything
    void TryReadingQVs(const std::string qvs, DNALength start, DNALength length,
                       std::string *memberQVs) {
        if (qvs.size() == 0) {
            memberQVs->clear();
        } else {
            *memberQVs = qvs.substr(start, length);
        }
    }



public:
    T_TSequence tAlignedSeq;
    T_QSequence qAlignedSeq;
    std::string insertionQV, deletionQV, mergeQV, substitutionQV, deletionTag, substitutionTag;
    std::vector<std::string> optionalQVNames;
    DNALength   tAlignedSeqPos, qAlignedSeqPos;
    DNALength   tAlignedSeqLength, qAlignedSeqLength;
    float       pvalVariance, weightVariance, pvalNStdDev, weightNStdDev;
    int         numSignificantClusters;
    int readIndex;
    //
    // [q/t]IsSubstring refers to whether or not the text or query
    // sequences are pointers into longer sequences.  If they are,
    // then reassigning the target/query sequences just means
    // reassigning the seq and length values.  If not, they occupy their
    // own space, and should have the same lifetime as the alignment
    // candidate object.
    //

    bool tIsSubstring, qIsSubstring;
    std::string tTitle, qTitle;
    float clusterScore, clusterWeight;
    //
    // For indexing into sequence index databases, tIndex stores which
    // target this match is from.
    //
    int tIndex;

    AlignmentCandidate&operator=(const AlignmentCandidate &rhs)  {
        tAlignedSeq         = rhs.tAlignedSeq;
        qAlignedSeq         = rhs.qAlignedSeq;
        tAlignedSeqPos      = rhs.tAlignedSeqPos;
        qAlignedSeqPos      = rhs.qAlignedSeqPos;
        tAlignedSeqLength   = rhs.tAlignedSeqLength;
        qAlignedSeqLength   = rhs.qAlignedSeqLength;
        readIndex           = rhs.readIndex;
        tIndex              = rhs.tIndex;
        mapQV               = rhs.mapQV;
        clusterScore        = rhs.clusterScore;
        clusterWeight       = rhs.clusterWeight;
        *((Alignment*)this) = ((Alignment&)rhs);

        pvalVariance = rhs.pvalVariance;
        pvalNStdDev  = rhs.pvalNStdDev;
        weightVariance=rhs.weightVariance;
        weightNStdDev= rhs.weightNStdDev;

        insertionQV = rhs.insertionQV;
        deletionQV = rhs.deletionQV;
        substitutionQV = rhs.substitutionQV;
        mergeQV = rhs.mergeQV;
        substitutionTag = rhs.substitutionTag;
        deletionTag = rhs.deletionTag;

        return *this;
    }

    AlignmentCandidate() {
        /*
         * The default configuration of an alignment candidate is to have
         * the t and q sequences be substrings.  This means that the
         * position of the substrings starts at 0 (no offset into a longer
         * string).
         */
        tIsSubstring      = true;
        qIsSubstring      = true;
        tTitle            = "";
        qTitle            = "";
        tAlignedSeqPos    = 0;
        qAlignedSeqPos    = 0;
        tAlignedSeqLength = 0;
        qAlignedSeqLength = 0;
        tIndex            = 0;
        readIndex         = 0;
        mapQV             = 50;
        clusterScore      = 0;
        clusterWeight     = 0;
        numSignificantClusters = 0;
        pvalVariance = pvalNStdDev = 0;
        weightVariance = weightNStdDev = 0;
    }

    void Print(std::ostream & out = std::cout) {
        out << "An AlignmentCandidate object (mapQV " 
            << mapQV << ", clusterscore " << clusterScore 
            << ", tTitle: " << tTitle << ", qTitle: " << qTitle 
            << ")." << std::endl;
        out << "  query: " << qTitle << ", "  
            << "qName: " << qName << ","
            << "qStrand: " << qStrand << ", " 
            << "qPos: " << qPos << ", "
            << "qLen: " << qLength << ", "
            << "qAlignLength: " << qAlignLength << ", "
            << "qAlignedSeqPos:" << qAlignedSeqPos << ", "
            << "qAlignedSeqLen:" << qAlignedSeqLength << std::endl
            << "  target: " << tTitle << ", "  
            << "tName: " << tName << ","
            << "tStrand: " << tStrand << ", " 
            << "tPos: " << tPos << ", "
            << "tLen: " << tLength << ", "
            << "tAlignLength: " << tAlignLength << ", "
            << "tAlignedSeqPos:" << tAlignedSeqPos << ", " 
            << "tAlignedSeqLen:" << tAlignedSeqLength << std::endl;
        tAlignedSeq.Print(out);
    }

    AlignmentCandidate(const AlignmentCandidate &rhs) {
        *this = rhs;
    }

    DNALength GenomicTBegin() {
        return tAlignedSeqPos + tPos;
    }

    DNALength GenomicTEnd() {
        return tAlignedSeqPos + tPos + TEnd();
    }

    void GetQIntervalOnForwardStrand(int &qStart, int &qEnd) {
        GetQInterval(qStart, qEnd, true);
    }

    void GetQInterval(int &qStart, int &qEnd, bool useForwardStrand=false) {
        qStart = qEnd = 0;
        if (blocks.size() == 0) { return; }
        qStart = blocks[0].qPos + qAlignedSeqPos;
        qEnd   = QEnd() + qAlignedSeqPos;
        if (useForwardStrand and qStrand == 1) {
            int forQEnd, forQStart;
            forQStart = qLength - qEnd;
            forQEnd   = qLength - qStart;
            qStart    = forQStart;
            qEnd      = forQEnd;
        }
    }

    DNALength QAlignEnd() {
        return QEnd() + qPos + qAlignedSeqPos;
    }

    DNALength QAlignStart() {
        return qPos + qAlignedSeqPos;
    }

    DNALength TAlignStart() {
        return tPos + tAlignedSeqPos;
    }

    // Synonyms for T/QStart 
    DNALength GetQBasesToStart() {
        return qPos + qAlignedSeqPos;
    }
    DNALength GetTBasesToStart() {
        return tPos + tAlignedSeqPos;
    }
    
    // ReadOptionalQVs populates the optional QV attributes of
    // AlignmentCandidate with values read from a vector.  
    void ReadOptionalQVs(const std::vector<std::string>& optionalQVs,
                         DNALength start, DNALength length) {
      TryReadingQVs(optionalQVs[0], start, length, &insertionQV);
      TryReadingQVs(optionalQVs[1], start, length, &deletionQV);
      TryReadingQVs(optionalQVs[2], start, length, &substitutionQV);
      TryReadingQVs(optionalQVs[3], start, length, &mergeQV);
      TryReadingQVs(optionalQVs[4], start, length, &substitutionTag);
      TryReadingQVs(optionalQVs[5], start, length, &deletionTag);
    } 
    
    // CopyQVs fills a vector with optional QV attributes.
    void CopyQVs(std::vector<std::string> *optionalQVs) {  
      optionalQVNames.clear();
      optionalQVs->clear();
      optionalQVs->push_back(insertionQV);
      optionalQVNames.push_back("InsertionQV");
      optionalQVs->push_back(deletionQV);
      optionalQVNames.push_back("DeletionQV");
      optionalQVs->push_back(substitutionQV);
      optionalQVNames.push_back("SubstitutionQV");
      optionalQVs->push_back(mergeQV);
      optionalQVNames.push_back("MergeQV");
      optionalQVs->push_back(substitutionTag);
      optionalQVNames.push_back("SubstitutionTag");
      optionalQVs->push_back(deletionTag);
      optionalQVNames.push_back("DeletionTag");
    }

    void AppendAlignment(AlignmentCandidate &next) {

        //
        // If the next alignment is empty, just return now.
        //
        if (next.blocks.size() == 0) {
            return;
        }
        //
        // It is necessary to determine how much after the first alignment
        // the second alignment starts, in order to 
        assert(GetTBasesToStart() <= next.GetTBasesToStart());
        assert(GetQBasesToStart() <= next.GetQBasesToStart());
        assert(GetTBasesToStart() + TEnd() <= next.GetTBasesToStart());
        assert(GetQBasesToStart() + QEnd() <= next.GetQBasesToStart());

        //
        // qOffset is the offset of the frame of reference for the 'next'
        // alignment relative to this one.  If the frame of reference is
        // the same (qOffset == 0 and tOffset == 0), then the alignment
        // blocks may simply be appended.  If it is non zero, then the
        // location in the query or target where the alignment has started
        // is different, and the values of qPos or tPos need to be
        // adjusted accordingly.

        DNALength qOffset = next.qPos + next.qAlignedSeqPos - qPos - qAlignedSeqPos;
        DNALength tOffset = next.tPos + next.tAlignedSeqPos - tPos - tAlignedSeqPos;
        DNALength origQEnd = QEnd();
        DNALength origTEnd = TEnd();

        /*    DNALength tGap = next.GetTBasesToStart() + next.blocks[0].tPos - (GetTBasesToStart() + TEnd());
              DNALength qGap = next.GetQBasesToStart() + next.blocks[0].qPos - (GetQBasesToStart() + QEnd());
              */
        DNALength tGap = next.GetTBasesToStart() - (GetTBasesToStart() + TEnd());
        DNALength qGap = next.GetQBasesToStart() - (GetQBasesToStart() + QEnd());

        //

        if ( gaps.size() > 0 and next.gaps.size() > 0 ) {

            //
            // Determine the gap between the two alignments in order to assign
            // the gap between them.
            DNALength commonGap = 0;
            DNALength gapDiff = 0;

            if (tGap >= qGap) {
                gapDiff   = tGap - qGap;
                commonGap = tGap - gapDiff;
                tGap      = gapDiff;
                qGap      = 0;
            }
            else {
                gapDiff   = qGap - tGap;
                commonGap = qGap - gapDiff;
                qGap      = gapDiff;
                tGap      = 0;
            }

            if (commonGap > 0) {
                // There is some portion of sequence between the two alignments
                // that is a common gap. Add a block representing this.

                blasr::Block block;
                block.qPos = origQEnd;
                block.tPos = origTEnd;
                block.length = commonGap;
                blocks.push_back(block);
                blasr::GapList emptyGap;
                gaps.push_back(emptyGap);
            }

            blasr::GapList endGapList;
            //
            // When gapDiff == 0, an empty list is appended.
            //
            if (next.gaps.size() > 0) {
                //
                // The first gap in the next alignment is already handled by
                // the gap created with the endGap.  So get rid of the first
                // gaps. 
                //        next.gaps[0].resize(0);
                static const bool mergeFirstGap = true;
                AppendAlignmentGaps(next);
            }
        }

        //
        // Finally append all the blocks.
        //
        AppendAlignmentBlocks(next, qOffset, tOffset);

    }

    void FreeSubsequences() {
        if (tIsSubstring == false) {
            tAlignedSeq.Free();
        }
        if (qIsSubstring == false) {
            qAlignedSeq.Free();
        }
    }

    void ReassignTSequence(DNASequence &newSeq) {
        ReassignSequence(tAlignedSeq, tIsSubstring, newSeq);
    }

    template<typename T_Sequence>
        void ReassignQSequence(T_Sequence &newSeq) {
            ReassignSequence(qAlignedSeq, qIsSubstring, newSeq);
        }

    ~AlignmentCandidate() {
        qAlignedSeq.Free();
        tAlignedSeq.Free();
    }
};
//
// Define a default alignment candidate for aligning quality-sequence
// to a reference without quality.
//
typedef AlignmentCandidate<DNASequence,FASTQSequence> T_AlignmentCandidate;

class SortAlignmentPointersByScore {
public:
    /// Sort AlignmentCandidate pointer by score, then by target position.
    int operator()(T_AlignmentCandidate *lhs, T_AlignmentCandidate* rhs);
};

class SortAlignmentPointersByMapQV {
public:
    /// Sort AlignmentCandidate pointer by mapQV, then by target position.
    int operator()(T_AlignmentCandidate *lhs, T_AlignmentCandidate* rhs);
};

#endif // _ALIGNMENT_ALIGNMENT_CANDIDATE_HPP_