1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #ifndef _U2_GENOME_ALIGNER_SEARCH_QUERY_H_
23 #define _U2_GENOME_ALIGNER_SEARCH_QUERY_H_
24 
25 #include <QVector>
26 
27 #include <U2Core/DNASequence.h>
28 #include <U2Core/U2AssemblyUtils.h>
29 
30 #include "GenomeAlignerIndexPart.h"
31 
32 #define BinarySearchResult qint64
33 
34 namespace U2 {
35 
36 class GenomeAlignerIndex;
37 
38 class CacheResult {
39 public:
40     int posAtShortRead;
41     int numberOfPart;
42     quint64 bitValue;
43 };
44 
45 class SearchQuery {
46     Q_DISABLE_COPY(SearchQuery)
47 public:
48     SearchQuery(const DNASequence *shortRead, SearchQuery *revCompl = nullptr);
49     SearchQuery(const U2AssemblyRead &shortRead, SearchQuery *revCompl = nullptr);
50     ~SearchQuery();
51 
52     QString getName() const;
53     int length() const;
54     int getNameLength() const;
55     char *data();
56     const char *constData() const;
57     const QByteArray constSequence() const;
58     bool hasQuality() const;
59     const DNAQuality &getQuality() const;
60 
61     bool haveResult() const;
62     bool haveMCount() const;
63     void addResult(SAType result, quint32 mCount);
64     void addOveplapResult(SAType result);
65     void onPartChanged();
66     void clear();
67     SAType firstResult() const;
68     quint32 firstMCount() const;
69     bool contains(SAType result) const;
70     const QVector<SAType> &getResults() const;
isWroteResult()71     bool isWroteResult() const {
72         return wroteResult;
73     }
writeResult()74     void writeResult() {
75         wroteResult = true;
76     }
getRevCompl()77     SearchQuery *getRevCompl() {
78         return revCompl;
79     }
setRevCompl(SearchQuery * rc)80     void setRevCompl(SearchQuery *rc) {
81         revCompl = rc;
82     }
83 
84     qint64 memoryHint() const;
85 
86 private:
87     // U2AssemblyRead assRead;
88     DNAQuality *quality;
89     char *seq;
90     char *name;
91     quint32 seqLength;
92     quint32 nameLength;
93     bool dna;
94     bool wroteResult;
95     SearchQuery *revCompl;
96 
97     QVector<SAType> results;
98     QVector<SAType> overlapResults;
99     QVector<quint32> mismatchCounts;
100 };
101 
102 class SearchQueryContainer {
103 public:
104     SearchQueryContainer();
105     ~SearchQueryContainer();
106     void append(SearchQuery *qu);
107     void clear();
108     quint64 size() const;
109     SearchQuery *at(quint64 pos);
110 
111 private:
112     SearchQuery **queries;
113     quint64 length;
114     quint64 allocated;
115 
116     static const quint64 reallocSize;
117 };
118 
119 }  // namespace U2
120 #endif  //_U2_GENOME_ALIGNER_SEARCH_QUERY_H_
121