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 #include "MysqlAssemblyAdapter.h"
23
24 #include <U2Core/U2AssemblyUtils.h>
25
26 #include "MysqlAssemblyUtils.h"
27
28 namespace U2 {
29
MysqlAssemblyAdapter(const U2DataId & assemblyId,const AssemblyCompressor * compressor,MysqlDbRef * ref)30 MysqlAssemblyAdapter::MysqlAssemblyAdapter(const U2DataId &assemblyId,
31 const AssemblyCompressor *compressor,
32 MysqlDbRef *ref)
33 : AssemblyAdapter(assemblyId, compressor),
34 db(ref) {
35 }
36
MysqlAssemblyNameFilter(const QByteArray & expectedName)37 MysqlAssemblyNameFilter::MysqlAssemblyNameFilter(const QByteArray &expectedName)
38 : name(expectedName) {
39 }
40
filter(const U2AssemblyRead & r)41 bool MysqlAssemblyNameFilter::filter(const U2AssemblyRead &r) {
42 return name == r->name;
43 }
44
load(U2SqlQuery * q)45 U2AssemblyRead MysqlSimpleAssemblyReadLoader::load(U2SqlQuery *q) {
46 U2AssemblyRead read(new U2AssemblyReadData());
47
48 read->id = q->getDataId(0, U2Type::AssemblyRead);
49 read->packedViewRow = q->getInt64(1);
50 if (q->hasError()) {
51 return U2AssemblyRead();
52 }
53
54 read->leftmostPos = q->getInt64(2);
55 read->effectiveLen = q->getInt64(3);
56 read->flags = q->getInt64(4);
57 read->mappingQuality = (quint8)q->getInt32(5);
58 QByteArray data = q->getBlob(6);
59 if (q->hasError()) {
60 return U2AssemblyRead();
61 }
62
63 MysqlAssemblyUtils::unpackData(data, read, q->getOpStatus());
64 if (q->hasError()) {
65 return U2AssemblyRead();
66 }
67
68 #ifdef _DEBUG
69 // additional check to ensure that db stores correct info
70 qint64 effectiveLengthFromCigar = read->readSequence.length() + U2AssemblyUtils::getCigarExtraLength(read->cigar);
71 assert(effectiveLengthFromCigar == read->effectiveLen);
72 #endif
73
74 return read;
75 }
76
load(U2SqlQuery * q)77 PackAlgorithmData MysqlSimpleAssemblyReadPackedDataLoader::load(U2SqlQuery *q) {
78 PackAlgorithmData data;
79 data.readId = q->getDataId(0, U2Type::AssemblyRead);
80 data.leftmostPos = q->getInt64(1);
81 data.effectiveLen = q->getInt64(2);
82 return data;
83 }
84
85 } // namespace U2
86