Changeset 972 for cpp/frams/genetics/geno.cpp
- Timestamp:
- 07/03/20 00:32:23 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified 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
Note: See TracChangeset
for help on using the changeset viewer.