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 "SnpEffSupport.h"
23 
24 #include <U2Core/AppContext.h>
25 #include <U2Core/AppResources.h>
26 #include <U2Core/AppSettings.h>
27 #include <U2Core/DataPathRegistry.h>
28 #include <U2Core/ScriptingToolRegistry.h>
29 #include <U2Core/Settings.h>
30 #include <U2Core/U2OpStatusUtils.h>
31 #include <U2Core/U2SafePoints.h>
32 
33 #include <U2Formats/ConvertFileTask.h>
34 
35 #include "SnpEffDatabaseListModel.h"
36 #include "SnpEffDatabaseListTask.h"
37 #include "java/JavaSupport.h"
38 
39 namespace U2 {
40 
41 SnpEffDatabaseListModel *SnpEffSupport::databaseModel = new SnpEffDatabaseListModel();
42 const QString SnpEffSupport::ET_SNPEFF = "SnpEff";
43 const QString SnpEffSupport::ET_SNPEFF_ID = "USUPP_SNPEFF";
44 
SnpEffSupport()45 SnpEffSupport::SnpEffSupport()
46     : ExternalTool(SnpEffSupport::ET_SNPEFF_ID, "snpeff", SnpEffSupport::ET_SNPEFF) {
47     if (AppContext::getMainWindow() != nullptr) {
48         icon = QIcon(":external_tool_support/images/cmdline.png");
49         grayIcon = QIcon(":external_tool_support/images/cmdline_gray.png");
50         warnIcon = QIcon(":external_tool_support/images/cmdline_warn.png");
51     }
52 
53     executableFileName = "snpEff.jar";
54 
55     validMessage = "Usage: snpEff \\[command\\] \\[options\\] \\[files\\]";
56     description = tr("<i>SnpEff</i>: Genetic variant annotation and effect prediction toolbox.");
57 
58     versionRegExp = QRegExp("version SnpEff (\\d+.\\d+[a-zA-Z]?)");
59     validationArguments << "-h";
60     toolKitName = "SnpEff";
61 
62     toolRunnerProgram = JavaSupport::ET_JAVA_ID;
63     dependencies << JavaSupport::ET_JAVA_ID;
64 
65     connect(this, SIGNAL(si_toolValidationStatusChanged(bool)), SLOT(sl_validationStatusChanged(bool)));
66 }
67 
getToolRunnerAdditionalOptions() const68 QStringList SnpEffSupport::getToolRunnerAdditionalOptions() const {
69     QStringList result;
70     AppResourcePool *s = AppContext::getAppSettings()->getAppResourcePool();
71     CHECK(s != nullptr, result);
72     //java VM can't allocate whole free memory, Xmx size should be lesser than free memory
73     int memSize = s->getMaxMemorySizeInMB();
74 #if (defined(Q_OS_WIN) || defined(Q_OS_LINUX))
75     ExternalToolRegistry *etRegistry = AppContext::getExternalToolRegistry();
76     JavaSupport *java = qobject_cast<JavaSupport *>(etRegistry->getById(JavaSupport::ET_JAVA_ID));
77     CHECK(java != nullptr, result);
78     if (java->getArchitecture() == JavaSupport::x32) {
79         memSize = memSize > 1212 ? 1212 : memSize;
80     }
81 #endif    // windows or linux
82     result << "-Xmx" + QString::number(memSize > 150 ? memSize - 150 : memSize) + "M";
83     return result;
84 }
85 
sl_validationStatusChanged(bool isValid)86 void SnpEffSupport::sl_validationStatusChanged(bool isValid) {
87     if (isValid) {
88         SnpEffDatabaseListTask *task = new SnpEffDatabaseListTask();
89         connect(task, SIGNAL(si_stateChanged()), SLOT(sl_databaseListIsReady()));
90         AppContext::getTaskScheduler()->registerTopLevelTask(task);
91     }
92 }
93 
sl_databaseListIsReady()94 void SnpEffSupport::sl_databaseListIsReady() {
95     SnpEffDatabaseListTask *task = dynamic_cast<SnpEffDatabaseListTask *>(sender());
96     SAFE_POINT(task != nullptr, "SnpEffDatabaseListTask is NULL: wrong sender", );
97     if (task->isCanceled() || task->hasError() || !task->isFinished()) {
98         return;
99     }
100     QString dbListFilePath = task->getDbListFilePath();
101     SAFE_POINT(!dbListFilePath.isEmpty(), tr("Failed to get SnpEff database list"), );
102 
103     SnpEffSupport::databaseModel->getData(dbListFilePath);
104 }
105 
106 }    // namespace U2
107