File: AlignmentResult.h

package info (click to toggle)
snap-aligner 2.0.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,652 kB
  • sloc: cpp: 41,051; ansic: 5,239; python: 227; makefile: 85; sh: 28
file content (163 lines) | stat: -rw-r--r-- 6,686 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
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
/*++

Module Name:

    AlignmentResult.h

Abstract:

    Header for SNAP genome alignment results

Authors:

    Bill Bolosky, May, 2014

Environment:

    User mode service.

    This class is NOT thread safe.  It's the caller's responsibility to ensure that
    at most one thread uses an instance at any time.

Revision History:

   Pulled out of other places in SNAP

--*/

#pragma once
#include "Genome.h"
#include "directions.h"

class Read;

enum AlignmentResult {NotFound, SingleHit, MultipleHits, UnknownAlignment}; // BB: Changed Unknown to UnknownAlignment because of a conflict w/Windows headers

bool isAValidAlignmentResult(AlignmentResult result);


inline const char *AlignmentResultToString(AlignmentResult result) {
    switch (result) {
        case NotFound: return "NotFound";
        case SingleHit: return "SingleHit";
        case MultipleHits: return "MultipleHits";
        case UnknownAlignment: return "Unknown";
        default: return "Unknown alignment result type";
    }
}

struct SingleAlignmentResult {
	AlignmentResult status;

    GenomeLocation  location;	// Aligned genome location.
    GenomeLocation  origLocation;   // Location before seed was aligned
    Direction       direction;	// Did we match the reverse complement? 
    int             score;		// score of each end if matched
    int             scorePriorToClipping;   // Score prior to soft clipping generated when a read aligns off the end of a contig

    int             mapq;		// mapping quality, encoded like a Phred score (but as an integer, not ASCII Phred + 33).

    int             clippingForReadAdjustment;

    bool            usedAffineGapScoring;
    int             basesClippedBefore;
    int             basesClippedAfter;
    int             agScore;

    bool            supplementary;

    int             seedOffset;
    double          matchProbability;
    double          probabilityAllCandidates;
    unsigned        popularSeedsSkipped;
    _int64          alignmentTimeInNanoseconds;    // Only filled in when the -at option is selected

    static int compareByContigAndScore(const void *first, const void *second);      // qsort()-style compare routine
    static int compareByScore(const void *first, const void *second);               // qsort()-style compare routine
};

// Does an AlignmentResult represent a single location?
inline bool isOneLocation(AlignmentResult result) {
    return result == SingleHit;
}

const int NUM_READS_PER_PAIR = 2;    // This is just to make it clear what the array subscripts are, it doesn't ever make sense to change

struct PairedAlignmentResult {
    AlignmentResult status[NUM_READS_PER_PAIR]; // SingleHit or CertainHit if aligned, MultipleHit if matches DB
    // but not confidently aligned, or NotFound.

    GenomeLocation location[NUM_READS_PER_PAIR];// Genome location of each read.
    GenomeLocation origLocation[NUM_READS_PER_PAIR]; // Genome location of each read prior to Landau-Vishkin adjustment

    Direction direction[NUM_READS_PER_PAIR];    // Did we match the reverse complement? In general the two reads should have
    // opposite orientations because they're part of the same original fragment,
    // but it seems possible for a piece of the genome to get cut cleanly and flip
    // in a translocation event, which would cause both ends of a fragment aligning
    // there to be in the same orientation w.r.t. the reference genome.

    int score[NUM_READS_PER_PAIR];              // score of each end if matched
    int scorePriorToClipping[NUM_READS_PER_PAIR]; // Score prior to soft clipping generated when a read aligns off the end of a contig

    int mapq[NUM_READS_PER_PAIR];               // mapping quality of each end, encoded like a Phred score (but as an integer, not ASCII Phred + 33).

    int clippingForReadAdjustment[NUM_READS_PER_PAIR];

    bool usedAffineGapScoring[NUM_READS_PER_PAIR];
    int basesClippedBefore[NUM_READS_PER_PAIR];
    int basesClippedAfter[NUM_READS_PER_PAIR];
    int agScore[NUM_READS_PER_PAIR];
    bool supplementary[NUM_READS_PER_PAIR];
    int seedOffset[NUM_READS_PER_PAIR];
    int lvIndels[NUM_READS_PER_PAIR];
    double matchProbability[NUM_READS_PER_PAIR];
    double probabilityAllPairs;
    unsigned popularSeedsSkipped[NUM_READS_PER_PAIR];
    bool usedGaplessClipping[NUM_READS_PER_PAIR];
    int refSpan[NUM_READS_PER_PAIR];
    bool liftover[NUM_READS_PER_PAIR];

    bool alignedAsPair;                         // Were the reads aligned as a pair, or separately?
    bool agForcedSingleAlignerCall;             // Did we call the single aligner only because affine gap asked us to?  
    _int64 nanosInAlignTogether;
    _int64 alignmentTimeInNanoseconds;    // Only filled in when the -at option is selected

    unsigned nLVCalls;
    unsigned nSmallHits;

    static int compareByContigAndScore(const void *first, const void *second);      // qsort()-style compare routine
    static int compareByScore(const void *first, const void *second);               // qsort()-style compare routine

    inline PairedAlignmentResult& operator=(const PairedAlignmentResult& other) {
        for (int i = 0; i < NUM_READS_PER_PAIR; i++) {
            status[i] = other.status[i];
            location[i] = other.location[i];
            origLocation[i] = other.origLocation[i];
            direction[i] = other.direction[i];
            score[i] = other.score[i];
            scorePriorToClipping[i] = other.scorePriorToClipping[i];
            mapq[i] = other.mapq[i];
            clippingForReadAdjustment[i] = other.clippingForReadAdjustment[i];
            usedAffineGapScoring[i] = other.usedAffineGapScoring[i];
            basesClippedBefore[i] = other.basesClippedBefore[i];
            basesClippedAfter[i] = other.basesClippedAfter[i];
            agScore[i] = other.agScore[i];
            supplementary[i] = other.supplementary[i];
            seedOffset[i] = other.seedOffset[i];
            lvIndels[i] = other.lvIndels[i];
            matchProbability[i] = other.matchProbability[i];
            popularSeedsSkipped[i] = other.popularSeedsSkipped[i];
            usedGaplessClipping[i] = other.usedGaplessClipping[i];
            refSpan[i] = other.refSpan[i];
            liftover[i] = other.liftover[i];
        }
        probabilityAllPairs = other.probabilityAllPairs;
        alignedAsPair = other.alignedAsPair;
        agForcedSingleAlignerCall = other.agForcedSingleAlignerCall;
        nanosInAlignTogether = other.nanosInAlignTogether;
        nLVCalls = other.nLVCalls;
        nSmallHits = other.nSmallHits;
        alignmentTimeInNanoseconds = other.alignmentTimeInNanoseconds;
        return *this;
    }
};