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 "TrimmomaticTask.h"
23 
24 #include <U2Core/Counter.h>
25 #include <U2Core/GUrlUtils.h>
26 #include <U2Core/U2SafePoints.h>
27 
28 #include "TrimmomaticLogParser.h"
29 #include "TrimmomaticSupport.h"
30 
31 namespace U2 {
32 
33 const QString TrimmomaticTaskSettings::SINGLE_END = "single-end";
34 const QString TrimmomaticTaskSettings::PAIRED_END = "paired-end";
35 
TrimmomaticTaskSettings()36 TrimmomaticTaskSettings::TrimmomaticTaskSettings()
37     : pairedReadsInput(false),
38       generateLog(false),
39       numberOfThreads(1) {
40 }
41 
TrimmomaticTask(const TrimmomaticTaskSettings & settings)42 TrimmomaticTask::TrimmomaticTask(const TrimmomaticTaskSettings &settings)
43     : ExternalToolSupportTask(tr("Improve reads with Trimmomatic"), TaskFlags_NR_FOSE_COSC),
44       settings(settings),
45       trimmomaticToolRunTask(nullptr) {
46     GCOUNTER(cvar, "TrimmomaticTask");
47 
48     if (settings.pairedReadsInput) {
49         SAFE_POINT_EXT(!settings.pairedOutputUrl1.isEmpty() && !settings.pairedOutputUrl2.isEmpty() &&
50                            !settings.unpairedOutputUrl1.isEmpty() && !settings.unpairedOutputUrl2.isEmpty(),
51                        setError("At least one of the four output files is not set!"), );
52     } else {
53         SAFE_POINT_EXT(!settings.seOutputUrl.isEmpty(), setError("Output file is not set!"), );
54     }
55 
56     SAFE_POINT_EXT(!(settings.generateLog && settings.logUrl.isEmpty()), setError("Log file is not set!"), );
57 }
58 
prepare()59 void TrimmomaticTask::prepare() {
60     trimmomaticToolRunTask = new ExternalToolRunTask(TrimmomaticSupport::ET_TRIMMOMATIC_ID, getArguments(), new TrimmomaticLogParser(), settings.workingDirectory);
61     setListenerForTask(trimmomaticToolRunTask);
62     addSubTask(trimmomaticToolRunTask);
63 }
64 
getArguments()65 QStringList TrimmomaticTask::getArguments() {
66     QStringList arguments;
67 
68     if (!settings.pairedReadsInput) {
69         arguments << "SE";
70     } else {
71         arguments << "PE";
72     }
73 
74     arguments << "-threads" << QString::number(settings.numberOfThreads);
75 
76     if (settings.generateLog) {
77         arguments << "-trimlog" << settings.logUrl;
78         GUrlUtils::prepareFileLocation(settings.logUrl, stateInfo);
79     }
80 
81     if (!settings.pairedReadsInput) {
82         arguments << settings.inputUrl1;
83         arguments << settings.seOutputUrl;
84         GUrlUtils::prepareFileLocation(settings.seOutputUrl, stateInfo);
85     } else {
86         arguments << settings.inputUrl1;
87         arguments << settings.inputUrl2;
88         arguments << settings.pairedOutputUrl1;
89         arguments << settings.unpairedOutputUrl1;
90         arguments << settings.pairedOutputUrl2;
91         arguments << settings.unpairedOutputUrl2;
92         GUrlUtils::prepareFileLocation(settings.pairedOutputUrl1, stateInfo);
93         GUrlUtils::prepareFileLocation(settings.pairedOutputUrl2, stateInfo);
94         GUrlUtils::prepareFileLocation(settings.unpairedOutputUrl1, stateInfo);
95         GUrlUtils::prepareFileLocation(settings.unpairedOutputUrl2, stateInfo);
96     }
97 
98     foreach (QString step, settings.trimmingSteps) {
99         step.remove('\'');
100         arguments << step;
101     }
102 
103     return arguments;
104 }
105 
getInputUrl1() const106 const QString &TrimmomaticTask::getInputUrl1() const {
107     return settings.inputUrl1;
108 }
109 
getSeOutputUrl() const110 const QString &TrimmomaticTask::getSeOutputUrl() const {
111     return settings.seOutputUrl;
112 }
113 
getPairedOutputUrl1() const114 const QString &TrimmomaticTask::getPairedOutputUrl1() const {
115     return settings.pairedOutputUrl1;
116 }
117 
getPairedOutputUrl2() const118 const QString &TrimmomaticTask::getPairedOutputUrl2() const {
119     return settings.pairedOutputUrl2;
120 }
121 
getUnpairedOutputUrl1() const122 const QString &TrimmomaticTask::getUnpairedOutputUrl1() const {
123     return settings.unpairedOutputUrl1;
124 }
125 
getUnpairedOutputUrl2() const126 const QString &TrimmomaticTask::getUnpairedOutputUrl2() const {
127     return settings.unpairedOutputUrl2;
128 }
129 
getLogUrl() const130 const QString &TrimmomaticTask::getLogUrl() const {
131     return settings.logUrl;
132 }
133 
134 }    // namespace U2
135