// todo: lift to HIVIntervention or helper function (repeated in HIVDelayedIntervention) bool HIVSimpleDiagnostic::UpdateCascade() { if( AbortDueToCurrentCascadeState() ) { return false ; } // is this the first time through? if so, update the cascade state. if (firstUpdate) { IHIVCascadeOfCare *ihcc = nullptr; if ( s_OK != parent->GetInterventionsContext()->QueryInterface(GET_IID(IHIVCascadeOfCare), (void **)&ihcc) ) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetInterventionsContext()", "IHIVCascadeOfCare", "IIndividualHumanInterventionsContext" ); } LOG_DEBUG_F( "Setting Cascade State to %s for individual %d.\n", cascadeState.c_str(), parent->GetSuid().data ); ihcc->setCascadeState(cascadeState); original_days_to_diagnosis = days_to_diagnosis; } return true ; }
bool HIVSimpleDiagnostic::AbortDueToCurrentCascadeState() { IHIVCascadeOfCare *ihcc = nullptr; if ( s_OK != parent->GetInterventionsContext()->QueryInterface(GET_IID(IHIVCascadeOfCare), (void **)&ihcc) ) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetInterventionsContext()", "IHIVCascadeOfCare", "IIndividualHumanInterventionsContext" ); } std::string currentState = ihcc->getCascadeState(); if ( abortStates.find(currentState) != abortStates.end() ) { // Duplicated from SimpleDiagnostic::positiveTestDistribute INodeTriggeredInterventionConsumer* broadcaster = nullptr; if (s_OK != parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&broadcaster)) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "INodeTriggeredInterventionConsumer", "INodeEventContext" ); } broadcaster->TriggerNodeEventObservers( parent->GetEventContext(), IndividualEventTriggerType::CascadeStateAborted ); LOG_DEBUG_F("The current cascade state \"%s\" is one of the Abort_States. Expiring the diagnostic for individual %d.\n", currentState.c_str(), parent->GetSuid().data ); expired = true; return true; } return false; }
void FlowControllerImpl::UpdateDesiredFlow( const IdmDateTime& rCurrentTime, float dt ) { LOG_DEBUG_F("%s()\n", __FUNCTION__); // ---------------------------------------------------------- // --- Count the total number of people eligible for pairing // ---------------------------------------------------------- float cumulative_base_flow = 0.0f; for( int risk_group = 0; risk_group < RiskGroup::COUNT; risk_group ++) { auto& eligible_population = pair_formation_stats->GetEligible((RiskGroup::Enum)risk_group); for (auto& entry : eligible_population) { for (float flow : entry.second) { cumulative_base_flow += flow; } } if (LOG_LEVEL(INFO)) { LOG_INFO_F( "%s: eligible population for %s risk group:\n", __FUNCTION__, RiskGroup::pairs::lookup_key(risk_group) ); for (auto& entry : eligible_population) { cout << "{ " << entry.first << ", [ "; for (int count : entry.second) { cout << count << ' '; } cout << "] }" << endl; } } } // --------------------------------------------------------------------- // --- Multiply the total number of people eligible times the base rate // --------------------------------------------------------------------- cumulative_base_flow *= parameters->FormationRate( rCurrentTime, dt ); if (cumulative_base_flow > 0.0f) { // ----------------------------------------------------------- // --- Determine the desired rate for each gender and age bin // ----------------------------------------------------------- for (int sex = Gender::MALE; sex <= Gender::FEMALE; sex++) { auto& desired = desired_flow.at(sex); // important, use a reference here so we update desired_flow auto& marginal = parameters->MarginalValues().at(sex); // use a reference here to avoid a copy int bin_count = desired.size(); for (int bin_index = 0; bin_index < bin_count; bin_index++) { desired[bin_index] = 0.5f * cumulative_base_flow * marginal[bin_index]; } } } else { memset(desired_flow[Gender::MALE].data(), 0, desired_flow[Gender::MALE].size() * sizeof(float)); memset(desired_flow[Gender::FEMALE].data(), 0, desired_flow[Gender::FEMALE].size() * sizeof(float)); } }
bool NodeLevelHealthTriggeredIV::Distribute( INodeEventContext *pNodeEventContext, IEventCoordinator2 *pEC ) { bool was_distributed = BaseNodeIntervention::Distribute(pNodeEventContext, pEC); if (was_distributed) { LOG_DEBUG_F("Distributed Nodelevel health-triggered intervention to NODE: %d\n", pNodeEventContext->GetId().data); // QI to register ourself as a NodeLevelHealthTriggeredIV observer INodeTriggeredInterventionConsumer * pNTIC = nullptr; if (s_OK != pNodeEventContext->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&pNTIC)) { throw QueryInterfaceException(__FILE__, __LINE__, __FUNCTION__, "pNodeEventContext", "INodeTriggeredInterventionConsumer", "INodeEventContext"); } release_assert(pNTIC); for (auto &trigger : m_trigger_conditions) { pNTIC->RegisterNodeEventObserver((IIndividualEventObserver*)this, trigger); } } return was_distributed; }
// BaseNodeIntervention BaseNodeIntervention::BaseNodeIntervention() : cost_per_unit(0.0f) , expired(false) { initSimTypes( 1, "*" ); LOG_DEBUG_F("New intervention, cost_per_unit = %f\n", cost_per_unit); }
ImportPressure::ImportPressure() : duration_counter(0) , num_imports(0) { LOG_DEBUG_F( "ctor\n" ); initSimTypes( 1, "GENERIC_SIM" ); }
void DiagnosticTreatNeg::onPatientDefault() { LOG_DEBUG_F( "Individual %d got the test but defaulted, receiving Defaulters intervention without waiting for days_to_diagnosis (actually means days_to_intervention) \n", parent->GetSuid().data ); // Important: Use the instance method to obtain the intervention factory obj instead of static method to cross the DLL boundary IGlobalContext *pGC = nullptr; const IInterventionFactory* ifobj = nullptr; if (s_OK == parent->QueryInterface(GET_IID(IGlobalContext), (void**)&pGC)) { ifobj = pGC->GetInterventionFactory(); } if (!ifobj) { throw NullPointerException( __FILE__, __LINE__, __FUNCTION__, "parent->GetInterventionFactoryObj()" ); } if( !defaulters_event.IsUninitialized() ) { if( defaulters_event != NO_TRIGGER_STR ) { INodeTriggeredInterventionConsumer* broadcaster = nullptr; if (s_OK != parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(INodeTriggeredInterventionConsumer), (void**)&broadcaster)) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "INodeTriggeredInterventionConsumer", "INodeEventContext" ); } broadcaster->TriggerNodeEventObserversByString( parent->GetEventContext(), defaulters_event ); } } else if( defaulters_config._json.Type() != ElementType::NULL_ELEMENT ) { auto tmp_config = Configuration::CopyFromElement(defaulters_config._json); // Distribute the defaulters intervention, right away (do not use the days_to_diagnosis IDistributableIntervention *di = const_cast<IInterventionFactory*>(ifobj)->CreateIntervention( tmp_config ); delete tmp_config; tmp_config = nullptr; ICampaignCostObserver* pICCO; // Now make sure cost of the test-positive intervention is reported back to node if (s_OK == parent->GetEventContext()->GetNodeEventContext()->QueryInterface(GET_IID(ICampaignCostObserver), (void**)&pICCO) ) { di->Distribute( parent->GetInterventionsContext(), pICCO ); pICCO->notifyCampaignEventOccurred( (IBaseIntervention*)di, (IBaseIntervention*)this, parent ); } else { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "parent->GetEventContext()->GetNodeEventContext()", "ICampaignCostObserver", "INodeEventContext" ); } } else { throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, "neither event or config defined" ); } }
void SusceptibilityPy::Initialize(float _age, float _immmod, float _riskmod) { LOG_DEBUG_F( "Initializing Py immunity object for new individual: id=%lu, age=%f, immunity modifier=%f, risk modifier=%f\n", parent->GetSuid().data, _age, _immmod, _riskmod ); Susceptibility::Initialize(_age, _immmod, _riskmod); // throws exception on error, no return type. }
void IndividualHumanPy::AcquireNewInfection(StrainIdentity *infstrain, int incubation_period_override ) { LOG_DEBUG_F("AcquireNewInfection: route %d\n", _routeOfInfection); IndividualHuman::AcquireNewInfection( infstrain, incubation_period_override ); #ifdef ENABLE_PYTHON_FEVER static auto pFunc = PythonSupportPtr->IdmPyInit( PythonSupport::SCRIPT_PYTHON_FEVER.c_str(), "acquire_infection" ); if( pFunc ) { // pass individual id ONLY static PyObject * vars = PyTuple_New(1); PyObject* py_existing_id = PyLong_FromLong( GetSuid().data ); PyTuple_SetItem(vars, 0, py_existing_id ); //vars = Py_BuildValue( "l", GetSuid().data ); // BuildValue with 1 param seems to give errors auto ret = PyObject_CallObject( pFunc, vars ); if( ret == nullptr ) { PyErr_Print(); std::stringstream msg; msg << "Embedded python code failed: PyObject_CallObject failed in call to 'acquire_infection'."; throw Kernel::IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() ); } } #endif }
void PairFormationStatsImpl::UpdateEligible( float age_in_days, int sex, RiskGroup::Enum risk_group, int delta ) { LOG_DEBUG_F("%s( %f, %d, %s, %d )\n", __FUNCTION__, age_in_days, sex, RiskGroup::pairs::lookup_key(risk_group), delta); int agebin_index = parameters->BinIndexForAgeAndSex(age_in_days, sex); release_assert( (eligible_population.at(risk_group).at(sex)[agebin_index] + delta) >= 0 ); eligible_population.at(risk_group).at(sex)[agebin_index] += delta; }
array_list_t *snp_filter(array_list_t *input_records, array_list_t *failed, variant_stats_t **input_stats, char *filter_name, void *f_args) { assert(input_records); assert(failed); array_list_t *passed = array_list_new(input_records->size + 1, 1, COLLECTION_MODE_ASYNCHRONIZED); size_t filter_name_len = strlen(filter_name); int include_snps = ((snp_filter_args*)f_args)->include_snps; LOG_DEBUG_F("snp_filter (preserve SNPs = %d) over %zu records\n", include_snps, input_records->size); vcf_record_t *record; for (int i = 0; i < input_records->size; i++) { record = input_records->items[i]; if (record->id_len == 1 && strncmp(".", record->id, 1) == 0) { if (include_snps) { annotate_failed_record(filter_name, filter_name_len, record); array_list_insert(record, failed); } else { array_list_insert(record, passed); } } else { if (include_snps) { array_list_insert(record, passed); } else { annotate_failed_record(filter_name, filter_name_len, record); array_list_insert(record, failed); } } } return passed; }
float SusceptibilityVector::BitingRiskAgeFactor(float _age) { float risk = 1.0f; switch(SusceptibilityVectorConfig::age_dependent_biting_risk_type) { case AgeDependentBitingRisk::OFF: // risk is independent by age break; case AgeDependentBitingRisk::LINEAR: risk = LinearBitingFunction(_age); break; case AgeDependentBitingRisk::SURFACE_AREA_DEPENDENT: risk = SurfaceAreaBitingFunction(_age); break; default: throw BadEnumInSwitchStatementException( __FILE__, __LINE__, __FUNCTION__, "age_dependent_biting_risk_type", SusceptibilityVectorConfig::age_dependent_biting_risk_type, AgeDependentBitingRisk::pairs::lookup_key(SusceptibilityVectorConfig::age_dependent_biting_risk_type) ); } LOG_DEBUG_F("Age-dependent biting-risk = %f for %0.2f-year-old individual.\n", risk, _age/DAYSPERYEAR); return risk; }
bool CommunityHealthWorkerEventCoordinator::Distribute( IIndividualHumanEventContext* pIHEC ) { release_assert( m_pInterventionIndividual ); IDistributableIntervention *di = m_pInterventionIndividual->Clone(); release_assert(di); ICampaignCostObserver* p_icco = nullptr; if (s_OK != pIHEC->GetNodeEventContext()->QueryInterface(GET_IID(ICampaignCostObserver), (void**)&p_icco)) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "pIHEC->GetNodeEventContext()", "ICampaignCostObserver", "INodeEventContext" ); } di->AddRef(); bool distributed = di->Distribute( pIHEC->GetInterventionsContext(), p_icco ); if( distributed ) { LOG_DEBUG_F("Distributed '%s' intervention to individual %d\n", m_InterventionName.c_str(), pIHEC->GetSuid().data ); } di->Release(); return distributed; }
bool ReferenceTrackingEventCoordinator::Configure( const Configuration * inputJson ) { if( !JsonConfigurable::_dryrun && #ifdef ENABLE_TYPHOID (GET_CONFIGURABLE( SimulationConfig )->sim_type != SimType::TYPHOID_SIM) && #endif (GET_CONFIGURABLE( SimulationConfig )->sim_type != SimType::STI_SIM) && (GET_CONFIGURABLE( SimulationConfig )->sim_type != SimType::HIV_SIM) ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "ReferenceTrackingEventCoordinator can only be used in STI, HIV, and TYPHOID simulations." ); } float update_period = DAYSPERYEAR; initConfigComplexType("Time_Value_Map", &year2ValueMap, RTEC_Time_Value_Map_DESC_TEXT ); initConfigTypeMap( "Update_Period", &update_period, RTEC_Update_Period_DESC_TEXT, 1.0, 10*DAYSPERYEAR, DAYSPERYEAR ); initConfigTypeMap( "End_Year", &end_year, RTEC_End_Year_DESC_TEXT, MIN_YEAR, MAX_YEAR, MAX_YEAR ); auto ret = StandardInterventionDistributionEventCoordinator::Configure( inputJson ); num_repetitions = -1; // unlimited if( JsonConfigurable::_dryrun == false ) { float dt = GET_CONFIGURABLE(SimulationConfig)->Sim_Tstep; tsteps_between_reps = update_period/dt; // this won't be precise, depending on math. if( tsteps_between_reps <= 0.0 ) { // don't let this be zero or it will only update one time tsteps_between_reps = 1; } } LOG_DEBUG_F( "ReferenceTrackingEventCoordinator configured with update_period = %f, end_year = %f, and tsteps_between_reps (derived) = %d.\n", update_period, end_year, tsteps_between_reps ); return ret; }
cp_hashtable* associate_samples_and_positions(vcf_file_t* file) { LOG_DEBUG_F("** %zu sample names read\n", file->samples_names->size); array_list_t *sample_names = file->samples_names; cp_hashtable *sample_ids = cp_hashtable_create(sample_names->size * 2, cp_hash_string, (cp_compare_fn) strcasecmp ); int *index; char *name; for (int i = 0; i < sample_names->size; i++) { name = sample_names->items[i]; index = (int*) malloc (sizeof(int)); *index = i; if (cp_hashtable_get(sample_ids, name)) { LOG_FATAL_F("Sample %s appears more than once. File can not be analyzed.\n", name); } cp_hashtable_put(sample_ids, name, index); } // char **keys = (char**) cp_hashtable_get_keys(sample_ids); // int num_keys = cp_hashtable_count(sample_ids); // for (int i = 0; i < num_keys; i++) { // printf("%s\t%d\n", keys[i], *((int*) cp_hashtable_get(sample_ids, keys[i]))); // } return sample_ids; }
const ProbabilityNumber HIVInterventionsContainer::GetInfectivitySuppression() const { // If not on art, 1.0f, else if ramping up, it's linear from 1.0 to 0.08, else if ramped up, 0.08f; ProbabilityNumber ret = 1.0f; float multiplier = InfectionHIVConfig::ART_viral_suppression_multiplier ; if( ART_status == ARTStatus::ON_ART_BUT_NOT_VL_SUPPRESSED ) { if( days_to_achieve_suppression == 0.0 ) { ret = multiplier; } else { float time_since_starting_ART = days_to_achieve_suppression - full_suppression_timer ; ret = 1.0f - ( ((1.0f - multiplier)/days_to_achieve_suppression) * (time_since_starting_ART) ); } } else if( ART_status == ARTStatus::ON_VL_SUPPRESSED ) { ret = multiplier; } LOG_DEBUG_F( "Returning viral suppression factor of %f.\n", (float) ret ); return ret; }
float NodeLevelHealthTriggeredIVScaleUpSwitch::getDemographicCoverage( ) const { float demographic_coverage = demographic_restrictions.GetDemographicCoverage(); float current_demographic_coverage = demographic_coverage; switch (demographic_coverage_time_profile) { case ScaleUpProfile::Immediate: LOG_DEBUG("ScaleUpProfile is Immediate, don't need to update demographic coverage by time \n"); current_demographic_coverage = demographic_coverage; break; case ScaleUpProfile::Linear: if (duration <= primary_time_constant) { //the increment amount is ((demographic_coverage - initial_demog_coverage)/primary_time_constant) per day current_demographic_coverage = initial_demographic_coverage + ( (demographic_coverage - initial_demographic_coverage)/primary_time_constant) * duration; LOG_DEBUG_F("ScaleUpProfile is Linear, duration is %f, rate of %f, coverage is %f \n", duration, ( (demographic_coverage - initial_demographic_coverage)/primary_time_constant), current_demographic_coverage); } else { current_demographic_coverage = demographic_coverage; } break; default: throw NotYetImplementedException( __FILE__, __LINE__, __FUNCTION__, "Only Immediate and Linear supported currently. \n" ); break; } return current_demographic_coverage; }
bool NodeSetPolygon::Contains( INodeEventContext *nec ) { LOG_DEBUG_F( "Contains node ID = %d ?\n", nec->GetId().data ); if( vertices_raw.length() > 0 ) // clear this after parse. { // haven't parsed raw list yet. // Go through list and parse out. if( polygon_format == PolygonFormatType::SHAPE ) { parseEmodFormat(); } // don't need else here because enum parser already catches such errors } if( polygon_format == PolygonFormatType::SHAPE && nec->IsInPolygon( points_array, int(num_points) ) ) { LOG_INFO_F( "Node ID = %d is contained within intervention polygon\n", nec->GetId().data ); return true; } LOG_DEBUG("Polygon apparently does not contain this node.\n"); /*else if( polygon_format == PolygonFormatType::GEOJSON && nec->IsInPolygon( poly ) ) { return true; }*/ return false; }
array_list_t *indel_filter(array_list_t *input_records, array_list_t *failed, variant_stats_t **input_stats, char *filter_name, void *f_args) { assert(input_records); assert(failed); array_list_t *passed = array_list_new(input_records->size + 1, 1, COLLECTION_MODE_ASYNCHRONIZED); size_t filter_name_len = strlen(filter_name); int include_indels = ((indel_filter_args*)f_args)->include_indels; LOG_DEBUG_F("indel_filter (preserve indels = %d) over %zu records\n", include_indels, input_records->size); vcf_record_t *record; variant_stats_t *variant_stats; for (int i = 0; i < input_records->size; i++) { record = input_records->items[i]; variant_stats = input_stats[i]; if (variant_stats->is_indel) { if (include_indels) { array_list_insert(record, passed); } else { annotate_failed_record(filter_name, filter_name_len, record); array_list_insert(record, failed); } } else { if (include_indels) { annotate_failed_record(filter_name, filter_name_len, record); array_list_insert(record, failed); } else { array_list_insert(record, passed); } } } return passed; }
bool ImportPressure::Configure( const Configuration * inputJson ) { LOG_DEBUG_F( "%s\n", __FUNCTION__ ); // TODO: specification for rate, seasonality, and age-biting function initConfigTypeMap( "Durations", &durations, IP_Durations_DESC_TEXT, 0, INT_MAX, 1 ); initConfigTypeMap( "Daily_Import_Pressures", &daily_import_pressures, IP_Daily_Import_Pressures_DESC_TEXT , 0, FLT_MAX, 0 ); bool configured = Outbreak::Configure( inputJson ); if( configured && !JsonConfigurable::_dryrun ) { if( durations.size() != (daily_import_pressures.size()) ) { throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, "ImportPressure intervention requires Durations must be the same size as Daily_Import_Pressures" ); } if( durations.size() <= 0 ) { throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, "Empty Durations parameter in ImportPressure intervention." ); } ConstructDistributionCalendar(); } return configured; }
bool MultiInterventionEventCoordinator::HasNodeLevelIntervention() const { bool has_node_level_intervention = false; bool has_individual_level_intervention = false; const json::Array & interventions_array = json::QuickInterpreter( intervention_config._json ).As<json::Array>(); LOG_DEBUG_F("interventions array size = %d\n", interventions_array.Size()); for( int idx = 0; idx < interventions_array.Size(); idx++ ) { const json::Object& actualIntervention = json_cast<const json::Object&>(interventions_array[idx]); auto config = Configuration::CopyFromElement( actualIntervention, "campaign" ); INodeDistributableIntervention *ndi = InterventionFactory::getInstance()->CreateNDIIntervention(config); if( ndi != nullptr ) { has_node_level_intervention = true; ndi->Release(); } else { has_individual_level_intervention = true; } delete config; config = nullptr; } if( has_node_level_intervention && has_individual_level_intervention ) { throw GeneralConfigurationException( __FILE__, __LINE__, __FUNCTION__, "You cannot mix individual and nodel-level interventions." ); } return has_node_level_intervention; }
int insert_statement_vcf_query_fields(void *custom_fields, sqlite3_stmt *stmt, sqlite3 *db) { int rc; vcf_query_fields_t *fields = (vcf_query_fields_t *) custom_fields; sqlite3_bind_text(stmt, 1, fields->chromosome, strlen(fields->chromosome), SQLITE_STATIC); sqlite3_bind_int64(stmt, 2, fields->position); sqlite3_bind_text(stmt, 3, fields->allele_ref, strlen(fields->allele_ref), SQLITE_STATIC); sqlite3_bind_text(stmt, 4, fields->allele_maf, strlen(fields->allele_maf), SQLITE_STATIC); sqlite3_bind_text(stmt, 5, fields->genotype_maf, strlen(fields->genotype_maf), SQLITE_STATIC); sqlite3_bind_double(stmt, 6, fields->allele_maf_freq); sqlite3_bind_double(stmt, 7, fields->genotype_maf_freq); sqlite3_bind_int(stmt, 8, fields->missing_alleles); sqlite3_bind_int(stmt, 9, fields->missing_genotypes); sqlite3_bind_int(stmt, 10, fields->mendelian_errors); sqlite3_bind_int(stmt, 11, fields->is_indel); sqlite3_bind_double(stmt, 12, fields->cases_percent_dominant); sqlite3_bind_double(stmt, 13, fields->controls_percent_dominant); sqlite3_bind_double(stmt, 14, fields->cases_percent_recessive); sqlite3_bind_double(stmt, 15, fields->controls_percent_recessive); if (rc = sqlite3_step(stmt) != SQLITE_DONE) { LOG_DEBUG_F("Stats databases failed: %s (%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); } sqlite3_reset(stmt); return rc; }
void IndividualHumanPy::Update( float currenttime, float dt) { #ifdef ENABLE_PYTHON_FEVER static auto pFunc = PythonSupportPtr->IdmPyInit( PythonSupport::SCRIPT_PYTHON_FEVER.c_str(), "update" ); if( pFunc ) { // pass individual id AND dt static PyObject * vars = PyTuple_New(2); vars = Py_BuildValue( "ll", GetSuid().data, int(dt) ); auto pyVal = PyObject_CallObject( pFunc, vars ); if( pyVal != nullptr ) { char * state = "UNSET"; PyArg_ParseTuple(pyVal,"si",&state, &state_changed ); //o-> pyobject |i-> int|s-> char* state_to_report = state; } else { state_to_report = "D"; } #if !defined(_WIN32) || !defined(_DEBUG) Py_DECREF(pyVal); #endif PyErr_Print(); } LOG_DEBUG_F( "state_to_report for individual %d = %s; Infected = %d, change = %d.\n", GetSuid().data, state_to_report.c_str(), IsInfected(), state_changed ); if( state_to_report == "S" && state_changed && GetInfections().size() > 0 ) { LOG_DEBUG_F( "[Update] Somebody cleared their infection.\n" ); // ClearInfection auto inf = GetInfections().front(); IInfectionPy * inf_pydemo = NULL; if (s_OK != inf->QueryInterface(GET_IID(IInfectionPy ), (void**)&inf_pydemo) ) { throw QueryInterfaceException( __FILE__, __LINE__, __FUNCTION__, "inf", "IInfectionPy ", "Infection" ); } // get InfectionPy pointer inf_pydemo->Clear(); } else if( state_to_report == "D" && state_changed ) { LOG_INFO_F( "[Update] Somebody died from their infection.\n" ); } #endif return IndividualHuman::Update( currenttime, dt); }
json::QuickBuilder NodeSetFactory::GetSchema() { // Iterate over all registrangs, instantiate using function pointer (or functor?), call Configure // but with special 'don't error out' mode. //json::Object returnVal; support_spec_map_t& registrants = getRegisteredClasses(); JsonConfigurable::_dryrun = true; json::Object nodeSetsJsonArray; for (auto& entry : registrants) { const std::string& class_name = entry.first; LOG_DEBUG_F("class_name = %s\n", class_name.c_str()); json::Object fakeJson; fakeJson["class"] = json::String(class_name); Configuration * fakeConfig = Configuration::CopyFromElement( fakeJson ); instantiator_function_t creator = entry.second; try { // TBD: Handle Node-targeted interventions ISupports * pNS = CreateInstanceFromSpecs<INodeSet>(fakeConfig, getRegisteredClasses(), true); if( pNS ) { //campaignSchema[std::string(class_name)] = dynamic_cast<JsonConfigurable*>(pNS)->GetSchema(); json::QuickBuilder* schema = &dynamic_cast<JsonConfigurable*>(pNS)->GetSchema(); (*schema)[ "class" ] = json::String( class_name ); nodeSetsJsonArray[ class_name ] = *schema; //nodeSetsJsonArray[jsonArrayIdx][ "class" ] = json::String( class_name ); } } catch( DetailedException &e ) { std::ostringstream msg; msg << "ConfigException creating nodeset for GetSchema: " << e.what() << std::endl; LOG_INFO( msg.str().c_str() ); } catch( const json::Exception &e ) { std::ostringstream msg; msg << "json Exception creating nodeset for GetSchema: " << e.what() << std::endl; LOG_INFO( msg.str().c_str() ); } LOG_DEBUG( "Done with that class....\n" ); delete fakeConfig; fakeConfig = nullptr; } campaignSchema[ "schema" ] = nodeSetsJsonArray; LOG_DEBUG( "Returning from GetSchema.\n" ); json::QuickBuilder retSchema = json::QuickBuilder(campaignSchema); return retSchema; }
IndividualHumanPy *IndividualHumanPy::CreateHuman(INodeContext *context, suids::suid id, float monte_carlo_weight, float initial_age, int gender, float initial_poverty) { IndividualHumanPy *newhuman = _new_ IndividualHumanPy(id, monte_carlo_weight, initial_age, gender, initial_poverty); newhuman->SetContextTo(context); LOG_DEBUG_F( "Created human with age=%f\n", newhuman->m_age ); return newhuman; }
void HIVInterventionsContainer::ApplyProbMaternalTransmissionModifier( const ProbabilityNumber &probReduction ) { if( probReduction == 0.0f || ( probReduction > maternal_transmission_suppression ) ) { maternal_transmission_suppression = probReduction; LOG_DEBUG_F( "ApplyProbMaternalTransmissionModifier: intervention set maternal_transmission_suppression to (%f)\n", (float) maternal_transmission_suppression ); } else { LOG_DEBUG_F( "ApplyProbMaternalTransmissionModifier: attempt to update failed because new value (%f) is less than (or equal to) current value (%f)\n", (float) probReduction, (float) maternal_transmission_suppression ); } }
int insert_vcf_query_fields_list(array_list_t *list, sqlite3 *db) { int rc; sqlite3_stmt *stmt; vcf_query_fields_t *fields; char *error_message; prepare_statement_vcf_query_fields(db, &stmt); if (rc = sqlite3_exec(db, "BEGIN TRANSACTION", NULL, NULL, &error_message)) { LOG_DEBUG_F("Stats databases failed: %s (%d)\n", rc, error_message); } int num_items = array_list_size(list); for (int i = 0; i < num_items; i++) { fields = array_list_get(i, list); sqlite3_bind_text(stmt, 1, fields->chromosome, strlen(fields->chromosome), SQLITE_STATIC); sqlite3_bind_int64(stmt, 2, fields->position); sqlite3_bind_text(stmt, 3, fields->allele_ref, strlen(fields->allele_ref), SQLITE_STATIC); sqlite3_bind_text(stmt, 4, fields->allele_maf, strlen(fields->allele_maf), SQLITE_STATIC); sqlite3_bind_text(stmt, 5, fields->genotype_maf, strlen(fields->genotype_maf), SQLITE_STATIC); sqlite3_bind_double(stmt, 6, fields->allele_maf_freq); sqlite3_bind_double(stmt, 7, fields->genotype_maf_freq); sqlite3_bind_int(stmt, 8, fields->missing_alleles); sqlite3_bind_int(stmt, 9, fields->missing_genotypes); sqlite3_bind_int(stmt, 10, fields->mendelian_errors); sqlite3_bind_int(stmt, 11, fields->is_indel); sqlite3_bind_double(stmt, 12, fields->cases_percent_dominant); sqlite3_bind_double(stmt, 13, fields->controls_percent_dominant); sqlite3_bind_double(stmt, 14, fields->cases_percent_recessive); sqlite3_bind_double(stmt, 15, fields->controls_percent_recessive); if (rc = sqlite3_step(stmt) != SQLITE_DONE) { LOG_DEBUG_F("Stats databases failed: %s (%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); } sqlite3_reset(stmt); } if (rc = sqlite3_exec(db, "COMMIT TRANSACTION", NULL, NULL, &error_message)) { LOG_DEBUG_F("Stats databases failed: %s (%d)\n", rc, error_message); } sqlite3_finalize(stmt); }
void HIVSimpleDiagnostic::onNegativeTestResult() { auto iid = parent->GetSuid().data; LOG_DEBUG_F( "Individual %d tested 'negative' in HIVSimpleDiagnostic, receiving actual intervention.\n", iid ); if( !negative_diagnosis_event.IsUninitialized() ) { LOG_DEBUG_F( "Brodcasting event %s as negative diagnosis event for individual %d.", negative_diagnosis_event.c_str(), iid ); broadcastEvent( negative_diagnosis_event ); } else { LOG_DEBUG_F( "Negative diagnosis event is NoTrigger for individual %d.\n", iid ); } expired = true; }
array_list_t *inheritance_pattern_filter(array_list_t *input_records, array_list_t *failed, variant_stats_t **input_stats, char *filter_name, void *f_args) { assert(input_records); assert(failed); array_list_t *passed = array_list_new(input_records->size + 1, 1, COLLECTION_MODE_ASYNCHRONIZED); size_t filter_name_len = strlen(filter_name); enum inheritance_pattern pattern = ((inheritance_pattern_filter_args*)f_args)->pattern; float min_following_pattern = ((inheritance_pattern_filter_args*)f_args)->min_following_pattern; if (pattern == DOMINANT) { LOG_DEBUG_F("inheritance_pattern_filter (dominant in %.2f% of samples) over %zu records\n", min_following_pattern * 100, input_records->size); } else { LOG_DEBUG_F("inheritance_pattern_filter (recessive in %.2f% of samples) over %zu records\n", min_following_pattern * 100, input_records->size); } vcf_record_t *record; variant_stats_t *stats; for (int i = 0; i < input_records->size; i++) { record = input_records->items[i]; stats = input_stats[i]; if (pattern == DOMINANT) { if (stats->cases_percent_dominant >= min_following_pattern && stats->controls_percent_dominant >= min_following_pattern) { array_list_insert(record, passed); } else { annotate_failed_record(filter_name, filter_name_len, record); array_list_insert(record, failed); } } else if (pattern == RECESSIVE) { if (stats->cases_percent_recessive >= min_following_pattern && stats->controls_percent_recessive >= min_following_pattern) { array_list_insert(record, passed); } else { annotate_failed_record(filter_name, filter_name_len, record); array_list_insert(record, failed); } } } return passed; }
void InterventionsContainer::ChangeProperty( const char * property, const char * new_value ) { /* LOG_DEBUG_F( "ChangeProperty: property = %s, new_value = %s\n", property, new_value ); if( strlen( property ) == 0 ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "ChangeProperty called with empty property string." ); } if( strlen( new_value ) == 0 ) { throw IllegalOperationException( __FILE__, __LINE__, __FUNCTION__, "ChangeProperty called with empty value string." ); } */ // Get parent property (remove need for casts) IPKeyValueContainer* pProps = parent->GetEventContext()->GetProperties(); // Check that property exists, except Age_Bins which are special case. We bootstrap individuals into age_bins at t=1, // with no prior existing age bin property. IPKey key( property ); if( ( std::string( property ) != "Age_Bin" ) && !pProps->Contains( key ) ) { throw BadMapKeyException( __FILE__, __LINE__, __FUNCTION__, "properties", property ); } IPKeyValue new_kv( property, new_value ); if( !pProps->Contains( new_kv ) ) { IPKeyValue old_kv = pProps->Get( key ); LOG_DEBUG_F( "Moving individual (%lu) property %s from %s to %s\n", parent->GetSuid().data, property, old_kv.GetValueAsString().c_str(), new_value ); parent->UpdateGroupPopulation(-1.0f); pProps->Set( new_kv ); parent->UpdateGroupMembership(); parent->UpdateGroupPopulation(1.0f); parent->SetPropertyReportString(""); //broadcast that the individual changed properties IIndividualEventBroadcaster* broadcaster = parent->GetEventContext()->GetNodeEventContext()->GetIndividualEventBroadcaster(); LOG_DEBUG_F( "Individual %d changed property, broadcasting PropertyChange \n", parent->GetSuid().data ); broadcaster->TriggerObservers( parent->GetEventContext(), EventTrigger::PropertyChange ); } }