Task::ReportResult GTest_DNASequenceQualityScores::report() {

    GObject *obj = getContext<GObject>(this, objContextName);
    if(obj==NULL){
        stateInfo.setError(QString("wrong value: %1").arg(OBJ_ATTR));
        return ReportResult_Finished;
    }

    U2SequenceObject * mySequence = qobject_cast<U2SequenceObject*>(obj);
    if(mySequence==NULL){
        stateInfo.setError(QString("Can't cast to sequence from: %1").arg(obj->getGObjectName()));
        return ReportResult_Finished;
    }

    const DNAQuality& quality = mySequence->getQuality();
    if (quality.isEmpty()) {
        stateInfo.setError("Sequence doesn't have quality scores");
        return ReportResult_Finished;
    }

    if (quality.qualCodes != qualityScores) {
        stateInfo.setError( QString("Quality scores are not valid! The score is %1, expected %2").arg(quality.qualCodes.constData()).arg(qualityScores.constData()));
        return ReportResult_Finished;
    }

    return ReportResult_Finished;
}
Task::ReportResult GTest_DNAMulSequenceQuality::report() {
    GObject *obj = getContext<GObject>(this,objContextName);
    if (obj==NULL) {
        stateInfo.setError(QString("wrong object name: %1").arg(objContextName));
        return ReportResult_Finished;
    }

    MAlignmentObject* myMSequence= qobject_cast<MAlignmentObject*>(obj);
    if(myMSequence==NULL){
        stateInfo.setError(QString("Can not cast to alignment from: %1").arg(obj->getGObjectName()));
        return ReportResult_Finished;
    }

    bool ok_flag=false;
    foreach(const MAlignmentRow& myItem , myMSequence->getMAlignment().getRows()){
        if (myItem.getName() == seqName){
            ok_flag = true;
            //QByteArray qualityCodes = myItem.getCoreQuality().qualCodes;
            //if (qualityCodes != expectedQuality){
            //    stateInfo.setError(
            //        QString("Quality scores are not valid! The score is %1, expected %2").arg(qualityCodes.constData()).arg(expectedQuality.constData())
            //        );
            //    return ReportResult_Finished;
            //}
        }
    }
    if(!ok_flag){
        stateInfo.setError(QString("Sequence %1 is not found in the alignment").arg(seqName));
    }
    return ReportResult_Finished;

}
Task::ReportResult GTest_DNASequencePart::report() {
    GObject *obj = getContext<GObject>(this,objContextName);
    if (obj==NULL) {
        stateInfo.setError(QString("wrong value: %1").arg(OBJ_ATTR));
        return ReportResult_Finished;
    }

    U2SequenceObject * objSequence = qobject_cast<U2SequenceObject*>(obj);
    if (objSequence==NULL) {
        stateInfo.setError(QString("can't cast to sequence from: %1").arg(obj->getGObjectName()));
        return ReportResult_Finished;
    }
    if (objSequence->getSequenceLength() < startPos + subseq.length()) {
        stateInfo.setError(QString("sequence size is less that region end: size=%1, region-end=%2, objectName=%3").arg(objSequence->getSequenceLength()).arg(startPos + subseq.length()).arg(obj->getGObjectName()));
        return ReportResult_Finished;
    }
    QByteArray objSubSeq = objSequence->getSequenceData(U2Region(startPos, subseq.length()));
    if (!objSequence->getAlphabet()->isCaseSensitive()) {
        subseq = subseq.toUpper();
    }
    if (objSubSeq != subseq){
        stateInfo.setError(QString("region not matched: %1, expected %2").arg(objSubSeq.constData()).arg(subseq.constData()));
        return ReportResult_Finished;
    }
    return ReportResult_Finished;
}
Task::ReportResult GTest_DNASequenceQualityValue::report() {

    GObject *obj = getContext<GObject>(this, objContextName);
    if(obj==NULL){
        stateInfo.setError(QString("wrong value: %1").arg(OBJ_ATTR));
        return ReportResult_Finished;
    }

    U2SequenceObject * mySequence = qobject_cast<U2SequenceObject*>(obj);
    if(mySequence==NULL){
        stateInfo.setError(QString("Can't cast to sequence from: %1").arg(obj->getGObjectName()));
        return ReportResult_Finished;
    }

    const DNAQuality& quality = mySequence->getQuality();
    if ( (pos < 0) || (pos > quality.qualCodes.count() - 1 )  ) {
        stateInfo.setError(QString("Quality scores doesn't have position %1").arg(pos));
        return ReportResult_Finished;
    }

    int val = quality.getValue(pos);

    if (val != expectedVal) {
        stateInfo.setError( QString("Quality score values do not match! The score is %1, expected %2").arg(val).arg(expectedVal));
        return ReportResult_Finished;
    }

    return ReportResult_Finished;
}
Task::ReportResult GTest_DNASequencInMulSequence::report() {
    GObject *obj = getContext<GObject>(this, objContextName);
    if(obj==NULL){
        stateInfo.setError(QString("wrong value: %1").arg(OBJ_ATTR));
        return ReportResult_Finished;
    }

    MAlignmentObject* myMSequence= qobject_cast<MAlignmentObject*>(obj);
    if(myMSequence==NULL){
        stateInfo.setError(QString("can't cast to sequence from: %1").arg(obj->getGObjectName()));
        return ReportResult_Finished;
    }
    int tempSize=myMSequence->getNumRows();
    if (tempSize != seqInMSeq){
        stateInfo.setError(QString("numbers of Sequence not match: %1, expected %2 ").arg(tempSize).arg(seqInMSeq));
    }
    return ReportResult_Finished;
}
Task::ReportResult GTest_DNASequenceSize::report() {
    GObject *obj = getContext<GObject>(this, objContextName);
    if(obj==NULL){
        stateInfo.setError(QString("wrong value: %1").arg(OBJ_ATTR));
        return ReportResult_Finished;
    }

    U2SequenceObject * mySequence = qobject_cast<U2SequenceObject*>(obj);
    if(mySequence==NULL){
        stateInfo.setError(QString("can't cast to sequence from: %1").arg(obj->getGObjectName()));
        return ReportResult_Finished;
    }
    int tempLength=mySequence->getSequenceLength();
    if (tempLength != seqSize){
        stateInfo.setError(QString("sequence size not matched: %1, expected %2 ").arg(tempLength).arg(seqSize));
    }
    return ReportResult_Finished;
}
Task::ReportResult GTest_DNAMulSequenceAlphabetId::report() {
    GObject *obj = getContext<GObject>(this, objContextName);
    if(obj==NULL){
        stateInfo.setError(QString("wrong value: %1").arg(OBJ_ATTR));
        return ReportResult_Finished;
    }

    MAlignmentObject* myMSequence= qobject_cast<MAlignmentObject*>(obj);
    if(myMSequence==NULL){
        stateInfo.setError(QString("can't cast to sequence from: %1").arg(obj->getGObjectName()));
        return ReportResult_Finished;
    }
    const DNAAlphabet *tempAlphabet = myMSequence->getAlphabet();
    if( tempAlphabet->getId() != alpId){
        stateInfo.setError(QString("Alphabet id not matched: %1 expected %2").arg(tempAlphabet->getId()).arg(alpId));
    }
    return ReportResult_Finished;
}
Task::ReportResult GTest_DNATranslation3to1Test::report() {
    GObject *obj = getContext<GObject>(this, objContextName);
    if (obj==NULL){
        stateInfo.setError(QString("wrong value: %1").arg(OBJ_ATTR));
        return ReportResult_Finished;
    }

    U2SequenceObject * mySequence = qobject_cast<U2SequenceObject*>(obj);
    if(mySequence==NULL){
        stateInfo.setError(QString("error can't cast to sequence from: %1").arg(obj->getGObjectName()));
        return ReportResult_Finished;
    }
    if(!(mySequence->getAlphabet()->isNucleic())){
        stateInfo.setError(QString("error Alphabet is not Nucleic: %1").arg(mySequence->getAlphabet()->getId()));
        return ReportResult_Finished;
    }

    DNATranslation* aminoTransl = 0;

    DNATranslationRegistry* tr = AppContext::getDNATranslationRegistry();

    QList<DNATranslation*> aminoTs = tr->lookupTranslation(mySequence->getAlphabet(), DNATranslationType_NUCL_2_AMINO);
    if (!aminoTs.empty()) {
        aminoTransl = tr->getStandardGeneticCodeTranslation(mySequence->getAlphabet());
    }
    int tempValue;
    if(strTo == -1){
        tempValue=-1;
    } else{
        tempValue=(strTo-strFrom+1);
    }
    QByteArray myByteArray = mySequence->getSequenceData(U2Region(strFrom,tempValue));
    QByteArray rezult(myByteArray.length() / 3, 0);
    int n = aminoTransl->translate(myByteArray, myByteArray.length(), rezult.data(), rezult.length());
    assert(n == rezult.length()); Q_UNUSED(n);

    if(rezult != stringValue.toLatin1()){
        stateInfo.setError(QString("translated sequence not matched: %1, expected %2 ").arg(rezult.data()).arg(stringValue));
        return ReportResult_Finished;
    }
    return ReportResult_Finished;
}
Task::ReportResult GTest_DNAMulSequencePart::report() {
    GObject *obj = getContext<GObject>(this,objContextName);
    if (obj==NULL) {
        stateInfo.setError(QString("wrong value: %1").arg(OBJ_ATTR));
        return ReportResult_Finished;
    }

    MAlignmentObject* myMSequence= qobject_cast<MAlignmentObject*>(obj);
    if(myMSequence==NULL){
        stateInfo.setError(QString("can't cast to sequence from: %1").arg(obj->getGObjectName()));
        return ReportResult_Finished;
    }

    if (myMSequence->getLength() < startPos + subseq.length()) {
        stateInfo.setError(QString("sequence size is less that region end: size=%1, region-end=%").arg(myMSequence->getLength(), startPos + subseq.length()));
        return ReportResult_Finished;
    }

    if (!myMSequence->getAlphabet()->isCaseSensitive()) {
        subseq = subseq.toUpper();
    }
    bool ok_flag=false;
    U2OpStatus2Log os;
    const MAlignment ma = myMSequence->getMAlignment();
    foreach(const MAlignmentRow& myItem , ma.getRows()){
        if (myItem.getName() == seqName){
            ok_flag=true;
            QByteArray objSubSeq = myItem.mid(startPos, subseq.length(), os).toByteArray(subseq.length(), os);
            if (objSubSeq != subseq){
                stateInfo.setError(QString("region not matched: %1, expected %2").arg(objSubSeq.constData()).arg(subseq.constData()));
                return ReportResult_Finished;
            }
        }
    }
    if(!ok_flag){
        stateInfo.setError(QString("no Sequence name: %1").arg(seqName));
    }
    return ReportResult_Finished;

}
void GTest_CalculateTreeFromAligment::prepare() {

    GObject *obj = getContext<GObject>(this, objContextName);
    if(obj==NULL){
        stateInfo.setError(QString("wrong value: %1").arg(objContextName));
        return;
    }

    MultipleSequenceAlignmentObject* maObj = qobject_cast<MultipleSequenceAlignmentObject*>(obj);
    if(maObj==NULL){
        stateInfo.setError(QString("can't cast to multimple alignment object from: %1").arg(obj->getGObjectName()));
        return;
    }

    CreatePhyTreeSettings settings;
    settings.algorithmId = algName;
    settings.mb_ngen = 1000;
    settings.mrBayesSettingsScript = QString("Begin MrBayes;\n"
        "lset Nst=2 rates=gamma ngammacat=4;\n"
        "mcmc ngen=1000 samplefreq=100 printfreq=1000 nchains=4 temp=0.4 savebrlens=yes "
        "startingtree=random seed=10;\n"
        "sumt burnin=10;\n"
        "End;\n");

    task = new PhyTreeGeneratorLauncherTask(maObj->getMultipleAlignment(), settings);

    if (task == NULL) {
        stateInfo.setError(QString("Algorithm %1 not found").arg(algName));
        return;
    }
    addSubTask(task);
}
Task::ReportResult GTest_CompareTreesInTwoObjects::report() {
    Document* doc = getContext<Document>(this, docContextName);
    if (doc == NULL) {
        stateInfo.setError(QString("document not found %1").arg(docContextName));
        return ReportResult_Finished;
    }
    Document* doc2 = getContext<Document>(this, secondDocContextName);
    if (doc2 == NULL) {
        stateInfo.setError(QString("document not found %1").arg(secondDocContextName));
        return ReportResult_Finished;
    }

    const QList<GObject*>& objs = doc->getObjects();
    const QList<GObject*>& objs2 = doc2->getObjects();
    for (int i = 0; i < objs.size() && i < objs2.size(); ++i){
        GObject *obj = objs.at(i), *obj2 = objs2.at(i);
        PhyTreeObject *treeObj = NULL, *treeObj2 = NULL;
        if (obj->getGObjectType() == GObjectTypes::PHYLOGENETIC_TREE){
            treeObj = qobject_cast<PhyTreeObject*>(obj);
        }
        if (obj2->getGObjectType() == GObjectTypes::PHYLOGENETIC_TREE){
            treeObj2 = qobject_cast<PhyTreeObject*>(obj2);
        }
        if (treeObj == NULL){
            stateInfo.setError(QString("can't cast to tree from: %1 in position %2").arg(obj->getGObjectName()).arg(i));
            return ReportResult_Finished;
        }
        if (treeObj2 == NULL){
            stateInfo.setError(QString("can't cast to tree from: %1 in position %2").arg(obj2->getGObjectName()).arg(i));
            return ReportResult_Finished;
        }

        if (!PhyTreeObject::treesAreAlike(treeObj->getTree(), treeObj2->getTree())) {
            stateInfo.setError(QString("trees in position %1 are different").arg(i));
            return ReportResult_Finished;
        }
    }

    return ReportResult_Finished;
}