static void partialRecordRetrieval(CuTest *testCase) { setup(); //Make some number of large records stList *records = stList_construct3(0, free); stList *recordSizes = stList_construct3(0, (void(*)(void *)) stIntTuple_destruct); for (int32_t i = 0; i < 300; i++) { int32_t size = st_randomInt(0, 80); size = size * size * size; //Use cubic size distribution char *randomRecord = st_malloc(size * sizeof(char)); for (int32_t j = 0; j < size; j++) { randomRecord[j] = (char) st_randomInt(0, 100); } stList_append(records, randomRecord); stList_append(recordSizes, stIntTuple_construct(1, size)); CuAssertTrue(testCase, !stKVDatabase_containsRecord(database, i)); stKVDatabase_insertRecord(database, i, randomRecord, size * sizeof(char)); CuAssertTrue(testCase, stKVDatabase_containsRecord(database, i)); //st_uglyf("I am creating the record %i %i\n", i, size); } while (st_random() > 0.001) { int32_t recordKey = st_randomInt(0, stList_length(records)); CuAssertTrue(testCase, stKVDatabase_containsRecord(database, recordKey)); char *record = stList_get(records, recordKey); int32_t size = stIntTuple_getPosition(stList_get(recordSizes, recordKey), 0); //Get partial record int32_t start = size > 0 ? st_randomInt(0, size) : 0; int32_t partialSize = size - start > 0 ? st_randomInt(start, size) - start : 0; assert(start >= 0); assert(partialSize >= 0); assert(partialSize + start <= size); //st_uglyf("I am getting record %i %i %i %i\n", recordKey, start, partialSize, size); char *partialRecord = stKVDatabase_getPartialRecord(database, recordKey, start * sizeof(char), partialSize * sizeof(char), size * sizeof(char)); //Check they are equivalent.. for (int32_t i = 0; i < partialSize; i++) { if (record[start + i] != partialRecord[i]) { st_uglyf("There was a difference %i %i for record %i %i\n", record[start + i], partialRecord[i], i, partialSize); } //CuAssertTrue(testCase, record[start + i] == partialRecord[i]); } //Check we can not get out of bounds.. (start less than zero) stTry { stKVDatabase_getPartialRecord(database, recordKey, -1, 1, size * sizeof(char)); }stCatch(except) { CuAssertTrue(testCase, stExcept_getId(except) == ST_KV_DATABASE_EXCEPTION_ID); }stTryEnd; //Check we can not get out of bounds.. (start greater than index start) stTry { stKVDatabase_getPartialRecord(database, recordKey, size, 1, size * sizeof(char)); }stCatch(except) { CuAssertTrue(testCase, stExcept_getId(except) == ST_KV_DATABASE_EXCEPTION_ID); }stTryEnd; //Check we can not get out of bounds.. (total size if greater than record length) stTry { stKVDatabase_getPartialRecord(database, recordKey, 0, size + 1, size * sizeof(char)); }stCatch(except) { CuAssertTrue(testCase, stExcept_getId(except) == ST_KV_DATABASE_EXCEPTION_ID); }stTryEnd; //Check we can not get non existent record stTry { stKVDatabase_getPartialRecord(database, 1000000, 0, size, size * sizeof(char)); }stCatch(except) { CuAssertTrue(testCase, stExcept_getId(except) == ST_KV_DATABASE_EXCEPTION_ID); }stTryEnd; } stList_destruct(records); stList_destruct(recordSizes); teardown(); }
int main(int argc, char *argv[]) { int64_t j = 0; char *npReadFile = NULL; char *templateModelFile = stString_print("../models/testModelR9_template.model"); char *complementModelFile = stString_print("../models/testModelR9_complement_pop2.model"); double threshold = 0.8; int key; while (1) { static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"templateModel", required_argument, 0, 'T'}, {"complementModel", required_argument, 0, 'C'}, {"npRead", required_argument, 0, 'q'}, {"threshold", required_argument, 0, 'D'}, {0, 0, 0, 0} }; int option_index = 0; key = getopt_long(argc, argv, "h:T:C:q:f:b:D:m:", long_options, &option_index); if (key == -1) { //usage(); break; } switch (key) { case 'h': usage(); return 1; case 'T': templateModelFile = stString_copy(optarg); break; case 'C': complementModelFile = stString_copy(optarg); break; case 'q': npReadFile = stString_copy(optarg); break; case 'D': j = sscanf(optarg, "%lf", &threshold); assert (j == 1); assert (threshold >= 0); break; default: usage(); return 1; } } if (!stFile_exists(npReadFile)) { st_errAbort("Could not find npRead here: %s\n", npReadFile); } // read in the .npRead file NanoporeRead *npRead = nanopore_loadNanoporeReadFromFile(npReadFile); // build state machines (to use the look up table) StateMachine *sMt = getStateMachine3(templateModelFile); //StateMachine *sMc = getStateMachine3(complementModelFile); // make 1D map of events (mean, noise) to kmers stList *templateMap = signalUtils_templateOneDAssignmentsFromRead(npRead, sMt, ASSIGNMENT_THRESHOLD); //stList *complementMap = signalUtils_complementOneDAssignmentsFromRead(npRead, sMc, ASSIGNMENT_THRESHOLD); // convert template to log normal // NB only need this if you're estimating the NOISE parameteres //nanopore_convert_to_lognormal_params(sMt->alphabetSize, sMt->kmerLength, sMt->EMISSION_MATCH_MATRIX, templateMap); // convert complement to log normal //nanopore_convert_to_lognormal_params(sMc->alphabetSize, sMc->kmerLength, sMc->EMISSION_MATCH_MATRIX, complementMap); // error log report st_uglyf("SENTINEL - Before: shift: %f scale: %f var: %f [template]\n", npRead->templateParams.shift, npRead->templateParams.scale, npRead->templateParams.var); // compute template params //nanopore_compute_noise_scale_params(sMt->EMISSION_MATCH_MATRIX, templateMap, &npRead->templateParams); // compute complement params //nanopore_compute_noise_scale_params(sMc->EMISSION_MATCH_MATRIX, complementMap, &npRead->complementParams); // error log report signalUtils_estimateNanoporeParams(sMt, npRead, &npRead->templateParams, ASSIGNMENT_THRESHOLD, signalUtils_templateOneDAssignmentsFromRead, nanopore_dontAdjustEvents); //signalUtils_estimateNanoporeParams(sMc, npRead, &npRead->complementParams, ASSIGNMENT_THRESHOLD, // signalUtils_complementOneDAssignmentsFromRead, nanopore_dontAdjustEvents); st_uglyf("SENTINEL - After: shift: %f scale: %f var: %f [template]\n", npRead->templateParams.shift, npRead->templateParams.scale, npRead->templateParams.var); //st_uglyf("SENTINEL - After: shift_sd: %f scale_sd: %f var_sd: %f [template]\n", // npRead->complementParams.shift_sd, npRead->complementParams.scale_sd, npRead->complementParams.var_sd); stList *templateKmers = lineTokensFromFile(npReadFile, 10); //stList *complementKmers = lineTokensFromFile(npReadFile, 12); //printEventNoisesAndParams(npRead, templateKmers, complementKmers); printEventMeansAndParams(npRead, templateKmers, NULL); stList_destruct(templateKmers); //stList_destruct(complementKmers); stList_destruct(templateMap); //stList_destruct(complementMap); nanopore_nanoporeReadDestruct(npRead); stateMachine_destruct(sMt); //stateMachine_destruct(sMc); (void) j; // silence unused variable warning. return 0; }