File: runblastsearchworker.cpp

package info (click to toggle)
bandage 0.9.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 15,684 kB
  • sloc: cpp: 45,359; sh: 491; makefile: 12
file content (117 lines) | stat: -rw-r--r-- 3,756 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//Copyright 2017 Ryan Wick

//This file is part of Bandage

//Bandage is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//Bandage is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with Bandage.  If not, see <http://www.gnu.org/licenses/>.


#include "runblastsearchworker.h"
#include "../program/globals.h"
#include "../program/settings.h"
#include "blastsearch.h"
#include "../program/memory.h"


RunBlastSearchWorker::RunBlastSearchWorker(QString blastnCommand, QString tblastnCommand, QString parameters) :
    m_blastnCommand(blastnCommand), m_tblastnCommand(tblastnCommand), m_parameters(parameters)
{

}


void RunBlastSearchWorker::runBlastSearch()
{
    g_blastSearch->m_cancelRunBlastSearch = false;

    bool success;

    if (g_blastSearch->m_blastQueries.getQueryCount(NUCLEOTIDE) > 0)
    {
        g_blastSearch->m_blastOutput += runOneBlastSearch(NUCLEOTIDE, &success);
        if (!success)
            return;
    }

    if (g_blastSearch->m_blastQueries.getQueryCount(PROTEIN) > 0 && !g_blastSearch->m_cancelRunBlastSearch)
    {
        g_blastSearch->m_blastOutput += runOneBlastSearch(PROTEIN, &success);
        if (!success)
            return;
    }

    if (g_blastSearch->m_cancelRunBlastSearch)
    {
        m_error = "BLAST search cancelled.";
        emit finishedSearch(m_error);
        return;
    }

    //If the code got here, then the search completed successfully.
    g_blastSearch->buildHitsFromBlastOutput();
    g_blastSearch->findQueryPaths();
    g_blastSearch->m_blastQueries.searchOccurred();
    m_error = "";
    emit finishedSearch(m_error);
}


QString RunBlastSearchWorker::runOneBlastSearch(SequenceType sequenceType, bool * success)
{
    QString blastCommand;
    QStringList blastCommandArguments = { "-query" };
    if (sequenceType == NUCLEOTIDE) {
        blastCommand = m_blastnCommand;
        blastCommandArguments << g_blastSearch-> m_tempDirectory + "nucl_queries.fasta";
    }
    else {
        blastCommand = m_tblastnCommand;
        blastCommandArguments << g_blastSearch-> m_tempDirectory + "prot_queries.fasta";
    }
    blastCommandArguments << "-db" << (g_blastSearch->m_tempDirectory + "all_nodes.fasta");
    blastCommandArguments << "-outfmt" << "6";
    blastCommandArguments += m_parameters.split(" ", Qt::SkipEmptyParts);

    g_blastSearch->m_blast = new QProcess();
    g_blastSearch->m_blast->start(blastCommand, blastCommandArguments);

    bool finished = g_blastSearch->m_blast->waitForFinished(-1);

    if (g_blastSearch->m_blast->exitCode() != 0 || !finished)
    {
        if (g_blastSearch->m_cancelRunBlastSearch)
        {
            m_error = "BLAST search cancelled.";
            emit finishedSearch(m_error);
        }
        else
        {
            m_error = "There was a problem running the BLAST search";
            QString stdErr = g_blastSearch->m_blast->readAllStandardError();
            if (stdErr.length() > 0)
                m_error += ":\n\n" + stdErr;
            else
                m_error += ".";
            emit finishedSearch(m_error);
        }
        *success = false;
        return "";
    }

    QString blastOutput = g_blastSearch->m_blast->readAllStandardOutput();
    g_blastSearch->m_blast->deleteLater();
    g_blastSearch->m_blast = 0;

    *success = true;
    return blastOutput;
}