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 "AssemblyMessageTranslator.h"
23
24 #include <QScopedPointer>
25
26 #include <U2Core/U2AssemblyDbi.h>
27 #include <U2Core/U2OpStatusUtils.h>
28 #include <U2Core/U2SafePoints.h>
29
30 #include <U2Lang/DbiDataHandler.h>
31 #include <U2Lang/WorkflowContext.h>
32
33 const char *ASSEMBLY_LENGTH_LABEL = "Length: ";
34 const char *COUNT_OF_READS_LABEL = " Count of reads: ";
35
36 namespace U2 {
37
38 using namespace Workflow;
39
AssemblyMessageTranslator(const QVariant & atomicMessage,Workflow::WorkflowContext * initContext)40 AssemblyMessageTranslator::AssemblyMessageTranslator(const QVariant &atomicMessage,
41 Workflow::WorkflowContext *initContext)
42 : BaseMessageTranslator(atomicMessage, initContext) {
43 SAFE_POINT(source.canConvert<SharedDbiDataHandler>(), "Message doesn't contain dbi reference", );
44 SharedDbiDataHandler dbId = source.value<SharedDbiDataHandler>();
45 QScopedPointer<AssemblyObject> assemblyObject(StorageUtils::getAssemblyObject(
46 context->getDataStorage(), dbId));
47 SAFE_POINT(!assemblyObject.isNull(), "Couldn't obtain assembly object", );
48 assemblyRef = assemblyObject->getEntityRef();
49 }
50
getTranslation() const51 QString AssemblyMessageTranslator::getTranslation() const {
52 U2OpStatusImpl os;
53 DbiConnection connection(assemblyRef.dbiRef, os);
54 SAFE_POINT_OP(os, QString());
55
56 U2AssemblyDbi *dbi = connection.dbi->getAssemblyDbi();
57 SAFE_POINT(nullptr != dbi, "Invalid assembly DBI!", QString());
58 const U2DataId assemblyId = assemblyRef.entityId;
59 const qint64 assemblyLength = dbi->getMaxEndPos(assemblyId, os) + 1;
60 SAFE_POINT_OP(os, QString());
61
62 const U2Region wholeAssembly(0, assemblyLength);
63 const qint64 countOfReads = dbi->countReads(assemblyId, wholeAssembly, os);
64 SAFE_POINT_OP(os, QString());
65
66 QString result = QObject::tr(ASSEMBLY_LENGTH_LABEL) + QString::number(assemblyLength) + INFO_FEATURES_SEPARATOR;
67 result += QObject::tr(COUNT_OF_READS_LABEL) + QString::number(countOfReads);
68
69 return result;
70 }
71
72 } // namespace U2
73