void eventTree_check(EventTree *eventTree) { Event *event; EventTree_Iterator *eventIterator = eventTree_getIterator(eventTree); while((event = eventTree_getNext(eventIterator)) != NULL) { event_check(event); } eventTree_destructIterator(eventIterator); }
Event *eventTree_getEventByHeader(EventTree *eventTree, const char *eventHeader) { EventTree_Iterator *it = eventTree_getIterator(eventTree); Event *event; while ((event = eventTree_getNext(it)) != NULL) { if (strcmp(event_getHeader(event), eventHeader) == 0) { eventTree_destructIterator(it); return event; } } eventTree_destructIterator(it); return NULL; }
void testEventTree_iterator(CuTest* testCase) { cactusEventTreeTestSetup(); EventTree_Iterator *iterator = eventTree_getIterator(eventTree); CuAssertTrue(testCase, eventTree_getNext(iterator) == rootEvent); CuAssertTrue(testCase, eventTree_getNext(iterator) == internalEvent); EventTree_Iterator *iterator2 = eventTree_copyIterator(iterator); CuAssertTrue(testCase, eventTree_getNext(iterator) == leafEvent1); CuAssertTrue(testCase, eventTree_getNext(iterator) == leafEvent2); CuAssertTrue(testCase, eventTree_getNext(iterator) == NULL); CuAssertTrue(testCase, eventTree_getNext(iterator2) == leafEvent1); CuAssertTrue(testCase, eventTree_getNext(iterator2) == leafEvent2); CuAssertTrue(testCase, eventTree_getNext(iterator2) == NULL); CuAssertTrue(testCase, eventTree_getPrevious(iterator2) == leafEvent2); CuAssertTrue(testCase, eventTree_getPrevious(iterator2) == leafEvent1); CuAssertTrue(testCase, eventTree_getPrevious(iterator2) == internalEvent); CuAssertTrue(testCase, eventTree_getPrevious(iterator2) == rootEvent); CuAssertTrue(testCase, eventTree_getPrevious(iterator2) == NULL); eventTree_destructIterator(iterator); eventTree_destructIterator(iterator2); cactusEventTreeTestTeardown(); }
int main(int argc, char *argv[]) { ////////////////////////////////////////////// //Parse the inputs ////////////////////////////////////////////// parseBasicArguments(argc, argv, "coverageStats"); assert(referenceEventString != NULL); assert(otherReferenceEventString != NULL); assert(outgroupEventString != NULL); /////////////////////////////////////////////////////////////////////////// // Calculate and print to file a crap load of numbers. /////////////////////////////////////////////////////////////////////////// Sequence *referenceSequence = NULL; Sequence *otherReferenceSequence = NULL; Flower_SequenceIterator *sequenceIt = flower_getSequenceIterator(flower); Sequence *sequence; while ((sequence = flower_getNextSequence(sequenceIt)) != NULL) { const char *eventHeader = event_getHeader(sequence_getEvent(sequence)); if (eventHeader != NULL && strcmp(eventHeader, referenceEventString) == 0) { if (referenceSequence == NULL || sequence_getLength(sequence) >= sequence_getLength(referenceSequence)) { referenceSequence = sequence; } } if (eventHeader != NULL && strcmp(eventHeader, otherReferenceEventString) == 0) { if (otherReferenceSequence == NULL || sequence_getLength(sequence) >= sequence_getLength(otherReferenceSequence)) { otherReferenceSequence = sequence; } } } flower_destructSequenceIterator(sequenceIt); assert(referenceSequence != NULL); assert(otherReferenceSequence != NULL); FILE *fileHandle = fopen(outputFile, "w"); fprintf( fileHandle, "<coverageStats referenceSequenceLength=\"%i\" otherReferenceSequenceLength=\"%i\">\n", sequence_getLength(referenceSequence), sequence_getLength(otherReferenceSequence)); EventTree_Iterator *eventIt = eventTree_getIterator( flower_getEventTree(flower)); eventNumber = eventTree_getEventNumber(flower_getEventTree(flower)); Event * event; totalBaseCoverages = st_calloc(sizeof(int32_t), eventNumber + 1); totalReferenceBases = 0; totalOtherReferenceBases = 0; int32_t totalSamples = 0; ignoreOtherReferenceBlocks = 0; while ((event = eventTree_getNext(eventIt)) != NULL) { sampleEventString = event_getHeader(event); if (sampleEventString != NULL && strcmp(sampleEventString, "ROOT") != 0 && strcmp(sampleEventString, "") != 0) { baseCoverages = st_calloc(sizeof(int32_t), eventNumber + 1); baseCoverages[0] = strcmp(sampleEventString, referenceEventString) != 0 ? getTotalLengthOfAdjacencies(flower, sampleEventString) : 0; referenceBases = 0; otherReferenceBases = 0; getMAFs(flower, fileHandle, getMAFBlock2); if(strcmp(sampleEventString, referenceEventString) == 0) { for(int32_t i=2; i<eventNumber + 1; i++) { baseCoverages[i-1] = baseCoverages[i]; } baseCoverages[eventNumber] = 0; } printStatsForSample( strcmp(sampleEventString, referenceEventString) != 0 && strcmp(sampleEventString, outgroupEventString) != 0, fileHandle, 1); free(baseCoverages); totalSamples += (strcmp(sampleEventString, referenceEventString) != 0 && strcmp(sampleEventString, outgroupEventString) != 0) ? 1 : 0; } } eventTree_destructIterator(eventIt); //Do average base coverages.. sampleEventString = "average"; baseCoverages = totalBaseCoverages; referenceBases = totalReferenceBases; otherReferenceBases = totalOtherReferenceBases; printStatsForSample(0, fileHandle, totalSamples); //Do all.. sampleEventString = referenceEventString; baseCoverages = st_calloc(sizeof(int32_t), eventNumber + 1); baseCoverages[0] = totalBaseCoverages[0]; referenceBases = 0; getMAFs(flower, fileHandle, getMAFBlock2); for(int32_t i=2; i<eventNumber + 1; i++) { baseCoverages[i-1] = baseCoverages[i]; } baseCoverages[eventNumber] = 0; otherReferenceBases = sequence_getLength(otherReferenceSequence); sampleEventString = "all"; printStatsForSample(0, fileHandle, 1); free(baseCoverages); //Do blocks without other reference ignoreOtherReferenceBlocks = 1; sampleEventString = referenceEventString; baseCoverages = st_calloc(sizeof(int32_t), eventNumber + 1); baseCoverages[0] = totalBaseCoverages[0] - getTotalLengthOfAdjacencies(flower, otherReferenceEventString); referenceBases = 0; otherReferenceBases = 0; getMAFs(flower, fileHandle, getMAFBlock2); for(int32_t i=2; i<eventNumber + 1; i++) { baseCoverages[i-1] = baseCoverages[i]; } baseCoverages[eventNumber] = 0; sampleEventString = "minusOtherReference"; printStatsForSample(0, fileHandle, 1); free(baseCoverages); fprintf(fileHandle, "</coverageStats>\n"); st_logInfo("Finished writing out the stats.\n"); fclose(fileHandle); return 0; }