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 <SamtoolsAdapter.h>
23
24 #include "AssemblyDbiTestUtil.h"
25
26 namespace U2 {
27
28 const char *AssemblyDbiTestUtil::ERR_INVALID_ASSEMBLY_ID("Error message for invalid assembly id passed is not set.");
29
compareCigar(const QList<U2CigarToken> & c1,const QList<U2CigarToken> & c2)30 bool AssemblyDbiTestUtil::compareCigar(const QList<U2CigarToken> &c1, const QList<U2CigarToken> &c2) {
31 if (c1.size() != c2.size()) {
32 return false;
33 }
34 for (int i = 0; i < c1.size(); i++) {
35 U2CigarToken tok1 = c1.at(i);
36 U2CigarToken tok2 = c2.at(i);
37 if (tok1.count != tok2.count || tok1.op != tok2.op) {
38 return false;
39 }
40 }
41 return true;
42 }
43
compareReads(const U2AssemblyRead & r1,const U2AssemblyRead & r2)44 bool AssemblyDbiTestUtil::compareReads(const U2AssemblyRead &r1, const U2AssemblyRead &r2) {
45 if (r1->name != r2->name) {
46 return false;
47 }
48 if (r1->leftmostPos != r2->leftmostPos) {
49 return false;
50 }
51 if (r1->effectiveLen != r2->effectiveLen) {
52 return false;
53 }
54 if (r1->packedViewRow != r2->packedViewRow) {
55 return false;
56 }
57 if (r1->readSequence != r2->readSequence) {
58 return false;
59 }
60 bool q1 = SamtoolsAdapter::hasQuality(r1->quality);
61 bool q2 = SamtoolsAdapter::hasQuality(r2->quality);
62 if (q1 != q2) {
63 return false;
64 }
65 if (q1 && (r1->quality != r2->quality)) {
66 return false;
67 }
68 if (r1->mappingQuality != r2->mappingQuality) {
69 return false;
70 }
71 if (r1->flags != r2->flags) {
72 return false;
73 }
74 if (!compareCigar(r1->cigar, r2->cigar)) {
75 return false;
76 }
77 return true;
78 }
79
findRead(const U2AssemblyRead & subj,QList<U2AssemblyRead> & reads)80 bool AssemblyDbiTestUtil::findRead(const U2AssemblyRead &subj, QList<U2AssemblyRead> &reads) {
81 for (qint64 i = 0, n = reads.size(); i < n; i++) {
82 const U2AssemblyRead &curRead = reads.at(i);
83 if (compareReads(subj, curRead)) {
84 reads.removeAt(i);
85 return true;
86 }
87 }
88 return false;
89 }
90
compareReadLists(U2DbiIterator<U2AssemblyRead> * iter,QList<U2AssemblyRead> & expectedReads)91 bool AssemblyDbiTestUtil::compareReadLists(U2DbiIterator<U2AssemblyRead> *iter, QList<U2AssemblyRead> &expectedReads) {
92 while (iter->hasNext()) {
93 const U2AssemblyRead &read = iter->next();
94 if (!findRead(read, expectedReads)) {
95 return false;
96 }
97 }
98 if (!expectedReads.isEmpty()) {
99 return false;
100 }
101 return true;
102 }
103
var2readList(const QVariantList & varList,QList<U2AssemblyRead> & reads)104 void AssemblyDbiTestUtil::var2readList(const QVariantList &varList, QList<U2AssemblyRead> &reads) {
105 foreach (const QVariant &var, varList) {
106 U2AssemblyRead read = var.value<U2AssemblyRead>();
107 reads.append(read);
108 }
109 }
110
111 } // namespace U2
112