Ignore:
Timestamp:
07/03/20 00:32:23 (4 years ago)
Author:
Maciej Komosinski
Message:
  • separate "0" and "0s" formats (for SHAPE_BALL_AND_STICK and SHAPE_SOLIDS, respectively)
  • converting to format list (Geno::F0_FORMAT_LIST = "0,0s")
  • (optional) declaring Model as SHAPE_BALL_AND_STICK or SHAPE_SOLIDS (or SHAPE_UNKNOWN)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/genetics/geno.cpp

    r955 r972  
    2424}
    2525
     26bool Geno::formatIsOneOf(const SString& format, const SString& format_list)
     27{
     28        if (strchr(format_list.c_str(), ',') == NULL)
     29                return format == format_list;
     30        else
     31        {
     32                SString item; int pos = 0;
     33                while (format_list.getNextToken(pos, item, ','))
     34                        if (item == format)
     35                                return true;
     36        }
     37        return false;
     38}
     39
    2640const SString Geno::INVALID_FORMAT = "invalid";
    2741const SString Geno::UNKNOWN_FORMAT = "";
     42const SString Geno::F0_FORMAT_LIST = "0,0s";
     43
     44bool Geno::isF0Format(const SString& format_list)
     45{
     46        if (strchr(format_list.c_str(), ',') == NULL)
     47                return formatIsOneOf(format_list, F0_FORMAT_LIST);
     48        SString item; int pos = 0;
     49        while (format_list.getNextToken(pos, item, ','))
     50                if (!formatIsOneOf(item, F0_FORMAT_LIST))
     51                        return false;
     52        return true;
     53}
    2854
    2955void Geno::init(const SString& genstring, const SString& genformat, const SString& genname, const SString& comment)
     
    4167{
    4268        SString format = trim(input);
    43         if (format.len() == 0 || strContainsOneOf(format.c_str(), " \r\n\t"))
     69        if (format.length() == 0 || strContainsOneOf(format.c_str(), " \r\n\t"))
    4470                return Geno::INVALID_FORMAT;
    4571        return format;
     
    7399                                        genformat = trimAndValidateFormat(genstring.substr(2));
    74100                                        gencopy = "";
    75                                         mapinshift = genstring.len();
     101                                        mapinshift = genstring.length();
    76102                                }
    77103                                break;
     
    88114                                        genformat = trimAndValidateFormat(genstring.substr(2));
    89115                                        gencopy = "";
    90                                         mapinshift = genstring.len();
     116                                        mapinshift = genstring.length();
    91117                                }
    92118                                break;
     
    95121                        {
    96122                                SString cut;
    97                                 if (error_end < 0) error_end = genstring.len();
     123                                if (error_end < 0) error_end = genstring.length();
    98124                                static const int MAX_ERROR = 20;
    99125                                if (error_end > MAX_ERROR)
     
    104130                                if (lf >= 0) { if ((lf > 0) && (cut[lf - 1] == '\r')) lf--; cut = cut.substr(0, lf); }
    105131                                sstringQuote(cut);
    106                                 logPrintf("Geno", "init", LOG_ERROR, "Invalid genotype format declaration: '%s'%s", cut.c_str(), name.len() ? SString::sprintf(" in '%s'", name.c_str()).c_str() : "");
     132                                logPrintf("Geno", "init", LOG_ERROR, "Invalid genotype format declaration: '%s'%s", cut.c_str(), name.length() ? SString::sprintf(" in '%s'", name.c_str()).c_str() : "");
    107133                        }
    108134
     
    212238int Geno::mapGenToString(int genpos) const
    213239{
    214         if (genpos > gen.len()) return -2;
     240        if (genpos > gen.length()) return -2;
    215241        if (genpos < 0) return -1;
    216242        return mapinshift + genpos;
     
    220246{
    221247        stringpos -= mapinshift;
    222         if (stringpos > gen.len()) return -2;
     248        if (stringpos > gen.length()) return -2;
    223249        if (stringpos < 0) return -1;
    224250        return stringpos;
     
    232258int ModelGenoValidator::testGenoValidity(Geno& g)
    233259{
    234         if (g.getFormat() == "0")
    235         {
    236                 Model mod(g);
     260        if (Geno::formatIsOneOf(g.getFormat(), Geno::F0_FORMAT_LIST))
     261        {
     262                Model mod(g, Model::SHAPE_UNKNOWN);
    237263                return mod.isValid();
    238264        }
     
    240266        {
    241267                bool converter_missing;
    242                 Geno f0geno = g.getConverted("0", NULL, false, &converter_missing);
     268                Geno f0geno = g.getConverted(Geno::F0_FORMAT_LIST, NULL, false, &converter_missing);
    243269                if (converter_missing)
    244270                        return -1;//no result
     
    250276{
    251277        if (isvalid >= 0) return;
    252         if (gen.len() == 0) { isvalid = 0; return; }
     278        if (gen.length() == 0) { isvalid = 0; return; }
    253279        if (format == INVALID_FORMAT) { isvalid = 0; return; }
    254280        Validators* vals = getValidators();
     
    309335}
    310336
    311 Geno Geno::getConverted(SString otherformat, MultiMap *m, bool using_checkpoints, bool *converter_missing)
    312 {
    313         if (otherformat == getFormat()) { if (converter_missing) *converter_missing = false; return *this; }
     337Geno Geno::getConverted(SString otherformat_list, MultiMap *m, bool using_checkpoints, bool *converter_missing)
     338{
     339        if (formatIsOneOf(getFormat(), otherformat_list)) { if (converter_missing) *converter_missing = false; return *this; }
    314340#ifndef NO_GENOCONVMANAGER
    315341        GenoConvManager *converters = getConverters();
    316342        if (converters)
    317343        {
    318                 if ((otherformat == "0") && (!m) && (!using_checkpoints))
     344                if ((isF0Format(otherformat_list)) && (!m) && (!using_checkpoints))
    319345                {
    320346                        if (!f0gen)
    321                                 f0gen = new Geno(converters->convert(*this, otherformat, NULL, using_checkpoints, converter_missing));
     347                                f0gen = new Geno(converters->convert(*this, otherformat_list, NULL, using_checkpoints, converter_missing));
    322348                        else
    323349                        {
     
    327353                }
    328354                else
    329                         return converters->convert(*this, otherformat, m, using_checkpoints, converter_missing);
     355                        return converters->convert(*this, otherformat_list, m, using_checkpoints, converter_missing);
    330356        }
    331357#endif
    332358        if (converter_missing) *converter_missing = true;
    333         return (otherformat == getFormat()) ? *this : Geno("", "", "", "GenConvManager not available");
     359        return (formatIsOneOf(getFormat(), otherformat_list)) ? *this : Geno("", "", "", "GenConvManager not available");
    334360}
    335361
Note: See TracChangeset for help on using the changeset viewer.