AssemblyNavigationWidget::AssemblyNavigationWidget(AssemblyBrowser *_browser, QWidget *p) : QWidget(p), browser(_browser), savableTab(this, GObjectViewUtils::findViewByName(_browser->getName())) { QVBoxLayout* mainLayout = new QVBoxLayout; mainLayout->setContentsMargins(0, 0, 0, 0); mainLayout->setAlignment(Qt::AlignTop); mainLayout->setSpacing(5); setLayout(mainLayout); U2OpStatus2Log os; qint64 modelLen = browser->getModel()->getModelLength(os); if(!os.isCoR()) { posSelector = new PositionSelector(this, 1, modelLen, false); connect(posSelector, SIGNAL(si_positionChanged(int)), browser, SLOT(sl_onPosChangeRequest(int))); posSelector->setContentsMargins(0,0,10,0); mainLayout->addWidget(new QLabel(tr("Enter position in assembly:"), this)); mainLayout->addWidget(posSelector); connect(browser, SIGNAL( si_zoomOperationPerformed() ), SLOT( sl_updateZoomingState() )); sl_updateZoomingState(); } CoveredRegionsLabel * coveredLabel = new CoveredRegionsLabel(browser, this); QWidget * coveredGroup = new ShowHideSubgroupWidget("COVERED", tr("Most Covered Regions"), coveredLabel, true); mainLayout->addWidget(coveredGroup); U2WidgetStateStorage::restoreWidgetState(savableTab); }
void DownloadRemoteFileDialog::accept() { defaultDB = getDBId(); QString resourceId = getResourceId(); if( resourceId.isEmpty() ) { QMessageBox::critical(this, L10N::errorTitle(), tr("Resource id is empty!")); ui->idLineEdit->setFocus(); return; } QString fullPath = getFullpath(); if( ui->saveFilenameLineEdit->text().isEmpty() ) { QMessageBox::critical(this, L10N::errorTitle(), tr("No folder selected for saving file!")); ui->saveFilenameLineEdit->setFocus(); return; } U2OpStatus2Log os; fullPath = GUrlUtils::prepareDirLocation(fullPath, os); if (fullPath.isEmpty()) { QMessageBox::critical(this, L10N::errorTitle(), os.getError()); ui->saveFilenameLineEdit->setFocus(); return; } QString dbId = getDBId(); QStringList resIds = resourceId.split(QRegExp("[\\s,;]+")); QList<Task*> tasks; QString fileFormat; if (ui->formatBox->count() > 0) { fileFormat = ui->formatBox->currentText(); } QVariantMap hints; hints.insert(FORCE_DOWNLOAD_SEQUENCE_HINT, ui->chbForceDownloadSequence->isVisible() && ui->chbForceDownloadSequence->isChecked()); int taskCount = 0; bool addToProject = ui->chbAddToProjectCheck->isChecked(); if (addToProject && resIds.size() >= 100) { QString message = tr("There are more than 100 files found for download.\nAre you sure you want to open all of them?"); int button = QMessageBox::question(QApplication::activeWindow(), tr("Warning"), message, tr("Cancel"), tr("Open anyway"), tr("Don't open")); if (button == 0) { return; // return to dialog } else if (button == 2) { addToProject = false; } } bool hasLoadOnlyDocuments = false; foreach (const QString &resId, resIds) { LoadRemoteDocumentMode mode = LoadRemoteDocumentMode_LoadOnly; if (addToProject) { mode = taskCount < OpenViewTask::MAX_DOC_NUMBER_TO_OPEN_VIEWS ? LoadRemoteDocumentMode_OpenView : LoadRemoteDocumentMode_AddToProject; } hasLoadOnlyDocuments = hasLoadOnlyDocuments || mode == LoadRemoteDocumentMode_LoadOnly; tasks.append(new LoadRemoteDocumentAndAddToProjectTask(resId, dbId, fullPath, fileFormat, hints, mode)); taskCount++; }
QList<GObject *> DbiDocumentFormat::prepareObjects(DbiConnection &handle, const QList<U2DataId> &objectIds) { QList<GObject *> objects; U2EntityRef ref; ref.dbiRef = handle.dbi->getDbiRef(); QMap<U2DataId, GObject*> match; foreach(const U2DataId &id, objectIds) { U2OpStatus2Log status; ref.entityId = id; U2Object object; handle.dbi->getObjectDbi()->getObject(object, id, status); CHECK_OPERATION(!status.isCoR(), continue); if (object.visualName.isEmpty()) { object.visualName = "Unnamed object"; } GObject *gobject = GObjectUtils::createObject(ref.dbiRef, id, object.visualName); CHECK_OPERATION(NULL != gobject, continue); match[id] = gobject; objects << gobject; }
void ExportProjectDialogController::accept(){ QString dirPath = exportFolderEdit->text(); projectFile = fixProjectFile(projectFileEdit->text()); U2OpStatus2Log os; exportDir = GUrlUtils::prepareDirLocation(dirPath, os); if (exportDir.isEmpty()) { assert(os.hasError()); QMessageBox::critical(this, this->windowTitle(), os.getError()); return; } QDialog::accept(); }
Task* CAP3Worker::tick() { U2OpStatus2Log os; if (input->hasMessage()) { Message inputMessage = getMessageAndSetupScriptValues(input); SAFE_POINT(!inputMessage.isEmpty(), "NULL message!", NULL); QVariantMap data = inputMessage.getData().toMap(); if (!data.contains(IN_URL_SLOT_ID)) { os.setError("CAP3 input slot is empty!"); return new FailTask(os.getError()); } QString dataset = data[BaseSlots::DATASET_SLOT().getId()].toString(); bool runCapForPreviousDataset = false; if (dataset != currentDatasetName) { if (!currentDatasetName.isEmpty()) { runCapForPreviousDataset = true; } settings.inputFiles = inputSeqUrls; inputSeqUrls.clear(); currentDatasetName = dataset; } inputSeqUrls << data.value(IN_URL_SLOT_ID).value<QString>(); if (runCapForPreviousDataset) { return runCap3(); } settings.inputFiles = inputSeqUrls; } else if (input->isEnded()) { if (!settings.inputFiles.isEmpty()) { return runCap3(); } else { datasetNumber = 0; setDone(); } } return NULL; }
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 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(); }
void ADVClipboard::copySequenceSelection(bool complement, bool amino) { ADVSequenceObjectContext* seqCtx = getSequenceContext(); if (seqCtx == NULL) { QMessageBox::critical(QApplication::activeWindow(), L10N::errorTitle(), "No sequence selected!"); return; } QString res; QVector<U2Region> regions = seqCtx->getSequenceSelection()->getSelectedRegions(); #ifdef UGENE_X86 int totalLen = 0; foreach (const U2Region& r, regions) { totalLen += r.length; } if (totalLen > MAX_COPY_SIZE_FOR_X86) { QMessageBox::critical(QApplication::activeWindow(), L10N::errorTitle(), COPY_FAILED_MESSAGE); return; } #endif if (!regions.isEmpty()) { U2SequenceObject* seqObj = seqCtx->getSequenceObject(); DNATranslation* complTT = complement ? seqCtx->getComplementTT() : NULL; DNATranslation* aminoTT = amino ? seqCtx->getAminoTT() : NULL; U2OpStatus2Log os; QList<QByteArray> seqParts = U2SequenceUtils::extractRegions(seqObj->getSequenceRef(), regions, complTT, aminoTT, false, os); if (os.hasError()) { QMessageBox::critical(QApplication::activeWindow(), L10N::errorTitle(), tr("An error occurred during getting sequence data: %1").arg(os.getError())); return; } if (seqParts.size() == 1) { putIntoClipboard(seqParts.first()); return; } res = U1SequenceUtils::joinRegions(seqParts); } putIntoClipboard(res); }
Task *ConservationPlotWorker::tick() { U2OpStatus2Log os; while (inChannel->hasMessage()) { Message m = getMessageAndSetupScriptValues(inChannel); QVariantMap data = m.getData().toMap(); if (!data.contains(ANNOT_SLOT_ID)) { os.setError("Annotations slot is empty"); return new FailTask(os.getError()); } plotData = StorageUtils::getAnnotationTableHandlers(data[ANNOT_SLOT_ID]); } if (!inChannel->isEnded()) { return NULL; } ConservationPlotSettings settings = createConservationPlotSettings(os); if (os.hasError()) { return new FailTask(os.getError()); } ConservationPlotTask* t = new ConservationPlotTask(settings, context->getDataStorage(), plotData); t->addListeners(createLogListeners()); connect(t, SIGNAL(si_stateChanged()), SLOT(sl_taskFinished())); return t; if (inChannel->isEnded()) { setDone(); } return NULL; }
bool StreamShortReadWriter::writeNextSequence(const U2SequenceObject *seq) { U2OpStatus2Log os; fastaFormat->storeSequence(seq, io, os); return !os.hasError(); }
QString AssemblyBrowser::tryAddObject(GObject * obj) { Document * objDoc = obj->getDocument(); SAFE_POINT(NULL != objDoc, "", tr("Internal error: only object with document can be added to browser")); if (GObjectTypes::SEQUENCE == obj->getGObjectType()) { U2SequenceObject * seqObj = qobject_cast<U2SequenceObject*>(obj); CHECK(NULL != seqObj, tr("Internal error: broken sequence object")); SAFE_POINT(NULL != objDoc->getDocumentFormat(), "", tr("Internal error: empty document format")); U2OpStatus2Log os; qint64 seqLen = seqObj->getSequenceLength(); QStringList errs; qint64 modelLen = model->getModelLength(os); if (seqLen != modelLen) { errs << tr("The lengths of the sequence and assembly are different."); } if (seqObj->getGObjectName() != gobject->getGObjectName()) { errs << tr("The sequence and assembly names are different."); } // commented: waiting for fix //QByteArray refMd5 = model->getReferenceMd5(); //if(!refMd5.isEmpty()) { // //QByteArray data = QString(seqObj->getSequence()).remove("-").toUpper().toUtf8(); // QByteArray data = QString(seqObj->getSequence()).toUpper().toUtf8(); // QByteArray seqObjMd5 = QCryptographicHash::hash(data, QCryptographicHash::Md5).toHex(); // if(seqObjMd5 != refMd5) { // errs << tr("- Reference MD5 not match with MD5 written in assembly"); // } //} bool setRef = !isAssemblyObjectLocked(true) && !model->isLoadingReference(); setRef &= model->checkPermissions(QFile::WriteUser, setRef); if(!errs.isEmpty() && setRef) { const NotificationStack *notificationStack = AppContext::getMainWindow()->getNotificationStack(); const QString message = tr("It seems that sequence \"%1\", set as reference to assembly \"%2\", does not match it.").arg(seqObj->getGObjectName()).arg(gobject->getGObjectName()) + "\n- " + errs.join("\n- "); notificationStack->addNotification(message, Warning_Not); } if(setRef) { model->setReference(seqObj); U2Assembly assembly = model->getAssembly(); U2DataId refId; QString folder; const QStringList folders = model->getDbiConnection().dbi->getObjectDbi()->getObjectFolders(assembly.id, os); if (folders.isEmpty() || os.isCoR()) { folder = U2ObjectDbi::ROOT_FOLDER; } else { folder = folders.first(); } if (seqObj->getEntityRef().dbiRef == model->getDbiConnection().dbi->getDbiRef()) { refId = seqObj->getEntityRef().entityId; } else { U2CrossDatabaseReferenceDbi * crossDbi = model->getDbiConnection().dbi->getCrossDatabaseReferenceDbi(); U2CrossDatabaseReference crossDbRef; // Cannot simply use seqObj->getSequenceRef(), since it points to a temporary dbi // TODO: make similar method seqObj->getPersistentSequenctRef() crossDbRef.dataRef.dbiRef.dbiId = objDoc->getURLString(); crossDbRef.dataRef.dbiRef.dbiFactoryId = "document"; crossDbRef.dataRef.entityId = seqObj->getGObjectName().toUtf8(); crossDbRef.visualName = "cross_database_reference: " + seqObj->getGObjectName(); crossDbRef.dataRef.version = 1; crossDbi->createCrossReference(crossDbRef, folder, os); LOG_OP(os); refId = crossDbRef.id; addObjectToView(obj); } model->associateWithReference(refId); } } else if (GObjectTypes::VARIANT_TRACK == obj->getGObjectType()) { VariantTrackObject *trackObj = qobject_cast<VariantTrackObject*>(obj); CHECK(NULL != trackObj, tr("Internal error: broken variant track object")); model->addTrackObject(trackObj); addObjectToView(obj); connect(model.data(), SIGNAL(si_trackRemoved(VariantTrackObject *)), SLOT(sl_trackRemoved(VariantTrackObject *))); } else {
/** * FASTQ format specification: http://maq.sourceforge.net/fastq.shtml */ static void load(IOAdapter* io, const U2DbiRef& dbiRef, const QVariantMap& hints, QList<GObject*>& objects, U2OpStatus& os, int gapSize, int predictedSize, QString& writeLockReason, QMap<QString, QString>& skippedLines) { DbiOperationsBlock opBlock(dbiRef, os); CHECK_OP(os, ); Q_UNUSED(opBlock); writeLockReason.clear(); bool merge = gapSize!=-1; QByteArray sequence; QByteArray qualityScores; QStringList headers; QSet<QString> uniqueNames; QVector<U2Region> mergedMapping; QByteArray gapSequence((merge ? gapSize : 0), 0); sequence.reserve(predictedSize); qualityScores.reserve(predictedSize); // for lower case annotations GObjectReference sequenceRef; qint64 sequenceStart = 0; U2SequenceImporter seqImporter(hints, true); const QString folder = hints.value(DocumentFormat::DBI_FOLDER_HINT, U2ObjectDbi::ROOT_FOLDER).toString(); int seqNumber = 0; int progressUpNum = 0; const int objectsCountLimit = hints.contains(DocumentReadingMode_MaxObjectsInDoc) ? hints[DocumentReadingMode_MaxObjectsInDoc].toInt() : -1; const bool settingsMakeUniqueName = !hints.value(DocumentReadingMode_DontMakeUniqueNames, false).toBool(); while (!os.isCoR()) { U2OpStatus2Log warningOs; //read header QString sequenceName = readSequenceName(warningOs, io, '@'); // check for eof while trying to read another FASTQ block if (io->isEof()) { if (io->hasError()) { os.setError(io->errorString()); } break; } if(errorLoggingBreak(warningOs, skippedLines, sequenceName)){ continue; } if(sequenceName.isEmpty()){ sequenceName = "Sequence"; } if ((merge == false) || (seqNumber == 0)) { QString objName = sequenceName; if (settingsMakeUniqueName) { objName = (merge) ? "Sequence" : TextUtils::variate(sequenceName, "_", uniqueNames); objName.squeeze(); uniqueNames.insert(objName); } seqImporter.startSequence(warningOs, dbiRef, folder, objName, false); if(errorLoggingBreak(warningOs, skippedLines, sequenceName)){ U2OpStatusImpl seqOs; seqImporter.finalizeSequenceAndValidate(seqOs); continue; } } //read sequence if (merge && sequence.length() > 0) { seqImporter.addDefaultSymbolsBlock(gapSize, warningOs); sequenceStart += sequence.length(); sequenceStart+=gapSize; if(errorLoggingBreak(warningOs, skippedLines, sequenceName)){ U2OpStatusImpl seqOs; seqImporter.finalizeSequenceAndValidate(seqOs); continue; } } sequence.clear(); readSequence(warningOs, io, sequence); if(errorLoggingBreak(warningOs, skippedLines, sequenceName)){ U2OpStatusImpl seqOs; seqImporter.finalizeSequenceAndValidate(seqOs); continue; } MemoryLocker lSequence(os, qCeil(sequence.size()/(1000*1000))); CHECK_OP_BREAK(os); Q_UNUSED(lSequence); seqImporter.addBlock(sequence.data(),sequence.length(), warningOs); if(errorLoggingBreak(warningOs, skippedLines, sequenceName)){ U2OpStatusImpl seqOs; seqImporter.finalizeSequenceAndValidate(seqOs); continue; } QString qualSequenceName = readSequenceName(warningOs, io, '+'); if (!qualSequenceName.isEmpty()) { if (sequenceName != qualSequenceName){ warningOs.setError(U2::FastqFormat::tr("Sequence name differs from quality scores name: %1 and %2").arg(sequenceName).arg(qualSequenceName)); } if(errorLoggingBreak(warningOs, skippedLines, sequenceName)){ U2OpStatusImpl seqOs; seqImporter.finalizeSequenceAndValidate(seqOs); continue; } } // read qualities qualityScores.clear(); readQuality(warningOs, io, qualityScores, sequence.size()); if(errorLoggingBreak(warningOs, skippedLines, sequenceName)){ U2OpStatusImpl seqOs; seqImporter.finalizeSequenceAndValidate(seqOs); continue; } if(sequence.length() != qualityScores.length()){ warningOs.setError(U2::FastqFormat::tr("Bad quality scores: inconsistent size.")); } if(errorLoggingBreak(warningOs, skippedLines, sequenceName)){ U2OpStatusImpl seqOs; seqImporter.finalizeSequenceAndValidate(seqOs); continue; } seqNumber++; progressUpNum++; if (merge) { headers.append(sequenceName); mergedMapping.append(U2Region(sequenceStart, sequence.length() )); } else { if (objectsCountLimit > 0 && objects.size() >= objectsCountLimit) { os.setError(FastqFormat::tr("File \"%1\" contains too many sequences to be displayed. " "However, you can process these data using instruments from the menu <i>Tools -> NGS data analysis</i> " "or pipelines built with Workflow Designer.") .arg(io->getURL().getURLString())); break; } U2Sequence u2seq = seqImporter.finalizeSequenceAndValidate(warningOs); if(errorLoggingBreak(warningOs, skippedLines, sequenceName)){ continue; } sequenceRef = GObjectReference(io->getURL().getURLString(), u2seq.visualName, GObjectTypes::SEQUENCE, U2EntityRef(dbiRef, u2seq.id)); U2SequenceObject* seqObj = new U2SequenceObject(u2seq.visualName, U2EntityRef(dbiRef, u2seq.id)); CHECK_EXT_BREAK(seqObj != NULL, os.setError("U2SequenceObject is NULL")); seqObj->setQuality(DNAQuality(qualityScores)); objects << seqObj; U1AnnotationUtils::addAnnotations(objects, seqImporter.getCaseAnnotations(), sequenceRef, NULL, hints); } if (PROGRESS_UPDATE_STEP == progressUpNum) { progressUpNum = 0; os.setProgress(io->getProgress()); } } CHECK_OP_EXT(os, qDeleteAll(objects); objects.clear(), ); bool emptyObjects = objects.isEmpty(); CHECK_EXT(!emptyObjects || merge, os.setError(Document::tr("Document is empty.")), ); SAFE_POINT(headers.size() == mergedMapping.size(), "headers <-> regions mapping failed!", ); if (!merge) { return; } U2Sequence u2seq = seqImporter.finalizeSequenceAndValidate(os); CHECK_OP(os,); sequenceRef = GObjectReference(io->getURL().getURLString(), u2seq.visualName, GObjectTypes::SEQUENCE, U2EntityRef(dbiRef, u2seq.id)); U1AnnotationUtils::addAnnotations(objects, seqImporter.getCaseAnnotations(), sequenceRef, NULL, hints); objects << new U2SequenceObject(u2seq.visualName, U2EntityRef(dbiRef, u2seq.id)); objects << DocumentFormatUtils::addAnnotationsForMergedU2Sequence(sequenceRef, dbiRef, headers, mergedMapping, hints); if (headers.size() > 1) { writeLockReason = QObject::tr("Document sequences were merged"); } }