Changeset 972 for cpp/frams/genetics
- Timestamp:
- 07/03/20 00:32:23 (4 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/geno.cpp
r955 r972 24 24 } 25 25 26 bool 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 26 40 const SString Geno::INVALID_FORMAT = "invalid"; 27 41 const SString Geno::UNKNOWN_FORMAT = ""; 42 const SString Geno::F0_FORMAT_LIST = "0,0s"; 43 44 bool 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 } 28 54 29 55 void Geno::init(const SString& genstring, const SString& genformat, const SString& genname, const SString& comment) … … 41 67 { 42 68 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")) 44 70 return Geno::INVALID_FORMAT; 45 71 return format; … … 73 99 genformat = trimAndValidateFormat(genstring.substr(2)); 74 100 gencopy = ""; 75 mapinshift = genstring.len ();101 mapinshift = genstring.length(); 76 102 } 77 103 break; … … 88 114 genformat = trimAndValidateFormat(genstring.substr(2)); 89 115 gencopy = ""; 90 mapinshift = genstring.len ();116 mapinshift = genstring.length(); 91 117 } 92 118 break; … … 95 121 { 96 122 SString cut; 97 if (error_end < 0) error_end = genstring.len ();123 if (error_end < 0) error_end = genstring.length(); 98 124 static const int MAX_ERROR = 20; 99 125 if (error_end > MAX_ERROR) … … 104 130 if (lf >= 0) { if ((lf > 0) && (cut[lf - 1] == '\r')) lf--; cut = cut.substr(0, lf); } 105 131 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() : ""); 107 133 } 108 134 … … 212 238 int Geno::mapGenToString(int genpos) const 213 239 { 214 if (genpos > gen.len ()) return -2;240 if (genpos > gen.length()) return -2; 215 241 if (genpos < 0) return -1; 216 242 return mapinshift + genpos; … … 220 246 { 221 247 stringpos -= mapinshift; 222 if (stringpos > gen.len ()) return -2;248 if (stringpos > gen.length()) return -2; 223 249 if (stringpos < 0) return -1; 224 250 return stringpos; … … 232 258 int ModelGenoValidator::testGenoValidity(Geno& g) 233 259 { 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); 237 263 return mod.isValid(); 238 264 } … … 240 266 { 241 267 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); 243 269 if (converter_missing) 244 270 return -1;//no result … … 250 276 { 251 277 if (isvalid >= 0) return; 252 if (gen.len () == 0) { isvalid = 0; return; }278 if (gen.length() == 0) { isvalid = 0; return; } 253 279 if (format == INVALID_FORMAT) { isvalid = 0; return; } 254 280 Validators* vals = getValidators(); … … 309 335 } 310 336 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; }337 Geno 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; } 314 340 #ifndef NO_GENOCONVMANAGER 315 341 GenoConvManager *converters = getConverters(); 316 342 if (converters) 317 343 { 318 if (( otherformat == "0") && (!m) && (!using_checkpoints))344 if ((isF0Format(otherformat_list)) && (!m) && (!using_checkpoints)) 319 345 { 320 346 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)); 322 348 else 323 349 { … … 327 353 } 328 354 else 329 return converters->convert(*this, otherformat , m, using_checkpoints, converter_missing);355 return converters->convert(*this, otherformat_list, m, using_checkpoints, converter_missing); 330 356 } 331 357 #endif 332 358 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"); 334 360 } 335 361 -
cpp/frams/genetics/geno.h
r955 r972 129 129 static GenoConvManager* useConverters(GenoConvManager* gcm); 130 130 static GenoConvManager* getConverters(); 131 132 static bool formatIsOneOf(const SString& format, const SString& format_list); 133 static bool isF0Format(const SString& format_list); 134 static const SString F0_FORMAT_LIST; 131 135 }; 132 136 -
cpp/frams/genetics/genoconv.cpp
r955 r972 123 123 /// (can be NULL if you don't need this information) 124 124 125 GenoConverter **GenoConvManager::getPath(const SString& in , const SString& out, GenoConverter **path, int maxlen, int *mapavailable)125 GenoConverter **GenoConvManager::getPath(const SString& in_format, const SString& out_format_list, GenoConverter **path, int maxlen, int *mapavailable) 126 126 { 127 127 if (!maxlen) return 0; … … 130 130 for (; gk = (GenoConverter*)converters(i); i++) 131 131 { 132 if ((gk->enabled) && (gk->in_format == in ))132 if ((gk->enabled) && (gk->in_format == in_format)) 133 133 { 134 134 *path = gk; 135 if ( gk->out_format == out)135 if (Geno::formatIsOneOf(gk->out_format, out_format_list)) 136 136 { 137 137 if (mapavailable) … … 142 142 { 143 143 int mapavail; 144 GenoConverter **ret = getPath(gk->out_format, out , path + 1, maxlen - 1, &mapavail);144 GenoConverter **ret = getPath(gk->out_format, out_format_list, path + 1, maxlen - 1, &mapavail); 145 145 if (ret) 146 146 { … … 155 155 } 156 156 157 Geno GenoConvManager::convert(Geno &in, SString format, MultiMap *map, bool using_checkpoints, bool *converter_missing) 158 { 159 if (in.getFormat() == format) { if (converter_missing) *converter_missing = false; return in; } 157 Geno GenoConvManager::convert(Geno &in, SString format_list, MultiMap *map, bool using_checkpoints, bool *converter_missing) 158 { 159 if (Geno::formatIsOneOf(in.getFormat(), format_list)) 160 { 161 if (converter_missing) *converter_missing = false; return in; 162 } 160 163 GenoConverter *path[10]; 161 164 int dep; … … 164 167 int mapavail; 165 168 for (dep = 1; dep < (int)sizeof(path); dep++) //iterative deepening 166 if (ret = getPath(in.getFormat(), format , path, dep, &mapavail)) break;169 if (ret = getPath(in.getFormat(), format_list, path, dep, &mapavail)) break; 167 170 if (!ret) { if (converter_missing) *converter_missing = true; return Geno("", Geno::INVALID_FORMAT, "", "converter not found"); } 168 171 if (converter_missing) *converter_missing = false; 169 172 if (!map) mapavail = 0; 170 173 GenoConverter **t = path; 171 SString tmp ;174 SString tmp, out_format; 172 175 tmp = in.getGenes(); 173 176 MultiMap lastmap, tmpmap; … … 177 180 GenoConverter *gk = *t; 178 181 tmp = gk->convert(tmp, mapavail ? &tmpmap : 0, using_checkpoints); 179 if (!tmp.len()) 182 out_format = gk->out_format; 183 if (!tmp.length()) 180 184 { 181 185 string t = ssprintf("f%s->f%s conversion failed (%s)", gk->in_format.c_str(), gk->out_format.c_str(), gk->name); … … 200 204 if (map) 201 205 *map = lastmap; 202 return Geno(tmp, format, in.getName(), in.getComment());203 } 206 return Geno(tmp, out_format, in.getName(), in.getComment()); 207 } -
cpp/frams/genetics/genoconv.h
r955 r972 77 77 /// make a genotype in other format. genotype will be invalid 78 78 /// if GenoConvManager cannot convert it. 79 Geno convert(Geno &in, SString format , MultiMap *map = 0, bool using_checkpoints = false, bool *converter_missing = NULL);79 Geno convert(Geno &in, SString format_list, MultiMap *map = 0, bool using_checkpoints = false, bool *converter_missing = NULL); 80 80 /// register GenoConverter, the added object will be automatically deleted when GenoConvManager is destructed (call removeConverter() if this is not desirable) 81 81 void addConverter(GenoConverter *conv);
Note: See TracChangeset
for help on using the changeset viewer.