Beispiel #1
0
QList<U2MsaRow> MAlignmentExporter::exportRows( const U2DataId &msaId, const QList<qint64> rowIds,
    U2OpStatus &os ) const
{
    U2MsaDbi* msaDbi = con.dbi->getMsaDbi( );
    SAFE_POINT( NULL != msaDbi, NULL_MSA_DBI_ERROR, QList<U2MsaRow>( ) );
    QList<U2MsaRow> result;
    foreach ( qint64 rowId, rowIds ) {
        result.append( msaDbi->getRow( msaId, rowId, os) );
        SAFE_POINT_OP( os, QList<U2MsaRow>( ) );
    }
Task::ReportResult SimpleAddToAlignmentTask::report() {
    CHECK(!hasError() && !isCanceled(), ReportResult_Finished);
    U2UseCommonUserModStep modStep(settings.msaRef, stateInfo);
    CHECK_OP(stateInfo, ReportResult_Finished);
    U2MsaDbi *dbi = modStep.getDbi()->getMsaDbi();
    int posInMsa = inputMsa->getNumRows();


    dbi->updateMsaAlphabet(settings.msaRef.entityId, settings.alphabet, stateInfo);
    CHECK_OP(stateInfo, ReportResult_Finished);
    QListIterator<QString> namesIterator(settings.addedSequencesNames);

    const QList<qint64> rowsIds = inputMsa->getRowsIds();
    const U2MsaListGapModel msaGapModel = inputMsa->getGapModel();
    for (int i = 0; i < inputMsa->getNumRows(); i++) {
        MaDbiUtils::updateRowGapModel(settings.msaRef, rowsIds[i], msaGapModel[i], stateInfo);
        CHECK_OP(stateInfo, ReportResult_Finished);
    }

    foreach(const U2EntityRef& sequence, settings.addedSequencesRefs) {
        QString seqName = namesIterator.peekNext();
        U2SequenceObject seqObject(seqName, sequence);
        U2MsaRow row = MSAUtils::copyRowFromSequence(&seqObject, settings.msaRef.dbiRef, stateInfo);
        CHECK_OP(stateInfo, ReportResult_Finished);
        dbi->addRow(settings.msaRef.entityId, posInMsa, row, stateInfo);
        CHECK_OP(stateInfo, ReportResult_Finished);
        posInMsa++;

        if(sequencePositions.contains(seqName) && sequencePositions[seqName] > 0) {
            QList<U2MsaGap> gapModel;
            gapModel << U2MsaGap(0, sequencePositions[seqName]);
            dbi->updateGapModel(settings.msaRef.entityId, row.rowId, gapModel, stateInfo);
        }
        namesIterator.next();
    }

    MsaDbiUtils::trim(settings.msaRef, stateInfo);
    CHECK_OP(stateInfo, ReportResult_Finished);

    return ReportResult_Finished;
}
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, setTrackModType) {
    U2OpStatusImpl os;
    U2MsaDbi *msaDbi = SQLiteObjectDbiTestData::getMsaDbi();
    SQLiteObjectDbi *objectDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();

    // Create alignment 1
    U2DataId msaId1 = msaDbi->createMsaObject("", "Test name 1", BaseDNAAlphabetIds::NUCL_DNA_DEFAULT(), os);
    CHECK_NO_ERROR(os);
    Utils::addRow(msaDbi->getRootDbi(), msaId1, "1", "ACGTACGT", QList<U2MsaGap>(), os);
    CHECK_NO_ERROR(os);
    QList<U2MsaRow> rows1 = msaDbi->getRows(msaId1, os);
    CHECK_NO_ERROR(os);

    // Create alignment 2
    U2DataId msaId2 = msaDbi->createMsaObject("", "Test name 2", BaseDNAAlphabetIds::NUCL_DNA_DEFAULT(), os);
    CHECK_NO_ERROR(os);
    Utils::addRow(msaDbi->getRootDbi(), msaId2, "2", "CCCCCCC", QList<U2MsaGap>(), os);
    CHECK_NO_ERROR(os);
    QList<U2MsaRow> rows2 = msaDbi->getRows(msaId2, os);
    CHECK_NO_ERROR(os);

    // Change mod track 1
    objectDbi->setTrackModType(msaId1, TrackOnUpdate, os);
    CHECK_NO_ERROR(os);

    U2TrackModType newType1_1 = objectDbi->getTrackModType(rows1[0].sequenceId, os);
    CHECK_EQUAL(TrackOnUpdate, newType1_1, "new mod track type 1_1");

    U2TrackModType newType1_2 = objectDbi->getTrackModType(rows2[0].sequenceId, os);
    CHECK_EQUAL(NoTrack, newType1_2, "new mod track type 1_2");

    // Change mod track 2
    objectDbi->setTrackModType(msaId1, NoTrack, os);
    CHECK_NO_ERROR(os);
    objectDbi->setTrackModType(msaId2, TrackOnUpdate, os);
    CHECK_NO_ERROR(os);

    U2TrackModType newType2_1 = objectDbi->getTrackModType(rows1[0].sequenceId, os);
    CHECK_EQUAL(NoTrack, newType2_1, "new mod track type 2_1");

    U2TrackModType newType2_2 = objectDbi->getTrackModType(rows2[0].sequenceId, os);
    CHECK_EQUAL(TrackOnUpdate, newType2_2, "new mod track type 2_2");
}
Beispiel #4
0
QList<U2MsaRow> MAlignmentExporter::exportRows(const U2DataId& msaId, U2OpStatus& os) const {
    U2MsaDbi* msaDbi = con.dbi->getMsaDbi();
    SAFE_POINT(NULL != msaDbi, NULL_MSA_DBI_ERROR, QList<U2MsaRow>());

    return msaDbi->getRows(msaId, os);
}
IMPLEMENT_TEST(SQLiteObjectDbiUnitTests, removeMsaObject) {
    U2OpStatusImpl os;
    U2MsaDbi* msaDbi = SQLiteObjectDbiTestData::getMsaDbi();

    // FIRST ALIGNMENT
    // Create an alignment
    U2DataId msaId = msaDbi->createMsaObject("", "Test name", BaseDNAAlphabetIds::NUCL_DNA_DEFAULT(), os);
    CHECK_NO_ERROR(os);

    // Add alignment info
    U2StringAttribute attr(msaId, "MSA1 info key", "MSA1 info value");
    U2AttributeDbi* attrDbi = SQLiteObjectDbiTestData::getAttributeDbi();
    attrDbi->createStringAttribute(attr, os);
    CHECK_NO_ERROR(os);

    // Create sequences
    U2SequenceDbi* sequenceDbi = SQLiteObjectDbiTestData::getSequenceDbi();
    U2Sequence seq1;
    U2Sequence seq2;
    sequenceDbi->createSequenceObject(seq1, "", os);
    CHECK_NO_ERROR(os);
    sequenceDbi->createSequenceObject(seq2, "", os);
    CHECK_NO_ERROR(os);

    // Add rows
    U2MsaRow row1;
    row1.rowId = 0;
    row1.sequenceId = seq1.id;
    row1.gstart = 0;
    row1.gend = 5;

    U2MsaGap row1gap1(0, 2);
    U2MsaGap row1gap2(3, 1);
    QList<U2MsaGap> row1gaps;
    row1gaps << row1gap1 << row1gap2;

    row1.gaps = row1gaps;

    U2MsaRow row2;
    row2.rowId = 1;
    row2.sequenceId = seq2.id;
    row2.gstart = 2;
    row2.gend = 4;

    U2MsaGap row2gap(1, 2);
    QList<U2MsaGap> row2gaps;
    row2gaps << row2gap;

    row2.gaps = row2gaps;

    QList<U2MsaRow> rows;
    rows << row1 << row2;

    msaDbi->addRows(msaId, rows, os);
    CHECK_NO_ERROR(os);

    // SECOND ALIGNMENT
    // Create an alignment
    U2DataId msaId2 = msaDbi->createMsaObject("", "Test name 2", BaseDNAAlphabetIds::AMINO_DEFAULT(), os);
    CHECK_NO_ERROR(os);

    // Add alignment info
    U2StringAttribute attr2(msaId2, "MSA2 info key", "MSA2 info value");
    attrDbi->createStringAttribute(attr2, os);
    CHECK_NO_ERROR(os);

    // Create sequences
    U2Sequence al2Seq;
    sequenceDbi->createSequenceObject(al2Seq, "", os);
    CHECK_NO_ERROR(os);

    // Add rows
    U2MsaRow al2Row;
    al2Row.rowId = 0;
    al2Row.sequenceId = al2Seq.id;
    al2Row.gstart = 0;
    al2Row.gend = 15;

    U2MsaGap al2RowGap(1, 12);
    QList<U2MsaGap> al2RowGaps;
    al2RowGaps << al2RowGap;

    al2Row.gaps = al2RowGaps;

    QList<U2MsaRow> al2Rows;
    al2Rows << al2Row;

    msaDbi->addRows(msaId2, al2Rows, os);
    CHECK_NO_ERROR(os);

    // REMOVE THE FIRST ALIGNMENT OBJECT
    SQLiteObjectDbi* sqliteObjectDbi = SQLiteObjectDbiTestData::getSQLiteObjectDbi();
    sqliteObjectDbi->removeObject(msaId, os);

    // VERIFY THAT THERE IS ONLY THE SECOND ALIGNMENT'S RECORDS LEFT IN TABLES
    SQLiteDbi* sqliteDbi = SQLiteObjectDbiTestData::getSQLiteDbi();

    // "Attribute"
    SQLiteReadQuery qAttr("SELECT COUNT(*) FROM Attribute WHERE name = ?1", sqliteDbi->getDbRef(), os);
    qAttr.bindString(1, "MSA1 info key");
    qint64 msa1AttrNum = qAttr.selectInt64();
    CHECK_EQUAL(0, msa1AttrNum, "MSA1 attributes number");

    qAttr.reset(true);
    qAttr.bindString(1, "MSA2 info key");
    qint64 msa2AttrNum = qAttr.selectInt64();
    CHECK_EQUAL(1, msa2AttrNum, "MSA2 attributes number");

    // "StringAttribute"
    SQLiteReadQuery qStringAttr("SELECT COUNT(*) FROM StringAttribute WHERE value = ?1", sqliteDbi->getDbRef(), os);
    qStringAttr.bindString(1, "MSA1 info value");
    qint64 msa1StrAttrNum = qStringAttr.selectInt64();
    CHECK_EQUAL(0, msa1StrAttrNum, "MSA1 string attributes number");

    qStringAttr.reset(true);
    qStringAttr.bindString(1, "MSA2 info value");
    qint64 msa2StrAttrNum = qStringAttr.selectInt64();
    CHECK_EQUAL(1, msa2StrAttrNum, "MSA2 string attributes number");

    // "MsaRow"
    SQLiteReadQuery qMsaRow("SELECT COUNT(*) FROM MsaRow WHERE msa = ?1", sqliteDbi->getDbRef(), os);
    qMsaRow.bindDataId(1, msaId);
    qint64 msa1Rows = qMsaRow.selectInt64();
    CHECK_EQUAL(0, msa1Rows, "number of rows in MSA1");

    qMsaRow.reset(true);
    qMsaRow.bindDataId(1, msaId2);
    qint64 msa2Rows = qMsaRow.selectInt64();
    CHECK_EQUAL(1, msa2Rows, "number of rows in MSA2");

    // "MsaRowGap"
    SQLiteReadQuery qMsaRowGap("SELECT COUNT(*) FROM MsaRowGap WHERE msa = ?1", sqliteDbi->getDbRef(), os);
    qMsaRowGap.bindDataId(1, msaId);
    qint64 msa1Gaps = qMsaRowGap.selectInt64();
    CHECK_EQUAL(0, msa1Gaps, "number of gaps in MSA1 rows");

    qMsaRowGap.reset(true);
    qMsaRowGap.bindDataId(1, msaId2);
    qint64 msa2Gaps = qMsaRowGap.selectInt64();
    CHECK_EQUAL(1, msa2Gaps, "number of gaps in MSA2 rows");

    // "Sequence"
    SQLiteReadQuery qSeq("SELECT COUNT(*) FROM Sequence WHERE object = ?1", sqliteDbi->getDbRef(), os);
    qSeq.bindDataId(1, seq1.id);
    qint64 msa1seq1 = qSeq.selectInt64();
    CHECK_EQUAL(0, msa1seq1, "seq1 of msa1");

    qSeq.reset(true);
    qSeq.bindDataId(1, seq2.id);
    qint64 msa1seq2 = qSeq.selectInt64();
    CHECK_EQUAL(0, msa1seq2, "seq2 of msa1");

    qSeq.reset(true);
    qSeq.bindDataId(1, al2Seq.id);
    qint64 msa2seq = qSeq.selectInt64();
    CHECK_EQUAL(1, msa2seq, "seq of msa2");

    // "Msa"
    SQLiteReadQuery qMsa("SELECT COUNT(*) FROM Msa WHERE object = ?1", sqliteDbi->getDbRef(), os);
    qMsa.bindDataId(1, msaId);
    qint64 msa1records = qMsa.selectInt64();
    CHECK_EQUAL(0, msa1records, "number of MSA1 records");

    qMsa.reset(true);
    qMsa.bindDataId(1, msaId2);
    qint64 msa2records = qMsa.selectInt64();
    CHECK_EQUAL(1, msa2records, "number of MSA2 records");

    // "Object"
    SQLiteReadQuery qObj("SELECT COUNT(*) FROM Object WHERE id = ?1", sqliteDbi->getDbRef(), os);
    qObj.bindDataId(1, msaId);
    qint64 msa1objects = qObj.selectInt64();
    CHECK_EQUAL(0, msa1objects, "number of MSA1 objects");

    qObj.reset(true);
    qObj.bindDataId(1, msaId2);
    qint64 msa2objects = qObj.selectInt64();
    CHECK_EQUAL(1, msa2objects, "number of MSA2 objects");

    // Remove the second alignment
    sqliteObjectDbi->removeObject(msaId2, os);
}