Пример #1
0
 static U2Feature loadStatic(SQLiteQuery* q) {
     U2Feature res;
     //class, type, parent, root, name, sequence, strand, start, len
     res.id = q->getDataId(0, U2Type::Feature);
     res.featureClass = static_cast<U2Feature::FeatureClass>(q->getInt32(1));
     res.featureType = static_cast<U2FeatureType>(q->getInt32(2));
     res.parentFeatureId = q->getDataId(3, U2Type::Feature);
     res.rootFeatureId = q->getDataId(4, U2Type::Feature);
     res.name = q->getString(5);
     res.sequenceId = q->getDataId(6, U2Type::Sequence);
     res.location.strand = U2Strand(U2Strand::Direction(q->getInt32(7)));
     res.location.region.startPos = q->getInt64(8);
     res.location.region.length= q->getInt64(9);
     return res;
 }
Пример #2
0
QList<Task *> SpideyAlignmentTask::onSubTaskFinished(Task *subTask) {
    QList<Task *> res;

    propagateSubtaskError();

    if (hasError() || isCanceled()) {
        return res;
    }

    if (subTask == prepareDataForSpideyTask) {
        SAFE_POINT(!prepareDataForSpideyTask->getResultPath().isEmpty(), "Invalid result path!",
            res);

        tmpOutputUrl = prepareDataForSpideyTask->getResultPath();
        const QStringList &arguments = prepareDataForSpideyTask->getArgumentsList();

        spideyTask = new ExternalToolRunTask(ET_SPIDEY, arguments, new SpideyLogParser());
        spideyTask->setSubtaskProgressWeight(95);
        res.append(spideyTask);
    } else if (subTask == spideyTask) {
        if (!QFile::exists(tmpOutputUrl)) {
            if (AppContext::getExternalToolRegistry()->getByName(ET_SPIDEY)->isValid()) {
                stateInfo.setError(tr("Output file not found"));
            } else {
                ExternalTool *spideyTool = AppContext::getExternalToolRegistry()->getByName(ET_SPIDEY);
                SAFE_POINT(NULL != spideyTool, "Invalid Spidey tool!", res);
                stateInfo.setError(
                    tr("Output file not found. May be %1 tool path '%2' not valid?")
                    .arg(spideyTool->getName()).arg(spideyTool->getPath()));
            }
            return res;
        }

        // parse result

        QFile resultFile(tmpOutputUrl);

        if (!resultFile.open(QFile::ReadOnly)) {
            setError(tr("Failed to open result file %1").arg(tmpOutputUrl));
            return res;
        }

        QTextStream inStream(&resultFile);
        bool strandDirect = true;

        U2Location location;
        location->op = U2LocationOperator_Join;

        while (!inStream.atEnd()) {
            QByteArray buf = inStream.readLine().toLatin1();
            if (buf.startsWith("Strand")) {
                strandDirect = buf.contains("plus");
            }
            if (buf.startsWith("Exon")) {
                // TODO: better to use reg exp here
                int startPos = buf.indexOf(":") + 1;
                int endPos = buf.indexOf("(gen)");
                if (startPos == -1 || endPos == -1) {
                    continue;
                }
                QByteArray loc = buf.mid(startPos, endPos - startPos).trimmed();
                QList<QByteArray> loci = loc.split('-');
                if (loci.size() < 2) {
                    continue;
                }
                int start = QString(loci.at(0)).toInt();
                int finish = QString(loci.at(1)).toInt();

                if (start == finish) {
                    continue;
                }

               location->regions.append(U2Region(start - 1, finish - start + 1));
            }
        }

        if (!location->isEmpty()) {
            SharedAnnotationData data(new AnnotationData);
            data->location = location;
            data->setStrand(U2Strand(strandDirect ? U2Strand::Direct : U2Strand::Complementary));
            data->type = U2FeatureTypes::Exon;
            data->name = "exon";
            U1AnnotationUtils::addDescriptionQualifier(data, annDescription);
            resultAnnotations.append(data);
        }
    }

    return res;
}