void Character::update() { if(characterSet == CHARACTER_PLAYER) { for(std::list <MessageOverHeadClass>::iterator it=messageOverHead.begin(); it!=messageOverHead.end();) { if(it->fadesAway) { it->alpha -= deltaTime*5.f; if(it->alpha <= 0.f) { it = messageOverHead.erase(it); continue; } } else { it->alpha += deltaTime*25.f; if(it->alpha > 255.f) it->alpha = 255.f; } if(globalTime >= it->timeout_startFadingAway) { it->fadesAway = true; } ++it; } if(ID == playerCharacterID) return;; } if(!isSeen) return;; float tmp = dir-destDir; if(tmp < -M_PI) tmp += 2*M_PI; if(tmp > M_PI) tmp -= 2*M_PI; if(fabs(tmp) <= deltaTime/2.f) dir = destDir; else if(tmp < 0) { dir += deltaTime/2.f; if(dir > M_PI) dir = -2*M_PI+dir; } else { dir -= deltaTime/2.f; if(dir < -M_PI) dir = 2*M_PI+dir; } if(!floatCompare(position.x, destPosition.x, 0.01f) || !floatCompare(position.y, destPosition.y, 0.01f)) { float dir = atan2(destPosition.y-position.y, destPosition.x-position.x); float dir_cos = cos(dir); float dir_sin = sin(dir); if(fabs(position.x-destPosition.x) <= deltaTime*speed*dir_cos) position.x = destPosition.x; else { position.x += deltaTime*speed*dir_cos; } if(fabs(position.y-destPosition.y) <= deltaTime*speed*dir_sin) position.y = destPosition.y; else { position.y += deltaTime*speed*dir_sin; } } }
//------------------------------------------------------------------------------------------------------------------- Real fVector2::normalize(void) { Real len = sqrt(x*x+y*y); if(floatCompare(len, 0)<=0) return 0.0; Real inv_len = 1.0f/len; x *= inv_len; y *= inv_len; return len; }
void SGMXASScanConfiguration2013::checkIfMatchesBeamline() { bool currentMatchStatus; //Ensure bl is connected AND fluxResolutionGroup/TrackingGroup have been properly initialized if(SGMBeamline::sgm()->isConnected() && fluxResolutionGroup().count() > 0 && trackingGroup().count() > 0) { currentMatchStatus = (floatCompare(dbObject()->exitSlitGap() + 1.0e-200, SGMBeamline::sgm()->exitSlitGap()->value() + 1.0e-200, 0.20) && floatCompare(dbObject()->grating() + 1.0e-200, SGMBeamline::sgm()->grating()->value() + 1.0e-200, 0.0001) && floatCompare(dbObject()->harmonic() + 1.0e-200, SGMBeamline::sgm()->harmonic()->value() + 1.0e-200, 0.001) && floatCompare(dbObject()->undulatorTracking() + 1.0e-200, SGMBeamline::sgm()->undulatorTracking()->value() + 1.0e-200, 0.001) && floatCompare(dbObject()->monoTracking() + 1.0e-200, SGMBeamline::sgm()->monoTracking()->value() + 1.0e-200, 0.001) && floatCompare(dbObject()->exitSlitTracking() + 1.0e-200, SGMBeamline::sgm()->exitSlitTracking()->value() + 1.0e-200, 0.001)); } else { currentMatchStatus = false; } if(currentMatchStatus != this->matchesCurrentBeamline_) { matchesCurrentBeamline_ = currentMatchStatus; emit matchingBeamlineStatusChanged(currentMatchStatus); } }
void generateRelease(const string & vcf_filename, const string & output_prefix, const float min_called_probability) { cout << "[" << Utils::getLocalTime() << "] Running BayesTyperUtils (" << BTU_VERSION << ") generateRelease ...\n" << endl; GenotypedVcfFileReader vcf_reader(vcf_filename, true); assert(vcf_reader.metaData().miscMeta().erase("CommandLine")); assert(vcf_reader.metaData().infoDescriptors().erase("AE")); assert(vcf_reader.metaData().infoDescriptors().erase("ANC")); assert(vcf_reader.metaData().infoDescriptors().erase("HCR")); assert(vcf_reader.metaData().infoDescriptors().erase("HRS")); assert(vcf_reader.metaData().infoDescriptors().erase("VCGI")); assert(vcf_reader.metaData().infoDescriptors().erase("VCGS")); assert(vcf_reader.metaData().infoDescriptors().erase("VCI")); assert(vcf_reader.metaData().infoDescriptors().erase("VCS")); assert(vcf_reader.metaData().infoDescriptors().erase("VT")); auto complete_meta_data = vcf_reader.metaData(); assert(complete_meta_data.infoDescriptors().emplace("AT", Attribute::DetailedDescriptor("AT", Attribute::Number::A, Attribute::Type::String, "Allele type")).second); string lvq_label("LVQ"); assert(complete_meta_data.filterDescriptors().emplace(lvq_label, Attribute::Descriptor(lvq_label, "All alternative alleles excluding missing have low allele call probability (ACP < " + to_string(min_called_probability) + ")")).second); string nc_label("NC"); assert(complete_meta_data.filterDescriptors().emplace(nc_label, Attribute::Descriptor(nc_label, "All alternative alleles excluding missing are not called (ACP == 0)")).second); VcfMetaData called_file_meta_data = complete_meta_data; called_file_meta_data.filterDescriptors().clear(); called_file_meta_data.clearSamples(); assert(called_file_meta_data.infoDescriptors().erase("ACP")); assert(called_file_meta_data.infoDescriptors().erase("ACO")); called_file_meta_data.infoDescriptors().erase("AsmVar_ASQR"); called_file_meta_data.infoDescriptors().erase("DNE"); called_file_meta_data.infoDescriptors().erase("RMA"); VcfMetaData de_novo_file_meta_data = complete_meta_data; de_novo_file_meta_data.filterDescriptors().clear(); VcfFileWriter vcf_writer_complete(output_prefix + "_complete.vcf", complete_meta_data, true); VcfFileWriter vcf_writer_called(output_prefix + "_called_alleles.vcf", called_file_meta_data, true); VcfFileWriter vcf_writer_de_novo(output_prefix + "_de_novo.vcf", de_novo_file_meta_data, true); Variant * cur_var; uint num_variants = 0; uint num_alleles = 0; uint num_low_prob_variants = 0; uint num_filt_variants = 0; uint num_missing_alleles = 0; uint num_not_called_variants = 0; uint num_low_prob_alleles = 0; uint num_de_novo_events = 0; uint num_de_novo_multiple_events = 0; assert(min_called_probability > 0); assert(min_called_probability <= 1); while (vcf_reader.getNextVariant(&cur_var)) { num_variants++; num_alleles += cur_var->numAlls(); assert(cur_var->filters().size() == 1); // Label alleles vector<uint> alt_rm_idxs; alt_rm_idxs.reserve(cur_var->numAlts()); float alt_acp_max = 0; for (uint allele_idx = 0; allele_idx < cur_var->numAlls(); allele_idx++) { assert(cur_var->info().hasValue("AN")); auto acp_value = cur_var->allele(allele_idx).info().getValue<float>("ACP"); assert(acp_value.second); if (allele_idx > 0) { assert(cur_var->allele(allele_idx).info().hasValue("AC")); assert(cur_var->allele(allele_idx).info().hasValue("AF")); assert(cur_var->allele(allele_idx).info().hasValue("ACO")); assert(cur_var->allele(allele_idx).info().hasValue("AAI")); auto at = Auxiliaries::alleleAttributes(cur_var->allele(allele_idx), cur_var->ref()); auto rma_value = cur_var->allele(allele_idx).info().getValue<string>("RMA"); if (rma_value.second) { assert((rma_value.first == ".") or (at.type == Auxiliaries::Type::Insertion) or (at.type == Auxiliaries::Type::Deletion)); } assert(cur_var->allele(allele_idx).info().setValue("AT", at.typeStr())); if (cur_var->allele(allele_idx).isMissing()) { alt_rm_idxs.push_back(allele_idx - 1); num_missing_alleles++; continue; } alt_acp_max = max(alt_acp_max, acp_value.first); if (acp_value.first < min_called_probability) { alt_rm_idxs.push_back(allele_idx - 1); num_low_prob_alleles++; } } } if (cur_var->filters().front() == "PASS") { auto var_qual = cur_var->qual(); assert(var_qual.second); auto var_call_prob = 1 - pow(10, -1 * var_qual.first/10); assert((var_call_prob == alt_acp_max) or (abs(var_call_prob - alt_acp_max) < pow(10, -3))); if (floatCompare(alt_acp_max, 0)) { assert(alt_rm_idxs.size() == cur_var->numAlts()); cur_var->setFilters({nc_label}); num_not_called_variants++; } else if (alt_acp_max < min_called_probability) { assert(alt_rm_idxs.size() == cur_var->numAlts()); cur_var->setFilters({lvq_label}); num_low_prob_variants++; } else { assert(alt_rm_idxs.size() < cur_var->numAlts()); } } else { num_filt_variants++; } vcf_writer_complete.write(cur_var); auto dne_att = cur_var->info().getValue<string>("DNE"); if (dne_att.second) { assert(cur_var->filters().front() == "PASS"); if (dne_att.first.find(",") == string::npos) { num_de_novo_events++; } else { num_de_novo_multiple_events++; } vcf_writer_de_novo.write(cur_var); } if (cur_var->filters().front() == "PASS") { assert(alt_rm_idxs.size() < cur_var->numAlts()); int alt_rm_ac = 0; for (auto & alt_rm_idx: alt_rm_idxs) { auto ac_value = cur_var->alt(alt_rm_idx).info().getValue<int>("AC"); assert(ac_value.second); alt_rm_ac += ac_value.first; } cur_var->clearSamples(); cur_var->removeAlts(alt_rm_idxs); auto an_value = cur_var->info().getValue<int>("AN"); assert(an_value.second); assert(an_value.first >= alt_rm_ac); if (alt_rm_ac > 0) { assert(!cur_var->info().setValue<int>("AN", an_value.first - alt_rm_ac)); assert(cur_var->numAlts() > 0); for (uint alt_idx = 0; alt_idx < cur_var->numAlts(); alt_idx++) { if (an_value.first == alt_rm_ac) { assert(!cur_var->alt(alt_idx).info().setValue<float>("AF", 0)); } else { auto ac_value = cur_var->alt(alt_idx).info().getValue<int>("AC"); assert(ac_value.second); assert(!cur_var->alt(alt_idx).info().setValue<float>("AF", ac_value.first / static_cast<float>(an_value.first - alt_rm_ac))); } } } vcf_writer_called.write(cur_var); } delete cur_var; if ((num_variants % 100000) == 0) { std::cout << "[" << Utils::getLocalTime() << "] Parsed " << num_variants << " variants" << endl; } } cout << "\n[" << Utils::getLocalTime() << "] Parsed " << num_variants << " variants and " << num_alleles << " alleles (including reference and missing)\n" << endl; cout << "\t\t - " << num_filt_variants << " variant(s) were already labelled as filtered (UV or ISD)" << endl; cout << "\t\t - " << num_not_called_variants << " variant(s) were labelled as not called (NC)" << endl; cout << "\t\t - " << num_low_prob_variants << " variant(s) were labelled as low variant quality (LVQ)\n" << endl; cout << "\t\t - " << num_missing_alleles << " missing alleles(s)" << endl; cout << "\t\t - " << num_low_prob_alleles << " alleles(s) had probability below threshold\n" << endl; cout << "\t\t - " << num_de_novo_events << " de novo events" << endl; cout << "\t\t - " << num_de_novo_multiple_events << " multi de novo events" << endl; cout << endl; }