PluginSpec ModulesPluginDatabase::lookupProvides (std::string const & which) const { // check if plugin itself exists: if (status (PluginSpec (which)) == real) { return PluginSpec (which); } std::string errors; std::vector<std::string> allPlugins = listAllPlugins (); std::map<int, PluginSpec> foundPlugins; for (auto const & plugin : allPlugins) { // TODO: make sure (non)-equal plugins (i.e. with same/different contract) are handled correctly try { // TODO: support for generic plugins with config std::istringstream ss ( lookupInfo (PluginSpec (plugin, KeySet (5, *Key ("system/module", KEY_VALUE, "this plugin was loaded without a config", KEY_END), KS_END)), "provides")); std::string provide; while (ss >> provide) { if (provide == which) { int s = calculateStatus (lookupInfo ( PluginSpec (plugin, KeySet (5, *Key ("system/module", KEY_VALUE, "this plugin was loaded without a config", KEY_END), KS_END)), "status")); foundPlugins.insert (std::make_pair (s, PluginSpec (plugin))); } } } catch (std::exception const & e) { errors += e.what (); errors += ","; } // assume not loaded } if (foundPlugins.empty ()) { if (!errors.empty ()) throw NoPlugin ("No plugin that provides " + which + " could be found, got errors: " + errors); else throw NoPlugin ("No plugin that provides " + which + " could be found"); } // the largest element of the map contains the best-suited plugin: return foundPlugins.rbegin ()->second; }
std::map<int, PluginSpec> ModulesPluginDatabase::lookupAllProvidesWithStatus (std::string const & which) const { std::string errors; std::vector<std::string> allPlugins = listAllPlugins (); std::map<int, PluginSpec> foundPlugins; for (auto const & plugin : allPlugins) { // TODO: make sure (non)-equal plugins (i.e. with same/different contract) are handled correctly try { PluginSpec spec = PluginSpec ( plugin, KeySet (5, *Key ("system/module", KEY_VALUE, "this plugin was loaded without a config", KEY_END), KS_END)); // lets see if there is a plugin named after the required provider if (plugin == which) { int s = calculateStatus (lookupInfo (spec, "status")); foundPlugins.insert (std::make_pair (s, PluginSpec (plugin))); continue; // we are done with this plugin } // TODO: support for generic plugins with config std::istringstream ss (lookupInfo (spec, "provides")); std::string provide; while (ss >> provide) { if (provide == which) { int s = calculateStatus (lookupInfo (spec, "status")); foundPlugins.insert (std::make_pair (s, PluginSpec (plugin))); } } } catch (std::exception const & e) { errors += e.what (); errors += ","; } // assume not loaded } if (foundPlugins.empty ()) { if (!errors.empty ()) throw NoPlugin ("No plugin that provides " + which + " could be found, got errors: " + errors); else throw NoPlugin ("No plugin that provides " + which + " could be found"); } return foundPlugins; }
PluginSpec ModulesPluginDatabase::lookupMetadata (std::string const & which) const { std::vector<std::string> allPlugins = listAllPlugins (); std::map<int, PluginSpec> foundPlugins; std::string errors; // collect possible plugins for (auto const & plugin : allPlugins) { try { // TODO remove /module hack std::istringstream ss ( lookupInfo (PluginSpec (plugin, KeySet (5, *Key ("system/module", KEY_VALUE, "this plugin was loaded without a config", KEY_END), KS_END)), "metadata")); std::string metadata; while (ss >> metadata) { if (metadata == which) { int s = calculateStatus (lookupInfo ( PluginSpec (plugin, KeySet (5, *Key ("system/module", KEY_VALUE, "this plugin was loaded without a config", KEY_END), KS_END)), "status")); foundPlugins.insert (std::make_pair (s, PluginSpec (plugin))); break; } } } catch (std::exception const & e) { errors += e.what (); errors += ","; } // assume not loaded } if (foundPlugins.empty ()) { if (!errors.empty ()) throw NoPlugin ("No plugin that provides " + which + " could be found, got errors: " + errors); else throw NoPlugin ("No plugin that provides " + which + " could be found"); } // the largest element of the map contains the best-suited plugin: return foundPlugins.rbegin ()->second; }
void analyse(int start, int stop) { struct hash *hash; char line[512]; int lineCount = 0; char *words[32]; int wordCount; struct cdnaInfo *cdnaList = NULL; struct cdnaInfo *ci = NULL; int cdnaCount; int maxCdnaCount = stop - start; cdnaCount = 1; if (start > 1) { for (;;) { if (!fgets(line, sizeof(line), inFile)) errAbort("Not %d cDNAs in file, only %d\n", start, cdnaCount); ++lineCount; if (line[0] == '#') /* Skip comments. */ continue; wordCount = chopString(line, whiteSpaceChopper, words, ArraySize(words)); if (wordCount <= 0) /* Skip empty lines. */ continue; if (!differentWord(words[1], "alignments")) { ++cdnaCount; if (cdnaCount >= start) break; } } } cdnaCount = 0; hash = newHash(14); /* Hash table with 16k entries. */ for (;;) { if (!fgets(line, sizeof(line), inFile)) break; ++lineCount; if (line[0] == '#') /* Skip comments. */ continue; wordCount = chopString(line, whiteSpaceChopper, words, ArraySize(words)); if (wordCount <= 0) /* Skip empty lines. */ continue; if (wordCount < 4) /* Everyone else has at least four words. */ { errAbort("Short line %d:\n", lineCount); } if (sameWord(words[1], "Blasting")) { char *cdnaName = words[2]; if ((ci = lookupInfo(hash, cdnaName)) == NULL) { struct hashEl *hel; ci = needMem(sizeof(*ci)); hel = hashAdd(hash, cdnaName, ci); ci->next = cdnaList; cdnaList = ci; ci->ix = atoi(words[0]); ci->name = hel->name; } } else if (sameWord(words[2], "hits")) { /* Newer style - includes cDNA matching range. */ if (ci == NULL) continue; hitLine(ci, lineCount, words[0], words[1], words[3], words[4], words[5], words[9]); } else if (sameWord(words[1], "hits")) /* Older style - no cDNA matching range. */ { if (ci == NULL) continue; hitLine(ci, lineCount, words[0], NULL, words[2], words[3], words[4], words[8]); } else if (sameWord(words[1], "alignments")) { struct dnaSeq *cdnaSeq; struct wormCdnaInfo info; if (ci == NULL) continue; if (differentWord(ci->name, words[3])) errAbort("Line %d - %s is not %s", lineCount, words[3], ci->name); if (!ci->finished) { if (!anyCdnaSeq(ci->name, &cdnaSeq, &info)) { warn("Can't find cDNA %s", ci->name); ci->isDupe = TRUE; } else { ci->baseCount = cdnaSeq->size; ci->baseCrc = dnaCrc(cdnaSeq->dna, cdnaSeq->size); slReverse(&ci->roughAli); ci->roughScore = bestRoughScore(ci->roughAli); filterDupeCdna(ci, cdnaSeq); ci->isBackwards = (info.orientation == '-'); refineAlis(ci, cdnaSeq); ci->fineScore = bestFineScore(ci->fineAli); ci->isEmbryonic = info.isEmbryonic; ci->finished = TRUE; freeDnaSeq(&cdnaSeq); ++cdnaCount; if (cdnaCount >= maxCdnaCount) break; } } } else { errAbort("Can't deal with line %d\n", lineCount); } } slReverse(&cdnaList); doGoodBad(cdnaList); doUnusual(cdnaList); //makeCdnaToGene(cdnaList); /* Clean up. */ /* These two are slow and not really necessary. */ #ifdef FASTIDIOUS slFreeList(&cdnaList); freeHash(&hash); #endif uglyf("Done analyse\n"); }