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 "StringtieGeneAbundanceReportWorker.h"
23
24 #include <U2Core/FailTask.h>
25 #include <U2Core/FileAndDirectoryUtils.h>
26 #include <U2Core/TaskSignalMapper.h>
27
28 #include <U2Lang/BaseSlots.h>
29 #include <U2Lang/WorkflowMonitor.h>
30
31 #include "StringtieGeneAbundanceReportTask.h"
32 #include "StringtieGeneAbundanceReportWorkerFactory.h"
33
34 namespace U2 {
35 namespace LocalWorkflow {
36
StringtieGeneAbundanceReportWorker(Actor * actor)37 StringtieGeneAbundanceReportWorker::StringtieGeneAbundanceReportWorker(Actor *actor)
38 : BaseWorker(actor, false) {
39 }
40
init()41 void StringtieGeneAbundanceReportWorker::init() {
42 input = ports.value(StringtieGeneAbundanceReportWorkerFactory::INPUT_PORT_ID);
43 SAFE_POINT(nullptr != input, QString("Port with id '%1' is NULL").arg(StringtieGeneAbundanceReportWorkerFactory::INPUT_PORT_ID), );
44 }
45
tick()46 Task *StringtieGeneAbundanceReportWorker::tick() {
47 bool noMessage = true;
48 bool portIsEnded = true;
49
50 if (input->hasMessage()) {
51 noMessage = false;
52 while (input->hasMessage()) {
53 Message message = getMessageAndSetupScriptValues(input);
54 const QString stringtieReport = message.getData()
55 .toMap()[BaseSlots::URL_SLOT().getId()]
56 .toString();
57 if (stringtieReport.isEmpty()) {
58 setDone();
59 return new FailTask(tr("An empty URL to StringTie report passed to the '%1'")
60 .arg(getActor()->getLabel()));
61 }
62 stringtieReports << stringtieReport;
63 }
64 }
65 if (!input->isEnded()) {
66 portIsEnded = false;
67 }
68
69 if (noMessage && portIsEnded) {
70 if (stringtieReports.size() > 0) {
71 const QString geneAbudanceReportUrl = getValue<QString>(StringtieGeneAbundanceReportWorkerFactory::OUTPUT_FILE_ATTR_ID);
72 FileAndDirectoryUtils::createWorkingDir(geneAbudanceReportUrl,
73 FileAndDirectoryUtils::FILE_DIRECTORY,
74 "",
75 "");
76 StringtieGeneAbundanceReportTask *task = new StringtieGeneAbundanceReportTask(stringtieReports,
77 geneAbudanceReportUrl,
78 context->workingDir());
79 stringtieReports.clear();
80 connect(new TaskSignalMapper(task),
81 SIGNAL(si_taskSucceeded(Task *)),
82 SLOT(sl_taskSucceeded(Task *)));
83 return task;
84 }
85
86 if (portIsEnded) {
87 setDone();
88 algoLog.info(QString("Filter worker is done as input was ended"));
89 }
90 }
91
92 return nullptr;
93 }
94
cleanup()95 void StringtieGeneAbundanceReportWorker::cleanup() {
96 }
97
sl_taskSucceeded(Task * task)98 void StringtieGeneAbundanceReportWorker::sl_taskSucceeded(Task *task) {
99 StringtieGeneAbundanceReportTask *geneAbudanceReportTask = qobject_cast<StringtieGeneAbundanceReportTask *>(task);
100 SAFE_POINT(nullptr != geneAbudanceReportTask, "StringTieGeneAbundanceReportTask is NULL", );
101
102 const QString geneAbudanceReportUrl = geneAbudanceReportTask->getReportUrl();
103 monitor()->addOutputFile(geneAbudanceReportUrl, getActor()->getId(), true);
104 }
105
106 } // namespace LocalWorkflow
107 } // namespace U2
108