void PairwiseAlignmentHirschbergTask::changeGivenUrlIfDocumentExists(QString & givenUrl, const Project * curProject) { if(NULL != curProject->findDocumentByURL(GUrl(givenUrl))) { for(size_t i = 1; ; i++) { QString tmpUrl = givenUrl; QRegExp dotWithExtensionRegExp ("\\.{1,1}[^\\.]*$|^[^\\.]*$"); dotWithExtensionRegExp.lastIndexIn(tmpUrl); tmpUrl.replace(dotWithExtensionRegExp.capturedTexts().last(), "(" + QString::number(i) + ")" + dotWithExtensionRegExp.capturedTexts().last()); if(NULL == curProject->findDocumentByURL(GUrl(tmpUrl))) { givenUrl = tmpUrl; break; } } } }
QString ImportAnnotationsFromCSVDialog::readFileHeader(const QString& fileName, bool silentFail) { IOAdapterId ioId = IOAdapterUtils::url2io(fileName); IOAdapterFactory* iof = AppContext::getIOAdapterRegistry()->getIOAdapterFactoryById(ioId); QScopedPointer<IOAdapter> io(iof->createIOAdapter()); bool ok = io->open(fileName, IOAdapterMode_Read); if (!ok) { if (!silentFail) { QMessageBox::critical(this, L10N::errorTitle(), L10N::errorOpeningFileRead(fileName)); readFileName->setFocus(); } return QString(); } QByteArray previewBuff; previewBuff.resize(PREVIEW_BUFF_SIZE); qint64 bytesRead = io->readBlock(previewBuff.data(), PREVIEW_BUFF_SIZE); if (bytesRead == -1) { if (!silentFail) { QMessageBox::critical(this, L10N::errorTitle(), L10N::errorReadingFile(GUrl(fileName))); readFileName->setFocus(); } return QString(); } assert(bytesRead >= 0); previewBuff.resize(bytesRead); return QString::fromLocal8Bit(previewBuff); }
void GzipDecompressTask::run() { taskLog.details(tr("Start decompression '%1'").arg(zippedUrl.getURLString())); SAFE_POINT_EXT(AppContext::getIOAdapterRegistry() != NULL, setError(tr("IOAdapterRegistry is NULL!")), ); IOAdapterFactory* inFactory = AppContext::getIOAdapterRegistry()->getIOAdapterFactoryById(BaseIOAdapters::GZIPPED_LOCAL_FILE); SAFE_POINT_EXT(inFactory != NULL, setError(tr("IOAdapterFactory is NULL!")), ); IOAdapterFactory* outFactory = AppContext::getIOAdapterRegistry()->getIOAdapterFactoryById(BaseIOAdapters::LOCAL_FILE); SAFE_POINT_EXT(outFactory != NULL, setError(tr("IOAdapterFactory is NULL!")), ); QScopedPointer<IOAdapter> in(inFactory->createIOAdapter()); SAFE_POINT_EXT(!in.isNull(), setError(tr("Can not create IOAdapter!")), ); QScopedPointer<IOAdapter> out(outFactory->createIOAdapter()); SAFE_POINT_EXT(!out.isNull(), setError(tr("Can not create IOAdapter!")), ); if (unzippedUrl.isEmpty()) { QString unzippedUrlString = zippedUrl.dirPath() + "/" + QFileInfo(zippedUrl.getURLString()).completeBaseName(); if (unzippedUrlString == zippedUrl.getURLString()) { unzippedUrlString.append("_decompressed"); } unzippedUrl = GUrl(unzippedUrlString); } bool res = out->open( unzippedUrl, IOAdapterMode_Write); if (!res) { Task::setError(tr("Can not open output file '%1'").arg(unzippedUrl.getURLString())); return; } res = in->open( zippedUrl, IOAdapterMode_Read); if (!res) { Task::setError(tr("Can not open input file '%1'").arg(zippedUrl.getURLString())); return; } const int BUFFER_SIZE = 2097152; QByteArray readBuffer(BUFFER_SIZE, '\0'); char* buffer = readBuffer.data(); do { if ( isCanceled() ) { return; } int len = in->readBlock(buffer, BUFFER_SIZE); if (len == -1) { stateInfo.setError(tr("Error reading file")); return; } int written = out->writeBlock(buffer, len); if (written == -1) { stateInfo.setError(tr("Error writing to file")); return; } } while ( !in->isEof() ); taskLog.details(tr("Decompression finished")); }
void GenomeAssemblyDialog::addReads(QStringList fileNames, QTreeWidget* readsWidget){ foreach(const QString& f, fileNames) { QTreeWidgetItem *item = new QTreeWidgetItem(); item->setToolTip(0, f); item->setText(0, GUrl(f).fileName()); item->setData(0, Qt::UserRole, f); readsWidget->addTopLevelItem(item); item->setSizeHint(0, QComboBox().sizeHint()); }
void Bowtie2Task::prepare() { if(!justBuildIndex) { setUpIndexBuilding(indexSuffixes); if(!settings.prebuiltIndex) { setUpIndexBuilding(largeIndexSuffixes); } } if (GzipDecompressTask::checkZipped(settings.refSeqUrl)) { temp.open(); //opening creates new temporary file temp.close(); unzipTask = new GzipDecompressTask(settings.refSeqUrl, GUrl(QFileInfo(temp).absoluteFilePath())); settings.refSeqUrl = GUrl(QFileInfo(temp).absoluteFilePath()); } if(!settings.prebuiltIndex) { QString indexFileName = settings.indexFileName; if(indexFileName.isEmpty()) { if(justBuildIndex) { indexFileName = settings.refSeqUrl.dirPath() + "/" + settings.refSeqUrl.baseFileName(); } else { indexFileName = settings.resultFileName.dirPath() + "/" + settings.resultFileName.baseFileName(); } } buildIndexTask = new Bowtie2BuildIndexTask(settings.refSeqUrl.getURLString(), indexFileName); } if(!justBuildIndex) { alignTask = new Bowtie2AlignTask(settings); } if (unzipTask != NULL) { addSubTask(unzipTask); } else if(!settings.prebuiltIndex) { addSubTask(buildIndexTask); } else if(!justBuildIndex) { addSubTask(alignTask); } else { assert(false); } }
bool SiteconIOProto::isAcceptableDrop(const QMimeData * md, QVariantMap * params, const QString & urlAttrId ) const { if (md->hasUrls()) { QList<QUrl> urls = md->urls(); if (urls.size() == 1) { QString url = urls.at(0).toLocalFile(); QString ext = GUrlUtils::getUncompressedExtension(GUrl(url, GUrl_File)); if (SiteconIO::SITECON_EXT == ext) { if (params) { params->insert(urlAttrId, url); } return true; } } } return false; }
bool AbstractAlignmentTaskSettings::convertCustomSettings() { if (customSettings.contains(ALGORITHM_NAME)) { algorithmName = customSettings.value(ALGORITHM_NAME).toString(); customSettings.remove(ALGORITHM_NAME); } if (customSettings.contains(REALIZATION_NAME)) { realizationName = customSettings.value(REALIZATION_NAME).toString(); customSettings.remove(REALIZATION_NAME); } if (customSettings.contains(RESULT_FILE_NAME) && customSettings.value(RESULT_FILE_NAME).type() == QVariant::String) { resultFileName = GUrl(customSettings.value(RESULT_FILE_NAME).toString()); customSettings.remove(RESULT_FILE_NAME); } if (customSettings.contains(IN_NEW_WINDOW)) { inNewWindow = customSettings.value(IN_NEW_WINDOW).toBool(); customSettings.remove(IN_NEW_WINDOW); } return true; }
void ExportHighligtingDialogController::accept(){ startPos = ui->startLineEdit->value(); endPos = ui->endLineEdit->value(); if(ui->oneIndexRB->isChecked()){ startingIndex = 1; }else{ startingIndex = 0; } if (saveController->getSaveFileName().isEmpty()){ QMessageBox::warning(this, tr("Warning"), tr("Export to file URL is empty!")); return; } keepGaps = ui->keepGapsBox->isChecked(); dots = ui->dotsBox->isChecked(); transpose = ui->transposeBox->isChecked(); url = GUrl(saveController->getSaveFileName()); QDialog::accept(); }
bool CreatePhyTreeDialogController::checkFileName() { const QString fileName = saveController->getSaveFileName(); if (fileName.isEmpty()) { QMessageBox::warning(this, tr("Warning"), tr("Please, input the file name.")); ui->fileNameEdit->setFocus(); return false; } settings.fileUrl = fileName; U2OpStatus2Log os; GUrlUtils::validateLocalFileUrl(GUrl(fileName), os); if (os.hasError()) { QMessageBox::warning(this, tr("Error"), tr("Please, change the output file.") + "\n" + os.getError()); ui->fileNameEdit->setFocus(Qt::MouseFocusReason); return false; } return true; }
void TabixSupportTask::prepare() { algoLog.details(tr("Tabix indexing started")); if ( BgzipTask::checkBgzf( fileUrl )) { algoLog.info(tr("Input file '%1' is already bgzipped").arg(fileUrl.getURLString())); copyTask = new CopyFileTask( fileUrl, bgzfUrl); addSubTask(copyTask); return; } if (bgzfUrl.isEmpty()) { bgzfUrl = GUrl(fileUrl.getURLString() + ".gz"); } algoLog.info(tr("Saving data to file '%1'").arg(bgzfUrl.getURLString())); bgzipTask = new BgzipTask(fileUrl, bgzfUrl); addSubTask(bgzipTask); }
QString FileAndDirectoryUtils::getWorkingDir(const QString &fileUrl, int dirMode, const QString &customDir, const QString &workingDir) { QString result; bool useInternal = false; if (dirMode == FILE_DIRECTORY) { result = GUrl(fileUrl).dirPath() + "/"; } else if (dirMode == CUSTOM) { if (!customDir.isEmpty()) { result = customDir; if (!result.endsWith("/")) { result += "/"; } } else { algoLog.error("Result folder is empty, default workflow folder is used"); useInternal = true; } } else { useInternal = true; } if (useInternal) { result = workingDir; if (!result.endsWith("/")) { result += "/"; } result += OUTPUT_SUBDIR; if (!result.endsWith("/")) { result += "/"; } if (dirMode == WORKFLOW_INTERNAL_CUSTOM) { if (!customDir.isEmpty()) { result += customDir; } if (!result.endsWith("/")) { result += "/"; } } } return result; }
DNASequenceGeneratorTask::DNASequenceGeneratorTask(const DNASequenceGeneratorConfig& cfg) : Task(tr("Generate sequence task"), TaskFlag_NoRun), cfg(cfg), loadRefTask(NULL), evalTask(NULL), generateTask(NULL), saveTask(NULL) { GCOUNTER( cvar, tvar, "DNASequenceGeneratorTask" ); if (cfg.useReference()) { // do not load reference file if it is already in project and has loaded state const QString& docUrl = cfg.getReferenceUrl(); Project* prj = AppContext::getProject(); if (prj) { Document* doc = prj->findDocumentByURL(docUrl); if (doc && doc->isLoaded()) { QString err; evalTask = createEvaluationTask(doc, err); if (evalTask) { addSubTask(evalTask); } else { stateInfo.setError(err); } return; } } loadRefTask = LoadDocumentTask::getDefaultLoadDocTask(GUrl(docUrl)); if (loadRefTask) { addSubTask(loadRefTask); } else { stateInfo.setError(tr("Incorrect reference file")); return; } } else { generateTask = new GenerateDNASequenceTask(cfg.getContent(), cfg.getLength(), cfg.window, cfg.getNumberOfSequences(), cfg.seed); addSubTask(generateTask); } }
CHECK_EXT(NULL != format || NULL != importTask, setError(tr("File format is not recognized")), ); CHECK_OP(stateInfo, ); CHECK_OP(stateInfo, ); if (NULL != importTask) { addSubTask(importTask); } } void ImportFileToDatabaseTask::run() { CHECK(NULL != format, ); const QVariantMap hints = prepareHints(); IOAdapterFactory* ioFactory = AppContext::getIOAdapterRegistry()->getIOAdapterFactoryById(IOAdapterUtils::url2io(GUrl(srcUrl))); CHECK_EXT(NULL != ioFactory, setError(tr("Unrecognized url: ") + srcUrl), ); CHECK_OP(stateInfo, ); Document* loadedDoc = format->loadDocument(ioFactory, srcUrl, hints, stateInfo); CHECK_OP(stateInfo, ); U2OpStatusImpl os; Document* restructuredDoc = DocumentUtils::createCopyRestructuredWithHints(loadedDoc, os); if (NULL != restructuredDoc) { restructuredDoc->setDocumentOwnsDbiResources(false); loadedDoc->setDocumentOwnsDbiResources(true); } else { loadedDoc->setDocumentOwnsDbiResources(false); }
void CreateDocumentFromTextDialogController::accept() { QString validationError = w->validate(); if(!validationError.isEmpty()){ QMessageBox::critical(this, this->windowTitle(), validationError); return; } const QString url = saveController->getSaveFileName(); QFileInfo fi(url); if(fi.baseName().isEmpty()){ QMessageBox::critical(this, this->windowTitle(), tr("Filename is empty")); return; } if(url.isEmpty()){ QMessageBox::critical(this, this->windowTitle(), tr("No path specified")); return; } U2OpStatus2Log os; QString fullPath = GUrlUtils::prepareFileLocation(url, os); if (fullPath.isEmpty()) { QMessageBox::critical(this, L10N::errorTitle(), os.getError()); return; } if(ui->nameEdit->text().isEmpty()) { QMessageBox::critical(this, this->windowTitle(), tr("Sequence name is empty")); return; } CHECK_OP(os, ); Task *task = new CreateSequenceFromTextAndOpenViewTask(prepareSequences(), saveController->getFormatIdToSave(), GUrl(fullPath), ui->saveImmediatelyBox->isChecked()); AppContext::getTaskScheduler()->registerTopLevelTask(task); QDialog::accept(); }
QList<Task*> PairwiseAlignmentHirschbergTask::onSubTaskFinished(Task *subTask) { QList<Task*> res; if (hasError() || isCanceled()) { return res; } if (subTask->hasError() || subTask->isCanceled()) { return res; } if (subTask == kalignSubTask) { if (settings->inNewWindow == true) { TaskStateInfo localStateInfo; Project * currentProject = AppContext::getProject(); DocumentFormat * format = AppContext::getDocumentFormatRegistry()->getFormatById(BaseDocumentFormats::CLUSTAL_ALN); Document * alignmentDoc = NULL; QString newFileUrl = settings->resultFileName.getURLString(); changeGivenUrlIfDocumentExists(newFileUrl, currentProject); alignmentDoc = format->createNewLoadedDocument(IOAdapterUtils::get(BaseIOAdapters::LOCAL_FILE), GUrl(newFileUrl), localStateInfo); CHECK_OP(localStateInfo, res); MAlignment resultMa = kalignSubTask->resultMA; MAlignmentObject * docObject = MAlignmentImporter::createAlignment(alignmentDoc->getDbiRef(), resultMa, localStateInfo); CHECK_OP(localStateInfo, res); alignmentDoc->addObject(docObject); SaveDocFlags flags = SaveDoc_Overwrite; flags |= SaveDoc_OpenAfter; res << new SaveDocumentTask(alignmentDoc, flags); } else { //in current window U2OpStatus2Log os; DbiConnection con(settings->msaRef.dbiRef, os); CHECK_OP(os, res); QList<U2MsaRow> rows = con.dbi->getMsaDbi()->getRows(settings->msaRef.entityId, os); CHECK_OP(os, res); U2UseCommonUserModStep userModStep(settings->msaRef, os); Q_UNUSED(userModStep); SAFE_POINT_OP(os, res); for (int rowNumber = 0; rowNumber < rows.length(); ++rowNumber) { if (rows[rowNumber].sequenceId == settings->firstSequenceRef.entityId) { con.dbi->getMsaDbi()->updateGapModel(settings->msaRef.entityId, rows[rowNumber].rowId, kalignSubTask->resultMA.getRow(0).getGapModel(), os); CHECK_OP(os, res); } if (rows[rowNumber].sequenceId == settings->secondSequenceRef.entityId) { con.dbi->getMsaDbi()->updateGapModel(settings->msaRef.entityId, rows[rowNumber].rowId, kalignSubTask->resultMA.getRow(1).getGapModel(), os); CHECK_OP(os, res); } } } } return res; }
void AbstractAlignmentTaskSettings::setResultFileName(const QString& newFileName) { resultFileName = GUrl(newFileName); }
QVariant FileExtensionRelation::getAffectResult(const QVariant &influencingValue, const QVariant &dependentValue, DelegateTags * /*infTags*/, DelegateTags *depTags) const { QString newFormatId = influencingValue.toString(); DocumentFormat *newFormat = AppContext::getDocumentFormatRegistry()->getFormatById(newFormatId); updateDelegateTags(influencingValue, depTags); QString urlStr = dependentValue.toString(); if (urlStr.isEmpty()) { return ""; } QString extension; if (NULL == newFormat) { extension = newFormatId; } else { extension = newFormat->getSupportedDocumentFileExtensions().first(); } QString lastSuffix = GUrl(urlStr).lastFileSuffix(); bool withGz = false; if ("gz" == lastSuffix) { int dotPos = urlStr.length() - lastSuffix.length() - 1; if ((dotPos >= 0) && (QChar('.') == urlStr[dotPos])) { withGz = true; urlStr = urlStr.left(dotPos); lastSuffix = GUrl(urlStr).lastFileSuffix(); } } DocumentFormat *currentFormat = AppContext::getDocumentFormatRegistry()->selectFormatByFileExtension(lastSuffix); QString currentFormatId(""); if(currentFormat){ currentFormatId = currentFormat->getFormatId(); } bool foundExt = false; if (0 == QString::compare(lastSuffix, "csv", Qt::CaseInsensitive)) { foundExt = true; }else if (NULL == currentFormat) { foundExt = (lastSuffix == currentFormatId); } else { QStringList extensions(currentFormat->getSupportedDocumentFileExtensions()); if (NULL == newFormat) { extensions << newFormatId; } else { extensions << newFormat->getSupportedDocumentFileExtensions(); } foreach (QString supExt, extensions) { if (lastSuffix == supExt) { foundExt = true; break; } } } if (foundExt) { int dotPos = urlStr.length() - lastSuffix.length() - 1; if ((dotPos >= 0) && (QChar('.') == urlStr[dotPos])) { //yes, lastSuffix is a correct extension with . urlStr = urlStr.left(dotPos); } } urlStr += "." + extension; if (withGz) { urlStr += ".gz"; } return urlStr; }
SaveDocumentTask * TopHatSupportTask::createSaveTask(const QString &url, QPointer<Document> &doc, const QList<Workflow::SharedDbiDataHandler> &seqs) { DocumentFormat* docFormat = AppContext::getDocumentFormatRegistry()->getFormatById(BaseDocumentFormats::FASTQ); doc = docFormat->createNewLoadedDocument(IOAdapterUtils::get(BaseIOAdapters::LOCAL_FILE), GUrl(url), stateInfo); CHECK_OP(stateInfo, NULL); doc->setDocumentOwnsDbiResources(false); // Add all sequence objects to the document foreach (Workflow::SharedDbiDataHandler seqId, seqs) { U2SequenceObject* seqObj(Workflow::StorageUtils::getSequenceObject(settings.storage(), seqId)); if (NULL == seqObj) { stateInfo.setError(tr("An unexpected error has occurred during preparing the TopHat task!")); taskLog.trace(tr("Preparing TopHatSupportTask internal error: unable to get a sequence object!")); return NULL; } doc->addObject(seqObj); }
void MafftAddToAlignmentTask::prepare() { algoLog.info(tr("Align sequences to an existing alignment by MAFFT started")); MSAUtils::removeColumnsWithGaps(inputMsa, inputMsa->getNumRows()); tmpDirUrl = ExternalToolSupportUtils::createTmpDir("add_to_alignment", stateInfo); QString tmpAddedUrl = generateTmpFileUrl(tmpDirUrl + QDir::separator() + "XXXXXXXXXXXXXXXX_add.fa");; DocumentFormatRegistry *dfr = AppContext::getDocumentFormatRegistry(); DocumentFormat *dfd = dfr->getFormatById(BaseDocumentFormats::FASTA); Document* tempDocument = dfd->createNewLoadedDocument(IOAdapterUtils::get(BaseIOAdapters::LOCAL_FILE), GUrl(tmpAddedUrl), stateInfo); QListIterator<QString> namesIterator(settings.addedSequencesNames); int currentRowNumber = inputMsa->getNumRows(); foreach(const U2EntityRef& sequenceRef, settings.addedSequencesRefs) { uniqueIdsToNames[QString::number(currentRowNumber)] = namesIterator.next(); U2SequenceObject seqObject(QString::number(currentRowNumber), sequenceRef); GObject* cloned = seqObject.clone(tempDocument->getDbiRef(), stateInfo); CHECK_OP(stateInfo, ); cloned->setGObjectName(QString::number(currentRowNumber)); tempDocument->addObject(cloned); currentRowNumber++; } saveSequencesDocumentTask = new SaveDocumentTask(tempDocument, tempDocument->getIOAdapterFactory(), tmpAddedUrl, SaveDocFlags(SaveDoc_Roll) | SaveDoc_DestroyAfter | SaveDoc_ReduceLoggingLevel); addSubTask(saveSequencesDocumentTask); QString tmpExistingAlignmentUrl = generateTmpFileUrl(tmpDirUrl + QDir::separator() + "XXXXXXXXXXXXXXXX.fa"); saveAlignmentDocumentTask = new SaveMSA2SequencesTask(inputMsa, tmpExistingAlignmentUrl, false, BaseDocumentFormats::FASTA); addSubTask(saveAlignmentDocumentTask); }
foreach (const QString& url, shortReadList) { shortReadUrls.append(GUrl(env->getVar("COMMON_DATA_DIR") + "/" + url)); }