int SampleActionsManager::getValidClickedActionId(U2OpStatus &os) const { QAction *a = qobject_cast<QAction*>(sender()); CHECK_EXT(NULL != a, os.setError(L10N::internalError("Unexpected method call")), -1); bool ok = false; int id = a->property(ID_PROPERTY).toInt(&ok); CHECK_EXT(ok, os.setError(L10N::internalError("Wrong action ID")), -1); CHECK_EXT(id >=0 && id < actions.size(), os.setError(L10N::internalError("Out of range action ID")), -1); return id; }
U2VariantTrack MysqlVariantDbi::getVariantTrack(const U2DataId& variantTrackId, U2OpStatus& os) { U2VariantTrack res; DBI_TYPE_CHECK(variantTrackId, U2Type::VariantTrack, os, res); MysqlTransaction t(db, os); Q_UNUSED(t); dbi->getMysqlObjectDbi()->getObject(res, variantTrackId, os); CHECK_OP(os, res); static const QString queryString = "SELECT sequence, sequenceName, trackType, fileHeader FROM VariantTrack WHERE object = :object"; U2SqlQuery q(queryString, db, os); q.bindDataId(":object", variantTrackId); if (q.step()) { res.sequence = q.getDataId(0, U2Type::Sequence); res.sequenceName = q.getString(1); int trackType = q.getInt32(2); CHECK_EXT(TrackType_FIRST <= trackType && trackType <= TrackType_LAST, os.setError(U2DbiL10n::tr("Invalid variant track type: %1").arg(trackType)), res); res.trackType = static_cast<VariantTrackType>(trackType); res.fileHeader = q.getString(3); q.ensureDone(); } return res; }
Document* FastqFormat::loadTextDocument(IOAdapter* io, const U2DbiRef& dbiRef, const QVariantMap& _hints, U2OpStatus& os) { CHECK_EXT(io != NULL && io->isOpen(), os.setError(L10N::badArgument("IO adapter")), NULL); QVariantMap hints = _hints; QList<GObject*> objects; QMap<QString, QString> skippedLines; int gapSize = qBound(-1, DocumentFormatUtils::getMergeGap(_hints), 1000*1000); int predictedSize = qMax(100*1000, DocumentFormatUtils::getMergedSize(hints, gapSize==-1 ? 0 : io->left())); QString lockReason; load(io, dbiRef, _hints, objects, os, gapSize, predictedSize, lockReason, skippedLines); if (skippedLines.size() > 0){ QMapIterator<QString, QString> i(skippedLines); QStringList errors; while (i.hasNext()) { i.next(); QString msg = i.key() + ": " + i.value(); if (objects.length() > 0){ os.addWarning(msg); }else{ errors.append(msg); } } if (errors.length() > 0){ os.setError(errors.join("\n")); } } CHECK_OP_EXT(os, qDeleteAll(objects), NULL); DocumentFormatUtils::updateFormatHints(objects, hints); Document* doc = new Document(this, io->getFactory(), io->getURL(), dbiRef, objects, hints, lockReason); return doc; }
QList<long> CmdlineTaskRunner::getChildrenProcesses(qint64 processId, bool fullTree) { QList<long> children; #if defined(Q_OS_LINUX) || defined(Q_OS_MAC) char *buff = NULL; size_t len = 255; char command[256] = {0}; sprintf(command,"ps -ef|awk '$3==%u {print $2}'", (unsigned)processId); FILE *fp = (FILE*) popen(command, "r"); while (getline(&buff, &len, fp) >= 0) { int child_process_id = QString(buff).toInt(); if (child_process_id != 0) { children << child_process_id; } } free(buff); fclose(fp); #elif defined(Q_OS_WIN) HANDLE hProcessSnap; HANDLE hProcess; PROCESSENTRY32 pe32; // Take a snapshot of all processes in the system. hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); CHECK(hProcessSnap != INVALID_HANDLE_VALUE, children); // Set the size of the structure before using it. pe32.dwSize = sizeof(PROCESSENTRY32); // Retrieve information about the first process, // and exit if unsuccessful CHECK_EXT(Process32First(hProcessSnap, &pe32), CloseHandle(hProcessSnap), children); // Now walk the snapshot of processes, and // display information about each process in turn do { if (pe32.th32ParentProcessID == processId) { hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID); if (hProcess != NULL) { CloseHandle(hProcess); children << pe32.th32ProcessID; } } } while (Process32Next(hProcessSnap, &pe32)); CloseHandle(hProcessSnap); #endif if (fullTree && children.length() > 0) { foreach(long child, children) { QList<long> children2 = getChildrenProcesses(child, fullTree); children << children2; }
Document* FpkmTrackingFormat::loadDocument(IOAdapter* io, const U2DbiRef& dbiRef, const QVariantMap& hints, U2OpStatus& os) { CHECK_EXT(io != NULL && io->isOpen(), os.setError(L10N::badArgument("IO adapter")), NULL); QList<GObject*> objects; load(io, objects, dbiRef, hints, os); CHECK_OP_EXT(os, qDeleteAll(objects), NULL); Document* doc = new Document(this, io->getFactory(), io->getURL(), dbiRef, objects); return doc; }
int readLongLine (QString &buffer, IOAdapter* io, QScopedArrayPointer<char> &charbuff, int readBufferSize, U2OpStatus& os) { int len; buffer.clear(); do { len = io->readLine(charbuff.data(), readBufferSize - 1); CHECK_EXT(!io->hasError(), os.setError(io->errorString()), -1); charbuff.data()[len] = '\0'; buffer.append(QString(charbuff.data())); } while (readBufferSize - 1 == len); return buffer.length(); }
int ImageWrite( struct ImageLibrary *im, File *rootDev, gdImagePtr img, const char *path ) { FHandler *fh = rootDev->f_FSys; File *rfp = (File *)fh->FileOpen( rootDev, path, "wb" ); if( rfp != NULL ) { char *buffer = NULL; int length = 0; int psize = strlen( path ); if( psize > 3 ) //we are checking if file have extension { char ext[ 4 ]; strcpy( ext, &(path[ psize-4 ]) ); ext[ 0 ] = toupper( ext[ 0 ] ); ext[ 1 ] = toupper( ext[ 1 ] ); ext[ 2 ] = toupper( ext[ 2 ] ); if( CHECK_EXT( ext, 'P','N','G' ) ) { buffer = gdImagePngPtr( img, &length ); }else if( CHECK_EXT( ext, 'J','P','G' ) ){ buffer = gdImageJpegPtr( img, &length, 100 ); }else if( CHECK_EXT( ext, 'G','I','F' ) ){ buffer = gdImageGifPtr( img, &length ); }else if( CHECK_EXT( ext, 'W','E','B' ) ){ buffer = gdImageWebpPtr( img, &length ); }else if( CHECK_EXT( ext, 'I','I','F' ) ){ buffer = gdImageTiffPtr( img, &length ); }else if( CHECK_EXT( ext, 'B','M','P' ) ){ buffer = gdImageBmpPtr( img, &length, 100 ); } if( buffer == NULL ) { fh->FileClose( rootDev, rfp ); ERROR("Cannot save picture, GD couldnt create buffer from image\n"); return 2; } else { fh->FileWrite( rfp, buffer, length ); } } else { ERROR("Extension name is too short, file format not recognized\n"); } fh->FileClose( rootDev, rfp ); } else { ERROR("Cannot open file: %s to write\n", path ); return 1; } return 0; }
Document* FastaFormat::loadTextDocument(IOAdapter* io, const U2DbiRef& dbiRef, const QVariantMap& fs, U2OpStatus& os) { CHECK_EXT(io!=NULL && io->isOpen(), os.setError(L10N::badArgument("IO adapter")), NULL); QList<GObject*> objects; int gapSize = qBound(-1, DocumentFormatUtils::getMergeGap(fs), 1000 * 1000); QString lockReason; load(io, dbiRef, fs, objects, gapSize, lockReason, os); CHECK_OP_EXT(os, qDeleteAll(objects), NULL); Document* doc = new Document(this, io->getFactory(), io->getURL(), dbiRef, objects, fs, lockReason); return doc; }
Task::ReportResult GTest_CompareTwoMsa::report() { Document *doc1 = getContext<Document>(this, docContextName); CHECK_EXT(NULL != doc1, setError(QString("document not found: %1").arg(docContextName)), ReportResult_Finished); const QList<GObject *> objs1 = doc1->getObjects(); CHECK_EXT(1 == objs1.size(), setError(QString("document '%1' contains several objects: the comparison not implemented").arg(docContextName)), ReportResult_Finished); MultipleSequenceAlignmentObject *msa1 = qobject_cast<MultipleSequenceAlignmentObject *>(objs1.first()); CHECK_EXT(NULL != msa1, setError(QString("document '%1' contains an incorrect object: expected '%2', got '%3'") .arg(docContextName) .arg(GObjectTypes::MULTIPLE_SEQUENCE_ALIGNMENT) .arg(objs1.first()->getGObjectType())), ReportResult_Finished); Document *doc2 = getContext<Document>(this, secondDocContextName); CHECK_EXT(NULL != doc2, setError(QString("document not found: %1").arg(secondDocContextName)), ReportResult_Finished); const QList<GObject *> objs2 = doc2->getObjects(); CHECK_EXT(1 == objs2.size(), setError(QString("document '%1' contains several objects: the comparison not implemented").arg(secondDocContextName)), ReportResult_Finished); MultipleSequenceAlignmentObject *msa2 = qobject_cast<MultipleSequenceAlignmentObject *>(objs2.first()); CHECK_EXT(NULL != msa2, setError(QString("document '%1' contains an incorrect object: expected '%2', got '%3'") .arg(secondDocContextName) .arg(GObjectTypes::MULTIPLE_SEQUENCE_ALIGNMENT) .arg(objs2.first()->getGObjectType())), ReportResult_Finished); const qint64 rowsNumber1 = msa1->getNumRows(); const qint64 rowsNumber2 = msa2->getNumRows(); CHECK_EXT(rowsNumber1 == rowsNumber2, setError(QString("The rows numbers differ: the object '%1' from the document '%2' contains %3 rows, the object '%4' from the document '%5' contains %6 rows") .arg(msa1->getGObjectName()) .arg(docContextName) .arg(rowsNumber1) .arg(msa2->getGObjectName()) .arg(secondDocContextName) .arg(rowsNumber2)), ReportResult_Finished); for (int i = 0; i < rowsNumber1; i++) { const MultipleSequenceAlignmentRow row1 = msa1->getMsaRow(i); const MultipleSequenceAlignmentRow row2 = msa2->getMsaRow(i); const bool areEqual = row1->isRowContentEqual(row2); CHECK_EXT(areEqual, setError(QString("The rows with number %1 differ from each other").arg(i)), ReportResult_Finished); } return ReportResult_Finished; }
Document* FastqFormat::loadDocument(IOAdapter* io, const U2DbiRef& dbiRef, const QVariantMap& _hints, U2OpStatus& os) { CHECK_EXT(io != NULL && io->isOpen(), os.setError(L10N::badArgument("IO adapter")), NULL); QVariantMap hints = _hints; QList<GObject*> objects; int gapSize = qBound(-1, DocumentFormatUtils::getMergeGap(_hints), 1000*1000); int predictedSize = qMax(100*1000, DocumentFormatUtils::getMergedSize(hints, gapSize==-1 ? 0 : io->left())); QString lockReason; load(io, dbiRef, _hints, io->getURL(), objects, os, gapSize, predictedSize, lockReason); CHECK_OP_EXT(os, qDeleteAll(objects), NULL); DocumentFormatUtils::updateFormatHints(objects, hints); Document* doc = new Document(this, io->getFactory(), io->getURL(), dbiRef, objects, hints, lockReason ); return doc; }
bool WevoteValidator::validateTaxonomy(const Actor *actor, NotificationsList ¬ificationList) 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; }
QList<Task*> AddExportedDocumentAndOpenViewTask::onSubTaskFinished( Task* subTask ) { QList<Task*> subTasks; if (subTask == exportTask && !subTask->hasError() && !subTask->isCanceled()) { Document* doc = exportTask->getDocument(); const GUrl& fullPath = doc->getURL(); Project* prj = AppContext::getProject(); if (prj) { Document* sameURLdoc = prj->findDocumentByURL(fullPath); if (sameURLdoc) { taskLog.trace(tr("Document is already added to the project %1").arg(doc->getURL().getURLString())); subTasks << new LoadUnloadedDocumentAndOpenViewTask(sameURLdoc); return subTasks; } } loadTask = LoadDocumentTask::getDefaultLoadDocTask(doc->getURL()); CHECK_EXT(NULL != loadTask, setError(tr("Can't create load task")), subTasks); subTasks << loadTask; } if (subTask == loadTask) { subTasks << new AddDocumentAndOpenViewTask(loadTask->takeDocument()); } //TODO: provide a report if subtask fails return subTasks; }
UdrRecordId getRecordId(UdrDbi *dbi, const U2DataId &objId, U2OpStatus &os) { const QList<UdrRecord> records = dbi->getObjectRecords(RawDataUdrSchema::ID, objId, os); CHECK_OP(os, UdrRecordId("", "")); CHECK_EXT(1 == records.size(), os.setError("Unexpected records count"), UdrRecordId("", "")); return records.first().getId(); }
Primer PrimerLibraryModel::getPrimer(const QModelIndex &index, U2OpStatus &os) const { CHECK_EXT(index.row() >= 0 && index.row() < primers.size(), os.setError(L10N::internalError("Incorrect primer number")), Primer()); return primers.at(index.row()); }