SequenceObjectContext::SequenceObjectContext (U2SequenceObject* obj, QObject* parent) : QObject(parent), seqObj(obj), aminoTT(NULL), complTT(NULL), selection(NULL), translations(NULL), visibleFrames(NULL), rowChoosed(false) { selection = new DNASequenceSelection(seqObj, this); clarifyAminoTT = false; const DNAAlphabet* al = getAlphabet(); if (al->isNucleic()) { DNATranslationRegistry* translationRegistry = AppContext::getDNATranslationRegistry(); complTT = GObjectUtils::findComplementTT(seqObj->getAlphabet()); aminoTT = GObjectUtils::findAminoTT(seqObj, true); clarifyAminoTT = aminoTT == NULL; QList<DNATranslation*> aminoTs = translationRegistry->lookupTranslation(al, DNATranslationType_NUCL_2_AMINO); if (!aminoTs.empty()) { aminoTT = aminoTT == NULL ? translationRegistry->getStandardGeneticCodeTranslation(al) : aminoTT; translations = new QActionGroup(this); foreach(DNATranslation* t, aminoTs) { QAction* a = translations->addAction(t->getTranslationName()); a->setObjectName(t->getTranslationName()); a->setCheckable(true); a->setChecked(aminoTT == t); a->setData(QVariant(t->getTranslationId())); connect(a, SIGNAL(triggered()), SLOT(sl_setAminoTranslation())); }
ImagePtr generateAtlas(RendererImpl& rendererImpl, const std::string& filePath, uint32_t letterSize, Letters& letters) { static const auto kBorderWidth = 1u, kBorderSize = kBorderWidth * 2; static const auto kSpaceFactor = 0.7f; Context context; if (!context.loadFont(filePath, letterSize)) return ImagePtr(); auto width = 0, height = 0, heightOffset = 0; auto x = (double)kBorderWidth, y = 0.0; for (auto c : getAlphabet()) { auto glyph = context.getGlyph(c); if (!glyph) continue; if (c != kSpaceSymbol) { height = std::max<int32_t>(height, glyph->bounds.y2 - glyph->bounds.y1); heightOffset = std::min(heightOffset, glyph->bounds.y1); } x += (c == kSpaceSymbol ? kSpaceFactor : 1.0f) * glyph->advance_x + kBorderSize; } width = (int32_t)ceil(x); height += -heightOffset + kBorderSize; x = kBorderWidth; y = -heightOffset + kBorderWidth; letters.clear(); Renderer renderer((uint32_t)width, (uint32_t)height); for (auto c : getAlphabet()) { auto glyph = context.getGlyph(c); if (!glyph) continue; if (c != kSpaceSymbol) context.renderGlyph(renderer, glyph, x, y); auto w = (c == kSpaceSymbol ? kSpaceFactor : 1.0f) * std::max(glyph->advance_x, (double)(glyph->bounds.x2 - glyph->bounds.x1)); letters[c] = Rect((int32_t)x, 0, (int32_t)(x + w), height); x += w + kBorderSize; } auto atlas = rendererImpl.makeImage( {(uint32_t)width, (uint32_t)height}, Image::Format::A, true); atlas->upload(Image::Bytes(renderer.data(), renderer.size())); return atlas; }
int writeESAToFile(char *pFileName, ESA esa, unsigned char *pExtraData, int nExtra) { FILE *f; f = fopen(pFileName, "w"); if(f == 0) { char st[512]; sprintf(st, "Could not open '%s' for writing.", pFileName); setError(st); return 0; } // Initialize file format structure struct ESAFileFormat ff; memset(&ff, 0, sizeof(struct ESAFileFormat)); strcpy(ff.ID, HEADERNAME); ff.major = MAJOR_VERSION; ff.minor = MINOR_VERSION; ff.size = esa->size; ff.alphabetSize = getAlphabetSize(esa); strncpy(ff.alphabet, getAlphabet(esa), getAlphabetSize(esa)); ff.ignoreAlphabetSize = getIgnoreAlphabetSize(esa); strncpy(ff.ignoreAlphabet, getIgnoreAlphabet(esa), getIgnoreAlphabetSize(esa)); if(pExtraData == NULL) { ff.nExtraData = -1; } else { ff.nExtraData = nExtra; } ff.reserved1 = 0; // Presently the reserved values are not used ff.reserved2 = 0; // Write header fwrite(&ff, sizeof(struct ESAFileFormat), 1, f); // Write translated string fwrite(esa->pStr, sizeof(unsigned char), ff.size+1, f); // Write array fwrite(esa->suf, sizeof(int), ff.size, f); fwrite(esa->lcp, sizeof(unsigned char), ff.size, f); // Possibly write extra data if(pExtraData != NULL) { fwrite(pExtraData, sizeof(unsigned char), nExtra, f); } fclose(f); return 1; }
int main() { puts("\n\n ----- Lab 3: Alphabet Recognition ----- "); puts(" ----- Author: Matt Hixon -----\n\n"); //get blocks int size = readBlocksFile(); //iterates through chars and counts which codeblock it belongs to recognizeAlphabet(size); //Finds the most common codeblock associated with text int alphaIndex = getAlphabet(size); //prints alphabet printf("\nAlphabet: %s\n\n\n", blocks[alphaIndex].name); //free memory in struc here before program ends }
void Kimura2Param::init() { // Requirement: alpha+2*beta<1. This block of code scales the // values so that this constrain holds, without changing the // ratio transitionP/transversionP: double alphaPlusTwoBeta=(transitionP+2*transversionP)/0.999; transitionP/=alphaPlusTwoBeta; transversionP/=alphaPlusTwoBeta; // Install values into matrix RateMatrix &self=*this; const Alphabet &alphabet=getAlphabet(); Symbol A=alphabet.lookup('A'); Symbol C=alphabet.lookup('C'); Symbol G=alphabet.lookup('G'); Symbol T=alphabet.lookup('T'); self(A,G)=self(G,A)=self(C,T)=self(T,C)=transitionP; self(A,C)=self(A,T)=self(C,A)=self(C,G)=self(G,T)=self(G,C)=self(T,A)= self(T,G)=transversionP; installDiagonals(); }
bool Context::loadFont(const std::string &filePath, uint32_t letterSize) { ASSERT(engine_.last_error() == 0); if (!engine_.load_font(filePath.c_str(), 0, agg::glyph_ren_native_gray8)) { setError(InvalidFontFile); return false; } engine_.hinting(false); if (engine_.height() != letterSize || engine_.width() != letterSize) { engine_.height(letterSize); engine_.width(letterSize); } for (auto c : getAlphabet()) { manager_.reset_last_glyph(); if (!manager_.glyph((uint32_t)c)) { setError(IncompleteFontFile); return false; } } return true; }