void GCFramePlotAlgorithm::calculate(QVector<float>& res, U2SequenceObject* o, const U2Region& vr, const GSequenceGraphWindowData* d, U2OpStatus &os) { assert(d!=NULL); int nSteps = GSequenceGraphUtils::getNumSteps(vr, d->window, d->step); res.reserve(nSteps); const QByteArray &seq = getSequenceData(o, os); CHECK_OP(os, ); int startPos = vr.startPos; windowStrategyWithoutMemorize(res, seq, startPos, d, nSteps, os); }
void EntropyGraphAlgorithm::calculate(QVector<float>& res, U2SequenceObject* o, const U2Region& vr, const GSequenceGraphWindowData* d, U2OpStatus &os) { assert(d!=NULL); int nSteps = GSequenceGraphUtils::getNumSteps(vr, d->window, d->step); res.reserve(nSteps); const QByteArray &seq = getSequenceData(o, os); CHECK_OP(os, ); const DNAAlphabet* al = o->getAlphabet(); // prepare index -> TODO: make it once and cache! IndexedMapping3To1<int> index(al->getAlphabetChars(), 0); int* mapData = index.mapData(); int indexSize = index.getMapSize(); // algorithm float log10_2 = log10(2.0); const char* seqStr = seq.constData(); for (int i = 0; i < nSteps; i++) { int start = vr.startPos + i * d->step; int end = start + d->window; for (int x = start; x < end-2; x++) { int& val = index.mapNC(seqStr + x); val++; } //derive entropy from triplets and zero them float total = end-start-2; float ent = 0; for (int j = 0; j < indexSize; j++) { CHECK_OP(os, ); int ifreq = mapData[j]; if (ifreq == 0) { continue; } mapData[j] = 0; //zero triplets float freq = ifreq / total; ent -= freq*log10(freq)/log10_2; } res.append(ent); } }