int serve_client(const int client) { state s_; state *s = &s_; int action = -1; if (read(client, (void*) &action, sizeof(int)) != sizeof(int)) { return READ_ERROR; } if (action == ACTION_LIST_SOLUTIONS) { WRITE(client, &num_solutions, sizeof(int)); for (int i = 0; i < num_solutions; i++) { WRITE(client, sols[i]->base_state, SIZE_OF_STATE); int num_layers = (int)(sols[i]->num_layers); WRITE(client, &num_layers, sizeof(int)); int name_len = strlen(solution_names[i]); WRITE(client, &name_len, sizeof(int)); WRITE(client,solution_names[i], name_len * sizeof(char)); } return SOLUTION_FOUND; } else if (action == ACTION_QUERY_STATE) { if (read(client, (void*) s, SIZE_OF_STATE) != SIZE_OF_STATE) { return READ_ERROR; } #ifdef DEBUG print_state(s); repr_state(s); #endif return query_state(client, s); } return ERROR_INVALID_ACTION; }
int HypothesisEvaluator::MatchedFilter(DPTreephaser &working_treephaser, vector<BasecallerRead> &hypothesesReadsVector,int max_last_flow, int refHpLen, int flowPosition, int startFlow, vector<float>& DistanceObserved, vector<float>& DistanceHypotheses) { // Matched Filter HP distance is computed here vector<float> query_state(nFlows); int rHpLen = 0; if (flowPosition<startFlow || flowPosition >= nFlows) { cout << "Calculate Distances: Unsupported flowPosition! startFlow: " << startFlow << " flowPosition: " << flowPosition << " nFlows: " << nFlows << endl; return -1; } //cout << "Calling Query state " << endl; //cout << "Hypothesis = " << hypothesesReadsVector[0] << endl; //cout << "flow position = " << flowPosition << endl; //cout << "Nflows = " << nFlows << endl; //int readSize = hypothesesReadsVector[0].sequence.size(); // for (int i = 0; i < readSize ; i++) // cout << "Base = " << hypothesesReadsVector[0].sequence.at(i) << " Measure = " << hypothesesReadsVector[0].normalized_measurements.at(i) << endl; working_treephaser.QueryState(hypothesesReadsVector[0], query_state, rHpLen, nFlows, flowPosition); if (rHpLen == 0) { if (DEBUG) { cerr << "Hypothesis evaluator error ReadHpLen = 0 " << endl; cerr << "Calling Query state " << endl; cerr << "Hypothesis = " << hypothesesReadsVector[0].sequence.size() << endl; cerr << "flow position = " << flowPosition << endl; cerr << "Nflows = " << nFlows << endl; int readSize = hypothesesReadsVector[0].sequence.size(); for (int i = 0; i < readSize ; i++) cerr << " i = " << i << " Base = " << hypothesesReadsVector[0].sequence.at(i) << " Measure = " << hypothesesReadsVector[0].normalized_measurements.at(i) << endl; } return -1; } //return -1; if (abs(rHpLen-refHpLen) < 3) { float filter_num = 0.0f; float filter_den = 0.0f; if (this->DEBUG) cout << "Matched filter details: " << endl; for (int flow=0; flow<nFlows; flow++) { filter_num += (hypothesesReadsVector[0].normalized_measurements[flow] - hypothesesReadsVector[0].prediction[flow] + ((float)rHpLen*query_state[flow])) * query_state[flow]; filter_den += query_state[flow] * query_state[flow]; if ((this->DEBUG) and(query_state[flow] > 0.02 or flow == flowPosition)) { cout << "Flow " << flow << " State " << query_state[flow] << " Local delta " << ((hypothesesReadsVector[0].normalized_measurements[flow] - hypothesesReadsVector[0].prediction[flow] + ((float)rHpLen*query_state[flow])) * query_state[flow]) << " Measurements " << hypothesesReadsVector[0].normalized_measurements[flow]; //printf("Flow %4d State %1.4f Local delta %1.4f Measurements %1.4f"); //flow, query_state[flow], //((read.normalized_measurements[flow] - read.prediction[flow] + ((float)rHpLen*query_state[flow])) * query_state[flow]), //read.normalized_measurements[flow]); if (flow == flowPosition) //printf(" ***\n"); cout << " ***" << endl; else //printf("\n"); cout << endl; } } DistanceObserved[0] = filter_num / filter_den; //cout << DistanceObserved[0] << endl; } else { if (DEBUG) cerr << "Wrong rHpLen : " << rHpLen << " " << refHpLen << endl; return -1; } return(0); }