CreateSubalignmentSettings FormatsMsaClipboardTask::defineSettings(const QStringList& names, const U2Region &window, const DocumentFormatId &formatId, U2OpStatus& os){
    //Create temporal document for the workflow run task
    const AppSettings* appSettings = AppContext::getAppSettings();
    SAFE_POINT_EXT(NULL != appSettings, os.setError(tr("Invalid applications settings detected")), CreateSubalignmentSettings());

    UserAppsSettings* usersSettings = appSettings->getUserAppsSettings();
    SAFE_POINT_EXT(NULL != usersSettings, os.setError(tr("Invalid users applications settings detected")), CreateSubalignmentSettings());
    const QString tmpDirPath = usersSettings->getCurrentProcessTemporaryDirPath();
    GUrl path = GUrlUtils::prepareTmpFileLocation(tmpDirPath, "clipboard", "tmp", os);

    return CreateSubalignmentSettings(window, names, path, true, false, formatId);
}
Esempio n. 2
0
QList<Task*> DefaultConvertFileTask::onSubTaskFinished(Task *subTask) {
    QList<Task*> result;
    CHECK(!subTask->hasError() && !subTask->isCanceled(), result);
    CHECK(!hasError() && !isCanceled(), result);

    if (saveTask == subTask) {
        return result;
    }
    SAFE_POINT_EXT(loadTask == subTask, setError("Unknown subtask"), result);

    bool mainThread = false;
    Document *srcDoc = loadTask->getDocument(mainThread);
    SAFE_POINT_EXT(NULL != srcDoc, setError("NULL document"), result);

    DocumentFormatRegistry *dfr = AppContext::getDocumentFormatRegistry();
    DocumentFormat *df = dfr->getFormatById(targetFormat);
    SAFE_POINT_EXT(NULL != df, setError("NULL document format"), result);

    QSet<GObjectType> selectedFormatObjectsTypes = df->getSupportedObjectTypes();
    QSet<GObjectType> inputFormatObjectTypes;
    QListIterator<GObject*> objectsIterator(srcDoc->getObjects());
    while (objectsIterator.hasNext()) {
        GObject *obj = objectsIterator.next();
        inputFormatObjectTypes << obj->getGObjectType();
    }
    inputFormatObjectTypes.intersect(selectedFormatObjectsTypes);
    if (inputFormatObjectTypes.empty()) {
        setError(tr("The formats are not compatible: %1 and %2").arg(srcDoc->getDocumentFormatId()).arg(targetFormat));
        return result;
    }

    QString ext = targetFormat;
    if (!df->getSupportedDocumentFileExtensions().isEmpty()) {
        ext = df->getSupportedDocumentFileExtensions().first();
    }

    if (targetUrl.isEmpty()) {
        QString fileName = srcDoc->getName() + "." + ext;
        targetUrl = GUrlUtils::rollFileName(workingDir + fileName, QSet<QString>());
    } else {
        if (QFileInfo(targetFormat).suffix() != ext) {
            targetUrl += "." + ext;
        }
        targetUrl = GUrlUtils::rollFileName(targetUrl, QSet<QString>());
    }

    IOAdapterFactory *iof = AppContext::getIOAdapterRegistry()->getIOAdapterFactoryById(IOAdapterUtils::url2io(srcDoc->getURL()));
    Document *dstDoc = srcDoc->getSimpleCopy(df, iof, srcDoc->getURL());

    saveTask = new SaveDocumentTask(dstDoc, iof, targetUrl);
    result << saveTask;
    return result;
}
QList<Task*> FormatsMsaClipboardTask::onSubTaskFinished(Task *subTask) {
    QList<Task*> res;
    QList<Task*> subTasks;
    if (subTask->hasError() || isCanceled()) {
        return subTasks;
    }

    if(subTask == createSubalignmentTask){
        Document* doc = createSubalignmentTask->getDocument();
        SAFE_POINT_EXT(doc != NULL, setError(tr("No temporary document.")), subTasks);
        QScopedPointer<LocalFileAdapterFactory> factory( new LocalFileAdapterFactory());
        QScopedPointer<IOAdapter> io(factory->createIOAdapter());
        if(!io->open(doc->getURL(), IOAdapterMode_Read)){
            setError(tr("Cannot read the temporary file."));
            return subTasks;
        }

        QByteArray buf;
        while(!io->isEof()){
            buf.resize(READ_BUF_SIZE);
            buf.fill(0);
            bool terminatorFound = false;
            int read = io->readLine(buf.data(), READ_BUF_SIZE, &terminatorFound);
            buf.resize(read);
            result.append(buf);
            if (terminatorFound){
                result.append('\n');
            }
        }
    }
    return res;
}
Esempio n. 4
0
QList<Task*> DnaAssemblyTaskWithConversions::onSubTaskFinished(Task *subTask) {
    QList<Task*> result;
    CHECK(!subTask->hasError(), result);
    CHECK(!hasError(), result);

    ConvertFileTask *convertTask = dynamic_cast<ConvertFileTask*>(subTask);
    if (NULL != convertTask) {
        SAFE_POINT_EXT(conversionTasksCount > 0, setError("Conversions task count error"), result);
        if (convertTask->getSourceURL() == settings.refSeqUrl) {
            settings.refSeqUrl = convertTask->getResult();
        }

        for (QList<ShortReadSet>::Iterator i=settings.shortReadSets.begin(); i != settings.shortReadSets.end(); i++) {
            if (convertTask->getSourceURL() == i->url) {
                i->url = convertTask->getResult();
            }
        }
        conversionTasksCount--;

        if (0 == conversionTasksCount) {
            assemblyTask = new DnaAssemblyMultiTask(settings, viewResult, justBuildIndex);
            result << assemblyTask;
        }
    }

    return result;
}
Esempio n. 5
0
QList<Task*> BAMImporterTask::onSubTaskFinished(Task* subTask) {
    QList<Task*> res;

    if (subTask->hasError()) {
        propagateSubtaskError();
        return res;
    }

    if (loadInfoTask == subTask) {
        initPrepareToImportTask();
        CHECK(NULL != prepareToImportTask, res);
        res << prepareToImportTask;
    }

    else if (prepareToImportTask == subTask && prepareToImportTask->isNewURL()) {
        initLoadBamInfoTask();
        CHECK(NULL != loadBamInfoTask, res);
        res << loadBamInfoTask;
    }

    else if (loadBamInfoTask == subTask || prepareToImportTask == subTask) {
        initConvertToSqliteTask();
        CHECK(NULL != convertTask, res);
        res << convertTask;
    }

    else if (isSqliteDbTransit && convertTask == subTask) {
        initCloneObjectTasks();
        CHECK(!cloneTasks.isEmpty(), res);
        res << cloneTasks;
    }

    else if (!isSqliteDbTransit && convertTask == subTask) {
        initLoadDocumentTask();
        CHECK(NULL != loadDocTask, res);
        res << loadDocTask;
    }

    else if ((isSqliteDbTransit && cloneTasks.contains(subTask))) {
        cloneTasks.removeOne(subTask);
        CloneObjectTask *cloneTask = qobject_cast<CloneObjectTask *>(subTask);
        SAFE_POINT_EXT(NULL != cloneTask, setError("Unexpected task type: CloneObjectTask expected"), res);
        delete cloneTask->getSourceObject();

        if (cloneTasks.isEmpty()) {
            initLoadDocumentTask();
            CHECK(NULL != loadDocTask, res);
            res << loadDocTask;
        }
    }

    else if (subTask == loadDocTask) {
        resultDocument = loadDocTask->takeDocument();
    }

    return res;
}
QString PrepareInputFastaFilesTask::getBestFormatId(const QString &filePath) {
    QList<FormatDetectionResult> formats = DocumentUtils::detectFormat(filePath);
    if (formats.isEmpty()) {
        stateInfo.addWarning(tr("File '%1' was skipped. Cannot detect the file format.").arg(filePath));
        return "";
    }
    SAFE_POINT_EXT(NULL != formats.first().format, setError("An incorrect format found. An importer?"), "");
    return formats.first().format->getFormatId();
}
Esempio n. 7
0
int SQLiteBlobInputStream::read(char *buffer, int length, U2OpStatus &os) {
    SAFE_POINT_EXT(NULL != handle, os.setError("blob handle is not opened"), 0);
    int targetLength = (offset + length < size) ? length : (size - offset);
    if (0 == targetLength) {
        return -1;
    }

    int status = sqlite3_blob_read(handle, (void*)buffer, targetLength, offset);
    if (SQLITE_OK != status) {
        os.setError(QObject::tr("Can not read data. The database is closed or the data were changed."));
        return 0;
    }
    offset += targetLength;
    return targetLength;
}
Esempio n. 8
0
qint64 SQLiteBlobInputStream::skip(qint64 n, U2OpStatus &os) {
    SAFE_POINT_EXT(NULL != handle, os.setError("blob handle is not opened"), 0);
    if (offset + n >= size) {
        int oldOffset = offset;
        offset = size;
        return size - oldOffset;
    }
    if (offset + n < 0) {
        int oldOffset = offset;
        offset = 0;
        return -oldOffset;
    }
    offset += n;
    return n;
}
Esempio n. 9
0
QByteArray SQLiteSequenceDbi::getSequenceData(const U2DataId& sequenceId, const U2Region& region, U2OpStatus& os) {
    try {
        QByteArray res;
        if (0 == region.length) {
            return res;
        } else if (U2_REGION_MAX != region) {
            res.reserve(region.length);
        }
        // Get all chunks that intersect the region
        SQLiteReadQuery q("SELECT sstart, send, data FROM SequenceData WHERE sequence = ?1 "
            "AND  (send >= ?2 AND sstart < ?3) ORDER BY sstart", db, os);

        q.bindDataId(1, sequenceId);
        q.bindInt64(2, region.startPos);
        q.bindInt64(3, region.endPos());
        qint64 pos = region.startPos;
        qint64 regionLengthToRead = region.length;
        while (q.step()) {
            qint64 sstart = q.getInt64(0);
            qint64 send = q.getInt64(1);
            qint64 length = send - sstart;
            QByteArray data = q.getBlob(2);

            int copyStart = pos - sstart;
            int copyLength = static_cast<int>(qMin(regionLengthToRead, length - copyStart));
            res.append(data.constData() + copyStart, copyLength);
            pos += copyLength;
            regionLengthToRead -= copyLength;

            SAFE_POINT_EXT(regionLengthToRead >= 0,
                os.setError("An error occurred during reading sequence data from dbi."),
                QByteArray());
        }
        return res;
    } catch (const std::bad_alloc &) {
#ifdef UGENE_X86
        os.setError("UGENE ran out of memory during the sequence processing. "
            "The 32-bit UGENE version has a restriction on its memory consumption. Try using the 64-bit version instead.");
#else
        os.setError("Out of memory during the sequence processing.");
#endif
        return QByteArray();
    } catch (...) {
        os.setError("Internal error occurred during the sequence processing.");
        coreLog.error("An exception was thrown during reading sequence data from dbi.");
        return QByteArray();
    }
}
Esempio n. 10
0
U2Region RegionSelectorController::getRegion(bool *_ok) const {
    SAFE_POINT_EXT(gui.startLineEdit != NULL && gui.endLineEdit != NULL, *_ok = false, U2Region());

    bool ok = false;
    qint64 v1 = gui.startLineEdit->text().toLongLong(&ok) - 1;

    if (!ok || v1 < 0 || v1 > settings.maxLen) {
        if (_ok != NULL) {
            *_ok = false;
        }
        return U2Region();
    }

    int v2 = gui.endLineEdit->text().toLongLong(&ok);

    if (!ok || v2 <= 0 || v2 > settings.maxLen) {
        if (_ok != NULL) {
            *_ok = false;
        }
        return U2Region();
    }

    if (v1 > v2 && !settings.circular) { // start > end
        if (_ok != NULL) {
            *_ok = false;
        }
        return U2Region();
    }

    if (_ok != NULL) {
        *_ok = true;
    }

    if (v1 < v2) {
        return U2Region(v1, v2 - v1);
    } else {
        return U2Region(v1, v2 + settings.maxLen - v1);
    }
}
Esempio n. 11
0
bool WevoteValidator::validateTaxonomy(const Actor *actor, NotificationsList &notificationList) const {
    bool isValid = true;

    U2DataPathRegistry *dataPathRegistry = AppContext::getDataPathRegistry();
    SAFE_POINT_EXT(NULL != dataPathRegistry, notificationList.append(WorkflowNotification("U2DataPathRegistry is NULL", actor->getId())), false);

    U2DataPath *taxonomyDataPath = dataPathRegistry->getDataPathByName(NgsReadsClassificationPlugin::TAXONOMY_DATA_ID);
    CHECK_EXT(NULL != taxonomyDataPath && taxonomyDataPath->isValid(),
              notificationList << WorkflowNotification(tr("Taxonomy classification data from NCBI are not available."), actor->getId()), false);

    const QString missingFileMessage = tr("Taxonomy classification data from NCBI are not full: file '%1' is missing.");
    if (taxonomyDataPath->getPathByName(NgsReadsClassificationPlugin::TAXON_NODES_ITEM_ID).isEmpty()) {
        notificationList << WorkflowNotification(missingFileMessage.arg(NgsReadsClassificationPlugin::TAXON_NODES_ITEM_ID), actor->getId());
        isValid = false;
    }

    if (taxonomyDataPath->getPathByName(NgsReadsClassificationPlugin::TAXON_NAMES_ITEM_ID).isEmpty()) {
        notificationList << WorkflowNotification(missingFileMessage.arg(NgsReadsClassificationPlugin::TAXON_NAMES_ITEM_ID), actor->getId());
        isValid = false;
    }

    return isValid;
}
Esempio n. 12
0
bool UdrRecord::checkNum(int fieldNum, U2OpStatus &os) const {
    SAFE_POINT_EXT(NULL != schema, os.setError("NULL schema"), false);
    SAFE_POINT_EXT(data.size() == schema->size(), os.setError("Size mismatch"), false);
    SAFE_POINT_EXT(0 <= fieldNum && fieldNum < schema->size(), os.setError("Out of range"), false);
    return true;
}
QList<Task*> MafftAddToAlignmentTask::onSubTaskFinished(Task* subTask) {
    QList<Task*> subTasks;

    propagateSubtaskError();
    if(subTask->isCanceled() || isCanceled() || hasError()) {
        return subTasks;
    }

    if((subTask == saveAlignmentDocumentTask || subTask == saveSequencesDocumentTask) && saveAlignmentDocumentTask->isFinished()
        && saveSequencesDocumentTask->isFinished()) {

        resultFilePath = settings.resultFileName.isEmpty() ? tmpDirUrl + QDir::separator() + "result_aln.fa" : settings.resultFileName.getURLString();
        QStringList arguments;
        if(settings.addAsFragments) {
            arguments << "--addfragments";
        } else {
            arguments << "--add";
        }
        arguments << saveSequencesDocumentTask->getURL().getURLString();
        const DNAAlphabet* alphabet = U2AlphabetUtils::getById(settings.alphabet);
        SAFE_POINT_EXT(alphabet != NULL, setError("Albhabet is invalid."), subTasks);
        if(alphabet->isRaw()) {
            arguments << "--anysymbol";
        }
        if(useMemsaveOption()) {
            arguments << "--memsave";
        }
        if(settings.reorderSequences) {
            arguments << "--reorder";
        }
        arguments << saveAlignmentDocumentTask->getDocument()->getURLString();
        QString outputUrl = resultFilePath + ".out.fa";

        logParser = new MAFFTLogParser(inputMsa->getNumRows(), 1, outputUrl);
        mafftTask = new ExternalToolRunTask(ET_MAFFT, arguments, logParser);
        mafftTask->setStandartOutputFile(resultFilePath);
        mafftTask->setSubtaskProgressWeight(65);
        subTasks.append(mafftTask);
    } else if (subTask == mafftTask) {
        SAFE_POINT(logParser != NULL, "logParser is null", subTasks);
        logParser->cleanup();
        if (!QFileInfo(resultFilePath).exists()) {
            if (AppContext::getExternalToolRegistry()->getByName(ET_MAFFT)->isValid()){
                stateInfo.setError(tr("Output file '%1' not found").arg(resultFilePath));
            } else {
                stateInfo.setError(tr("Output file '%3' not found. May be %1 tool path '%2' not valid?")
                    .arg(AppContext::getExternalToolRegistry()->getByName(ET_MAFFT)->getName())
                    .arg(AppContext::getExternalToolRegistry()->getByName(ET_MAFFT)->getPath())
                    .arg(resultFilePath));
            }
            return subTasks;
        }
        ioLog.details(tr("Loading output file '%1'").arg(resultFilePath));
        IOAdapterFactory* iof = AppContext::getIOAdapterRegistry()->getIOAdapterFactoryById(BaseIOAdapters::LOCAL_FILE);
        loadTmpDocumentTask = new LoadDocumentTask(BaseDocumentFormats::FASTA, resultFilePath, iof);
        loadTmpDocumentTask->setSubtaskProgressWeight(5);
        subTasks.append(loadTmpDocumentTask);
    } else if(subTask == loadTmpDocumentTask) {
        modStep = new U2UseCommonUserModStep(settings.msaRef, stateInfo);
    }

    return subTasks;
}