14 #define AW_RENAME_SKIP_GUI
24 #define ARB_GENE_REF "ARB_is_gene"
34 if (gberror) err = msg+
" (Reason: "+gberror+
")";
95 if (!organism_name)
throw DBerror();
100 UND_species.
add_name(organism_name);
114 const string& DBwriter::getUnreservedQualifier(
const string& qualifier) {
121 static string prefix =
"ORG_";
125 const char *reserved[] = {
127 "pos_start",
"pos_stop",
"pos_complement",
"pos_certain",
"pos_joined",
131 for (
int i = 0; reserved[i]; ++i) {
132 unreserve->trans[reserved[i]] = prefix+reserved[i];
136 TranslateMap::const_iterator found = unreserve->trans.find(qualifier);
137 if (found != unreserve->trans.end()) {
138 return found->second;
143 unreserve->trans[qualifier] = prefix+qualifier;
144 return unreserve->trans[qualifier];
153 generatedGenes.clear();
160 NameCounter::iterator existing = generatedGenes.find(gene_name);
161 if (existing == generatedGenes.end()) {
162 generatedGenes[gene_name] = 1;
174 if (type ==
"source") {
183 if (err)
throw DBerror(
"Failed to write location", err);
189 stringMapCIter e = qualifiers.end();
191 for (stringMapCIter i = qualifiers.begin(); i != e; ++i) {
192 const string& unreserved = getUnreservedQualifier(i->first);
201 if (!gb_data)
throw DBerror(
"Failed to create alignment");
204 if (err)
throw DBerror(
"Failed to write alignment", err);
210 NameCounter::iterator gg_end = generatedGenes.end();
211 for (NameCounter::iterator gg = generatedGenes.begin(); gg != gg_end; ++gg) {
212 if (gg->second > 1) renameCounter[gg->first] = 0;
215 NameCounter::iterator rc_end = renameCounter.end();
224 NameCounter::iterator rc = renameCounter.find(gene_name);
226 int maxOccurrences = generatedGenes[gene_name];
233 if (err)
throw DBerror(
"Failed to write to field 'name' (during gene-renumbering)", err);
250 inline bool operator<(
const GEN_positionPtr&
A,
const GEN_positionPtr& B) {
260 for (
int p = 0; p<a.
parts; ++p) {
274 mutable GEN_positionPtr pos;
297 bool hasType(
const char *
type)
const {
return strcmp(getType(), type) == 0; }
303 const char *description()
const {
304 return GBS_global_string(
"%zi-%zi (%i parts)", pos->start_pos[0], pos->stop_pos[pos->parts-1], pos->parts);
317 return !(a<b || b<a);
327 void DBwriter::hideUnwantedGenes() {
328 typedef vector<PosGene> Genes;
329 typedef Genes::iterator GeneIter;
335 gps.push_back(
PosGene(gb_gene));
338 sort(gps.begin(), gps.end());
341 GeneIter end = gps.end();
342 GeneIter p = gps.begin();
343 GeneIter firstEqual = p;
344 GeneIter lastEqual = p;
346 while (firstEqual != end) {
348 if (p != end && *p == *firstEqual) {
352 int count = lastEqual-firstEqual+1;
355 GeneIter equalEnd = lastEqual+1;
356 GeneIter gene = find_if(firstEqual, equalEnd,
hasType(
"gene"));
358 if (gene != equalEnd) {
359 bool hideGene =
false;
360 GeneIter e = firstEqual;
361 const char *gene_name = gene->getName();
363 while (e != equalEnd) {
365 e->addRefToGene(gene_name);
371 if (hideGene) gene->hide();
374 firstEqual = lastEqual = p;
384 stringMapCIter e = entries.end();
386 for (stringMapCIter i = entries.begin(); i != e; ++i) {
387 const string& content = i->second;
388 if (!content.empty()) {
399 stringSetIter e = refKeys.end();
400 for (stringSetIter i = refKeys.begin(); i != e; ++i) {
407 renumberDuplicateGenes();
408 testAndRemoveTranslations(importer);
411 else GB_warning(
"No genes have been written (missing feature table?)");
414 generatedGenes.clear();
void getKeys(stringSet &keys) const
bool operator()(const PosGene &pg)
void GB_warning(const char *message)
unsigned char * complement
const char * getName() const
void writeSequence(const SequenceBuffer &seqData)
static void deleteStaticData()
void writeFeature(const Feature &feature, long seqLength)
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
void GEN_free_position(GEN_position *pos)
GBDATA * GB_nextEntry(GBDATA *entry)
std::map< std::string, int > NameCounter
static ArbImporter * importer
const char * GBS_global_string(const char *templat,...)
static GBDATA * DB_create_byte_field(GBDATA *parent, const char *field, unsigned char content)
const GEN_positionPtr & getPosition() const
void finalizeOrganism(const MetaInfo &meta, const References &refs, Importer &importer)
char * AWTC_makeUniqueShortName(const char *prefix, UniqueNameDetector &existingNames)
void warning(const char *msg)
NOT4PERL GBDATA * GBT_add_data(GBDATA *species, const char *ali_name, const char *key, GB_TYPES type) __ATTR__DEPRECATED_TODO("better use GBT_create_sequence_data()")
GB_ERROR GB_await_error()
static void importerWarning(AW_CL cl_importer, const char *message)
GBDATA * GB_create_container(GBDATA *father, const char *key)
const stringMap & getQualifiers() const
GBDATA * GB_create(GBDATA *father, const char *key, GB_TYPES type)
CONSTEXPR_INLINE int digits(int parts)
void message(char *errortext)
void createOrganism(const string &flatfile, const char *importerTag)
static bool has_prefix(const std::string &s1, const std::string &s2)
GB_ERROR GEN_write_position(GBDATA *gb_gene, const GEN_position *pos, long seqLength)
GEN_position * create_GEN_position() const
map< string, string, NoCaseCmp > TranslateMap
std::string createGeneName() const
std::map< std::string, std::string > stringMap
const std::string & getType() const
void GB_write_flag(GBDATA *gbd, long flag)
void renumberDuplicateGenes()
void addRefToGene(const char *name_of_gene)
bool operator==(const PosGene &a, const PosGene &b)
GB_ERROR GB_write_byte(GBDATA *gbd, int i)
static GBDATA * DB_create_container(GBDATA *parent, const char *name, bool mark)
typedef SmartCustomPtr(GEN_position, GEN_free_position) GEN_positionPtr
static ARB_init_perl_interface init
void add_name(const char *name)
NOT4PERL void GB_dump(GBDATA *gbd)
static GBDATA * DB_create_string_field(GBDATA *parent, const char *field, const char *content)
const char * getSequence() const
std::set< std::string > stringSet
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
const Location & getLocation() const
bool hasType(const char *type) const
GEN_position * GEN_read_position(GBDATA *gb_gene)
GBDATA * GB_entry(GBDATA *father, const char *key)
GB_ERROR GEN_testAndRemoveTranslations(GBDATA *gb_gene_data, void(*warn)(AW_CL cd, const char *msg), AW_CL cd, AW_repeated_question *ok_to_ignore_wrong_start_codon)
const char * getType() const
std::string tagged_content(const std::string &refkey) const
bool operator<(const GEN_positionPtr &A, const GEN_positionPtr &B)