Changeset 522 for cpp/frams/genetics
- Timestamp:
- 06/23/16 00:15:59 (9 years ago)
- Location:
- cpp/frams/genetics
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/genetics/defgenoconv.h
r286 r522 9 9 10 10 /// This GenoConvManager subclass allows you to add all "standard" converters in one go 11 class DefaultGenoConvManager : public GenoConvManager11 class DefaultGenoConvManager : public GenoConvManager 12 12 { 13 14 void addDefaultConverters();///< add all converters configured in gen-config file13 public: 14 void addDefaultConverters();///< add all converters configured in gen-config file 15 15 }; 16 16 -
cpp/frams/genetics/geno.cpp
r521 r522 12 12 THREAD_LOCAL_DEF_PTR(GenoConvManager, geno_converters); 13 13 14 Geno::Validators* Geno::getValidators() { return tlsGetPtr(geno_validators);}15 GenoConvManager* Geno::getConverters() { return tlsGetPtr(geno_converters);}14 Geno::Validators* Geno::getValidators() { return tlsGetPtr(geno_validators); } 15 GenoConvManager* Geno::getConverters() { return tlsGetPtr(geno_converters); } 16 16 17 17 Geno::Validators* Geno::useValidators(Validators* val) 18 {return tlsSetPtr(geno_validators,val);} 18 { 19 return tlsSetPtr(geno_validators, val); 20 } 19 21 GenoConvManager* Geno::useConverters(GenoConvManager* gcm) 20 {return tlsSetPtr(geno_converters,gcm);} 22 { 23 return tlsSetPtr(geno_converters, gcm); 24 } 21 25 22 26 void Geno::init(const SString& genstring, char genformat, const SString& genname, const SString& comment) … … 34 38 if (genstring.charAt(0) == '/') 35 39 { 36 int end, error_end =-1;40 int end, error_end = -1; 37 41 switch (genstring.charAt(1)) 38 42 { 39 43 case '/': 40 44 genformat = genstring.charAt(2); 41 if ((genformat =='\0')||isspace(genformat))42 genformat =INVALID_FORMAT;45 if ((genformat == '\0') || isspace(genformat)) 46 genformat = INVALID_FORMAT; 43 47 if ((end = genstring.indexOf('\n')) >= 0) 44 48 { 45 error_end =end;46 if (end !=3) genformat=INVALID_FORMAT;49 error_end = end; 50 if (end != 3) genformat = INVALID_FORMAT; 47 51 gencopy = genstring.substr(end + 1); 48 52 mapinshift = end + 1; … … 50 54 else 51 55 { 52 if (genstring.len() !=3) genformat=INVALID_FORMAT;56 if (genstring.len() != 3) genformat = INVALID_FORMAT; 53 57 gencopy = 0; 54 58 mapinshift = genstring.len(); … … 57 61 case '*': 58 62 genformat = genstring.charAt(2); 59 if ((genformat =='\0')||isspace(genformat))60 genformat =INVALID_FORMAT;63 if ((genformat == '\0') || isspace(genformat)) 64 genformat = INVALID_FORMAT; 61 65 if ((end = genstring.indexOf("*/")) >= 0) 62 66 { 63 error_end =end+2;64 if (end !=3) genformat=INVALID_FORMAT;67 error_end = end + 2; 68 if (end != 3) genformat = INVALID_FORMAT; 65 69 gencopy = genstring.substr(end + 2); 66 70 mapinshift = end + 2; … … 68 72 else 69 73 { 70 if (genstring.len() !=5) genformat=INVALID_FORMAT;74 if (genstring.len() != 5) genformat = INVALID_FORMAT; 71 75 gencopy = 0; 72 76 mapinshift = genstring.len(); … … 74 78 break; 75 79 } 76 if (genformat==INVALID_FORMAT)80 if (genformat == INVALID_FORMAT) 77 81 { 78 SString cut;79 if (error_end<0) error_end=genstring.len();80 static const int MAX_ERROR=20;81 if (error_end>MAX_ERROR)82 cut=genstring.substr(0,MAX_ERROR)+"...";83 else84 cut=genstring.substr(0,error_end);85 int lf=cut.indexOf('\n');86 if (lf>=0) cut=cut.substr(0,lf);87 logPrintf("Geno","init",LOG_ERROR,"Invalid genotype format declaration: '%s'%s",cut.c_str(),genname.len()?SString::sprintf(" in '%s'",genname.c_str()).c_str():"");82 SString cut; 83 if (error_end<0) error_end = genstring.len(); 84 static const int MAX_ERROR = 20; 85 if (error_end>MAX_ERROR) 86 cut = genstring.substr(0, MAX_ERROR) + "..."; 87 else 88 cut = genstring.substr(0, error_end); 89 int lf = cut.indexOf('\n'); 90 if (lf >= 0) cut = cut.substr(0, lf); 91 logPrintf("Geno", "init", LOG_ERROR, "Invalid genotype format declaration: '%s'%s", cut.c_str(), genname.len() ? SString::sprintf(" in '%s'", genname.c_str()).c_str() : ""); 88 92 } 89 93 … … 115 119 116 120 Geno::Geno(const Geno& src) 117 :gen(src.gen), name(src.name), format(src.format), txt(src.txt), isvalid(src.isvalid),118 f0gen(0), mapinshift(src.mapinshift), mapoutshift(src.mapinshift),119 multiline(src.multiline), owner(0)121 :gen(src.gen), name(src.name), format(src.format), txt(src.txt), isvalid(src.isvalid), 122 f0gen(0), mapinshift(src.mapinshift), mapoutshift(src.mapinshift), 123 multiline(src.multiline), owner(0) 120 124 { 121 125 f0gen = src.f0gen ? new Geno(*src.f0gen) : 0; refcount = 1; … … 216 220 { 217 221 if (genpos > gen.len()) return -2; 218 if (genpos <0) return -1;222 if (genpos < 0) return -1; 219 223 return mapinshift + genpos; 220 224 } … … 223 227 { 224 228 stringpos -= mapinshift; 225 if (stringpos >gen.len()) return -2;229 if (stringpos > gen.len()) return -2; 226 230 if (stringpos < 0) return -1; 227 231 return stringpos; … … 255 259 if (gen.len() == 0) { isvalid = 0; return; } 256 260 if (format == INVALID_FORMAT) { isvalid = 0; return; } 257 Validators* vals =getValidators();258 if (vals !=NULL)259 261 Validators* vals = getValidators(); 262 if (vals != NULL) 263 { 260 264 #ifdef WARN_VALIDATION_INCONSISTENCY 261 265 vector<int> results; 262 266 int first_result=-1; 263 267 FOREACH(GenoValidator*, v, (*vals)) 264 268 { 265 269 int r=v->testGenoValidity(*this); 266 270 if (first_result<0) first_result=r; 267 271 results.push_back(r); 268 272 } 269 273 int N=vals->size(); 270 274 for(int i=1;i<N;i++) 271 275 if (results[i]!=results[0]) 272 273 274 275 276 277 278 279 280 281 276 { 277 SString txt="Inconsistent validation results"; 278 for(int i=0;i<N;i++) 279 txt+=SString::sprintf(" %d",results[i]); 280 txt+=" for genotype '"; 281 txt+=getGene(); 282 txt+="'"; 283 logPrintf("Geno","validate",LOG_WARN,txt.c_str()); 284 break; 285 } 282 286 isvalid=first_result; 283 287 if (isvalid>=0) 284 288 return; 285 289 #else 286 FOREACH(GenoValidator*, v, (*vals))287 if ((isvalid = v->testGenoValidity(*this)) >= 0)288 return;290 FOREACH(GenoValidator*, v, (*vals)) 291 if ((isvalid = v->testGenoValidity(*this)) >= 0) 292 return; 289 293 #endif 290 294 } 291 295 isvalid = 0; 292 296 logPrintf("Geno", "validate", LOG_WARN, "Wrong configuration? No genotype validators defined for genetic format 'f%c'.", format); … … 295 299 bool Geno::isValid(void) 296 300 { 297 if (isvalid <0)298 299 LoggerToMemory err(LoggerBase::Enable | LoggerToMemory::StoreAllMessages, LOG_INFO);301 if (isvalid < 0) 302 { 303 LoggerToMemory err(LoggerBase::Enable | LoggerToMemory::StoreAllMessages, LOG_INFO); 300 304 validate(); 301 305 err.disable(); 302 string msg =err.getCountSummary();303 if (msg.size() >0)304 305 msg +=ssprintf(" while checking validity of '%s'",getName().c_str());306 msg +="\n";307 msg +=err.getMessages();308 logMessage("Geno", "isValid",err.getErrorLevel(),msg.c_str());309 310 311 return isvalid >0;306 string msg = err.getCountSummary(); 307 if (msg.size() > 0) 308 { 309 msg += ssprintf(" while checking validity of '%s'", getName().c_str()); 310 msg += "\n"; 311 msg += err.getMessages(); 312 logMessage("Geno", "isValid", err.getErrorLevel(), msg.c_str()); 313 } 314 } 315 return isvalid > 0; 312 316 } 313 317 … … 316 320 if (otherformat == getFormat()) { if (converter_missing) *converter_missing = false; return *this; } 317 321 #ifndef NO_GENOCONVMANAGER 318 GenoConvManager *converters =getConverters();322 GenoConvManager *converters = getConverters(); 319 323 if (converters) 320 324 { … … 324 328 f0gen = new Geno(converters->convert(*this, otherformat, NULL, converter_missing)); 325 329 else 326 { if (converter_missing) *converter_missing = false; } 330 { 331 if (converter_missing) *converter_missing = false; 332 } 327 333 return *f0gen; 328 334 } -
cpp/frams/genetics/geno.h
r518 r522 55 55 56 56 public: 57 static const int INVALID_FORMAT ='!';57 static const int INVALID_FORMAT = '!'; 58 58 typedef SListTempl<GenoValidator*> Validators; 59 59
Note: See TracChangeset
for help on using the changeset viewer.