コード例 #1
0
void flower_destruct(Flower *flower, int64_t recursive) {
    Flower_GroupIterator *iterator;
    Sequence *sequence;
    End *end;
    Block *block;
    Group *group;
    Chain *chain;
    Flower *nestedFlower;

    if (recursive) {
        iterator = flower_getGroupIterator(flower);
        while ((group = flower_getNextGroup(iterator)) != NULL) {
            nestedFlower = group_getNestedFlower(group);
            if (nestedFlower != NULL) {
                flower_destruct(nestedFlower, recursive);
            }
        }
        flower_destructGroupIterator(iterator);
    }

    cactusDisk_removeFlower(flower->cactusDisk, flower);

    flower_destructFaces(flower);
    stSortedSet_destruct(flower->faces);

    assert(flower_getEventTree(flower) != NULL);
    eventTree_destruct(flower_getEventTree(flower));

    while ((sequence = flower_getFirstSequence(flower)) != NULL) {
        sequence_destruct(sequence);
    }
    stSortedSet_destruct(flower->sequences);

    while ((chain = flower_getFirstChain(flower)) != NULL) {
        chain_destruct(chain);
    }
    stSortedSet_destruct(flower->chains);

    while ((end = flower_getFirstEnd(flower)) != NULL) {
        end_destruct(end);
    }
    stSortedSet_destruct(flower->caps);
    stSortedSet_destruct(flower->ends);

    while ((block = flower_getFirstBlock(flower)) != NULL) {
        block_destruct(block);
    }
    stSortedSet_destruct(flower->segments);
    stSortedSet_destruct(flower->blocks);

    while ((group = flower_getFirstGroup(flower)) != NULL) {
        group_destruct(group);
    }
    stSortedSet_destruct(flower->groups);

    free(flower);
}
コード例 #2
0
void flower_writeBinaryRepresentation(Flower *flower, void(*writeFn)(const void * ptr, size_t size, size_t count)) {
    Flower_SequenceIterator *sequenceIterator;
    Flower_EndIterator *endIterator;
    Flower_BlockIterator *blockIterator;
    Flower_GroupIterator *groupIterator;
    Flower_ChainIterator *chainIterator;
    Sequence *sequence;
    End *end;
    Block *block;
    Group *group;
    Chain *chain;

    binaryRepresentation_writeElementType(CODE_FLOWER, writeFn);
    binaryRepresentation_writeName(flower_getName(flower), writeFn);
    binaryRepresentation_writeBool(flower_builtBlocks(flower), writeFn);
    binaryRepresentation_writeBool(flower_builtTrees(flower), writeFn);
    binaryRepresentation_writeBool(flower_builtFaces(flower), writeFn);
    binaryRepresentation_writeName(flower->parentFlowerName, writeFn);

    if (flower_getEventTree(flower) != NULL) {
        eventTree_writeBinaryRepresentation(flower_getEventTree(flower), writeFn);
    }

    sequenceIterator = flower_getSequenceIterator(flower);
    while ((sequence = flower_getNextSequence(sequenceIterator)) != NULL) {
        sequence_writeBinaryRepresentation(sequence, writeFn);
    }
    flower_destructSequenceIterator(sequenceIterator);

    endIterator = flower_getEndIterator(flower);
    while ((end = flower_getNextEnd(endIterator)) != NULL) {
        end_writeBinaryRepresentation(end, writeFn);
    }
    flower_destructEndIterator(endIterator);

    blockIterator = flower_getBlockIterator(flower);
    while ((block = flower_getNextBlock(blockIterator)) != NULL) {
        block_writeBinaryRepresentation(block, writeFn);
    }
    flower_destructBlockIterator(blockIterator);

    groupIterator = flower_getGroupIterator(flower);
    while ((group = flower_getNextGroup(groupIterator)) != NULL) {
        group_writeBinaryRepresentation(group, writeFn);
    }
    flower_destructGroupIterator(groupIterator);

    chainIterator = flower_getChainIterator(flower);
    while ((chain = flower_getNextChain(chainIterator)) != NULL) {
        chain_writeBinaryRepresentation(chain, writeFn);
    }
    flower_destructChainIterator(chainIterator);

    binaryRepresentation_writeElementType(CODE_FLOWER, writeFn); //this avoids interpretting things wrong.
}
コード例 #3
0
void flower_check(Flower *flower) {
    eventTree_check(flower_getEventTree(flower));

    Flower_GroupIterator *groupIterator = flower_getGroupIterator(flower);
    Group *group;
    while ((group = flower_getNextGroup(groupIterator)) != NULL) {
        group_check(group);
    }
    flower_destructGroupIterator(groupIterator);

    Flower_ChainIterator *chainIterator = flower_getChainIterator(flower);
    Chain *chain;
    while ((chain = flower_getNextChain(chainIterator)) != NULL) {
        chain_check(chain);
    }
    flower_destructCapIterator(chainIterator);

    //We check built trees in here.
    Flower_EndIterator *endIterator = flower_getEndIterator(flower);
    End *end;
    while ((end = flower_getNextEnd(endIterator)) != NULL) {
        end_check(end);
        end_check(end_getReverse(end)); //We will test everything backwards also.
    }
    flower_destructEndIterator(endIterator);

    if (flower_builtFaces(flower)) {
        Flower_FaceIterator *faceIterator = flower_getFaceIterator(flower);
        Face *face;
        while ((face = flower_getNextFace(faceIterator)) != NULL) {
            face_check(face);
        }
        flower_destructFaceIterator(faceIterator);
        face_checkFaces(flower);
    } else {
        cactusCheck(flower_getFaceNumber(flower) == 0);
    }

    if (flower_builtBlocks(flower)) { //Note that a flower for which the blocks are not yet built must be a leaf.
        Flower_BlockIterator *blockIterator = flower_getBlockIterator(flower);
        Block *block;
        while ((block = flower_getNextBlock(blockIterator)) != NULL) {
            block_check(block);
            block_check(block_getReverse(block)); //We will test everything backwards also.
        }
        flower_destructBlockIterator(blockIterator);
    } else {
        cactusCheck(flower_isLeaf(flower)); //Defensive
        cactusCheck(flower_isTerminal(flower)); //Checks that a flower without built blocks is a leaf and does not
        //contain any blocks.
    }

    Flower_SequenceIterator *sequenceIterator = flower_getSequenceIterator(flower);
    Sequence *sequence;
    while ((sequence = flower_getNextSequence(sequenceIterator)) != NULL) {
        sequence_check(sequence);
    }
    flower_destructSequenceIterator(sequenceIterator);
}
コード例 #4
0
void bottomUp(stList *flowers, stKVDatabase *sequenceDatabase, Name referenceEventName,
              bool isTop, stMatrix *(*generateSubstitutionMatrix)(double)) {
    /*
     * A reference thread between the two caps
     * in each flower f may be broken into two in the children of f.
     * Therefore, for each flower f first identify attached stub ends present in the children of f that are
     * not present in f and copy them into f, reattaching the reference caps as needed.
     */
    stList *caps = getCaps(flowers, referenceEventName);
    for (int64_t i = stList_length(caps) - 1; i >= 0; i--) { //Start from end, as we add to this list.
        setAdjacencyLengthsAndRecoverNewCapsAndBrokenAdjacencies(stList_get(caps, i), caps);
    }
    for(int64_t i=0; i<stList_length(flowers); i++) {
        recoverBrokenAdjacencies(stList_get(flowers, i), caps, referenceEventName);
    }

    //Build the phylogenetic event trees for base calling.
    segmentWriteFn_flowerToPhylogeneticTreeHash = stHash_construct2(NULL, (void (*)(void *))cleanupPhylogeneticTree);
    for(int64_t i=0; i<stList_length(flowers); i++) {
        Flower *flower = stList_get(flowers, i);
        Event *refEvent = eventTree_getEvent(flower_getEventTree(flower), referenceEventName);
        assert(refEvent != NULL);
        stHash_insert(segmentWriteFn_flowerToPhylogeneticTreeHash, flower, getPhylogeneticTreeRootedAtGivenEvent(refEvent, generateSubstitutionMatrix));
    }

    if (isTop) {
        stList *threadStrings = buildRecursiveThreadsInList(sequenceDatabase, caps, segmentWriteFn,
                terminalAdjacencyWriteFn);
        assert(stList_length(threadStrings) == stList_length(caps));

        int64_t nonTrivialSeqIndex = 0, trivialSeqIndex = stList_length(threadStrings); //These are used as indices for the names of trivial and non-trivial sequences.
        for (int64_t i = 0; i < stList_length(threadStrings); i++) {
            Cap *cap = stList_get(caps, i);
            assert(cap_getStrand(cap));
            assert(!cap_getSide(cap));
            Flower *flower = end_getFlower(cap_getEnd(cap));
            char *threadString = stList_get(threadStrings, i);
            bool trivialString = isTrivialString(&threadString); //This alters the original string
            MetaSequence *metaSequence = addMetaSequence(flower, cap, trivialString ? trivialSeqIndex++ : nonTrivialSeqIndex++,
                    threadString, trivialString);
            free(threadString);
            int64_t endCoordinate = setCoordinates(flower, metaSequence, cap, metaSequence_getStart(metaSequence) - 1);
            (void) endCoordinate;
            assert(endCoordinate == metaSequence_getLength(metaSequence) + metaSequence_getStart(metaSequence));
        }
        stList_setDestructor(threadStrings, NULL); //The strings are already cleaned up by the above loop
        stList_destruct(threadStrings);
    } else {
        buildRecursiveThreads(sequenceDatabase, caps, segmentWriteFn, terminalAdjacencyWriteFn);
    }
    stHash_destruct(segmentWriteFn_flowerToPhylogeneticTreeHash);
    stList_destruct(caps);
}
コード例 #5
0
static void cactusEventTestSetup() {
	if(!nestedTest) {
		cactusEventTestTeardown();
		cactusDisk = testCommon_getTemporaryCactusDisk();
		flower = flower_construct(cactusDisk);
		eventTree = flower_getEventTree(flower);
		rootEvent = eventTree_getRootEvent(eventTree);

		internalEvent = event_construct3("INTERNAL", 0.5, rootEvent, eventTree);
		leafEvent1 = event_construct3("LEAF1", 0.2, internalEvent, eventTree);
		leafEvent2 = event_construct3(NULL, 1.3, internalEvent, eventTree);
		event_setOutgroupStatus(leafEvent1, 1);
		event_setOutgroupStatus(leafEvent2, 0);
	}
}
コード例 #6
0
void event_check(Event *event) {
    EventTree *eventTree = event_getEventTree(event);
    Event *ancestorEvent = event_getParent(event);

    //Check event and eventree properly linked
    cactusCheck(eventTree_getEvent(event_getEventTree(event), event_getName(event)) == event);

    //Event has parent, unless it is root.
    if (eventTree_getRootEvent(eventTree) == event) {
        cactusCheck(ancestorEvent == NULL);
    } else { //not root, so must have ancestor.
        cactusCheck(ancestorEvent != NULL);
    }

    //Each child event has event as parent.
    int64_t i = 0;
    for (i = 0; i < event_getChildNumber(event); i++) {
        Event *childEvent = event_getChild(event, i);
        cactusCheck(event_getParent(childEvent) == event);
    }

    //Ancestor-event --> event edge is consistent with any event tree that is in the parent of the containing flower.
    Group *parentGroup = flower_getParentGroup(eventTree_getFlower(
            event_getEventTree(event)));
    if (parentGroup != NULL) {
        EventTree *parentEventTree = flower_getEventTree(group_getFlower(
                parentGroup));
        Event *parentEvent = eventTree_getEvent(parentEventTree, event_getName(
                event));
        if (parentEvent != NULL) {
            if (ancestorEvent == NULL) { //the case where they are both root.
                cactusCheck(eventTree_getRootEvent(parentEventTree) == parentEvent);
            } else {
                //Check edge ancestorEvent --> event is in parent event tree.
                while (1) {
                    Event *parentAncestorEvent = eventTree_getEvent(
                            parentEventTree, event_getName(ancestorEvent));
                    if (parentAncestorEvent != NULL) {
                        cactusCheck(event_isAncestor(parentEvent, parentAncestorEvent));
                        break;
                    }
                    ancestorEvent = event_getParent(ancestorEvent);
                    cactusCheck(ancestorEvent != NULL);
                }
            }
        }
    }
}
コード例 #7
0
void testBlock_getChain(CuTest* testCase) {
    cactusBlockTestSetup();

    Block *block2 = block_construct(2, flower);
    Flower *flower2 = flower_construct(cactusDisk);
    eventTree_copyConstruct(flower_getEventTree(flower), flower2, NULL);
    end_copyConstruct(block_get3End(block), flower2);
    end_copyConstruct(block_get5End(block2), flower2);
    Group *group = group_construct(flower, flower2);
    Chain *chain = chain_construct(flower);
    link_construct(block_get3End(block), block_get5End(block2), group, chain);

    CuAssertTrue(testCase, block_getChain(block_construct(2, flower)) == NULL);
    CuAssertTrue(testCase, block_getChain(block) == chain);
    CuAssertTrue(testCase, block_getChain(block2) == chain);

    cactusBlockTestTeardown();
}
コード例 #8
0
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;
}
コード例 #9
0
void flower_removeEventTree(Flower *flower, EventTree *eventTree) {
    assert(flower_getEventTree(flower) == eventTree);
    flower->eventTree = NULL;
}
コード例 #10
0
void flower_setEventTree(Flower *flower, EventTree *eventTree) {
    if (flower_getEventTree(flower) != NULL) {
        eventTree_destruct(flower_getEventTree(flower));
    }
    flower->eventTree = eventTree;
}
コード例 #11
0
void testEventTree_addSiblingUnaryEvent(CuTest *testCase) {
	cactusEventTreeTestSetup();
	//Create two sibling flowers with the basic event tree..
	//then try adding events from on into the other.
	Group *group1 = group_construct2(flower);
	Group *group2 = group_construct2(flower);
	Flower *flower2 = flower_construct(cactusDisk);
	Flower *flower3 = flower_construct(cactusDisk);
	flower_setParentGroup(flower2, group1);
	flower_setParentGroup(flower3, group2);
	EventTree *eventTree2 = eventTree_copyConstruct(flower_getEventTree(flower), flower2, NULL);
	Event *parentUnaryEvent1 = event_construct4("UNARY1", 0.1, internalEvent, leafEvent1, eventTree);
	Event *parentUnaryEvent2 = event_construct4("UNARY2", 0.1, parentUnaryEvent1, leafEvent1, eventTree);
	Event *parentUnaryEvent3 = event_construct4("UNARY3", 0.1, internalEvent, leafEvent2, eventTree);
	//now event tree contains the added unary events.
	EventTree *eventTree3 = eventTree_copyConstruct(flower_getEventTree(flower), flower3, NULL);
	//add a couple of denovo events into the new event tree
	Event *internalEventChild = eventTree_getEvent(eventTree3, event_getName(internalEvent));
	Event *unaryEvent1 = eventTree_getEvent(eventTree3, event_getName(parentUnaryEvent1));
	Event *unaryEvent2 = eventTree_getEvent(eventTree3, event_getName(parentUnaryEvent2));
	Event *unaryEvent3 = eventTree_getEvent(eventTree3, event_getName(parentUnaryEvent3));
	Event *unaryEvent4 = event_construct4("UNARY4", 0.1,
			internalEventChild, unaryEvent3, eventTree3);
	Event *unaryEvent5 = event_construct4("UNARY5", 0.1,
				internalEventChild, unaryEvent4, eventTree3);
	//Now event-tree 2 does not contain the unary events but event-tree 3 does..

	CuAssertTrue(testCase, eventTree_getEvent(eventTree2, event_getName(unaryEvent1)) == NULL);
	CuAssertTrue(testCase, eventTree_getEvent(eventTree2, event_getName(unaryEvent2)) == NULL);
	CuAssertTrue(testCase, eventTree_getEvent(eventTree2, event_getName(unaryEvent3)) == NULL);
	CuAssertTrue(testCase, eventTree_getEvent(eventTree2, event_getName(unaryEvent4)) == NULL);
	CuAssertTrue(testCase, eventTree_getEvent(eventTree2, event_getName(unaryEvent5)) == NULL);

	eventTree_addSiblingUnaryEvent(eventTree2, unaryEvent1);
	Event *unaryEvent12 = eventTree_getEvent(eventTree2, event_getName(unaryEvent1));
	CuAssertTrue(testCase, unaryEvent12 != NULL);
	CuAssertTrue(testCase, event_getName(event_getParent(unaryEvent12)) == event_getName(internalEvent));
	CuAssertTrue(testCase, event_getChildNumber(unaryEvent12) == 1);
	CuAssertTrue(testCase, event_getName(event_getChild(unaryEvent12, 0)) == event_getName(leafEvent1));

	eventTree_addSiblingUnaryEvent(eventTree2, unaryEvent2);
	Event *unaryEvent22 = eventTree_getEvent(eventTree2, event_getName(unaryEvent2));
	CuAssertTrue(testCase, unaryEvent22 != NULL);
	CuAssertTrue(testCase, event_getName(event_getParent(unaryEvent22)) == event_getName(unaryEvent1));
	CuAssertTrue(testCase, event_getChildNumber(unaryEvent22) == 1);
	CuAssertTrue(testCase, event_getName(event_getChild(unaryEvent22, 0)) == event_getName(leafEvent1));

	eventTree_addSiblingUnaryEvent(eventTree2, unaryEvent3);
	Event *unaryEvent32 = eventTree_getEvent(eventTree2, event_getName(unaryEvent3));
	CuAssertTrue(testCase, unaryEvent32 != NULL);
	CuAssertTrue(testCase, event_getName(event_getParent(unaryEvent32)) == event_getName(internalEvent));
	CuAssertTrue(testCase, event_getChildNumber(unaryEvent32) == 1);
	CuAssertTrue(testCase, event_getName(event_getChild(unaryEvent32, 0)) == event_getName(leafEvent2));

	eventTree_addSiblingUnaryEvent(eventTree2, unaryEvent4);
	Event *unaryEvent42 = eventTree_getEvent(eventTree2, event_getName(unaryEvent4));
	CuAssertTrue(testCase, unaryEvent42 != NULL);
	CuAssertTrue(testCase, event_getName(event_getParent(unaryEvent42)) == event_getName(internalEvent));
	CuAssertTrue(testCase, event_getChildNumber(unaryEvent42) == 1);
	CuAssertTrue(testCase, event_getName(event_getChild(unaryEvent42, 0)) == event_getName(unaryEvent3));

	eventTree_addSiblingUnaryEvent(eventTree2, unaryEvent5);
	Event *unaryEvent52 = eventTree_getEvent(eventTree2, event_getName(unaryEvent5));
	CuAssertTrue(testCase, unaryEvent52 != NULL);
	CuAssertTrue(testCase, event_getName(event_getParent(unaryEvent52)) == event_getName(internalEvent));
	CuAssertTrue(testCase, event_getChildNumber(unaryEvent52) == 1);
	CuAssertTrue(testCase, event_getName(event_getChild(unaryEvent52, 0)) == event_getName(unaryEvent4));

	//uglyf("Event-tree-1 %s\n", eventTree_makeNewickString(eventTree));
	//uglyf("Event-tree-2 %s\n", eventTree_makeNewickString(eventTree3));
	//uglyf("Event-tree-3 %s\n", eventTree_makeNewickString(eventTree2));

	cactusEventTreeTestTeardown();
}
コード例 #12
0
int main(int argc, char *argv[]) {
    /*
     * Script for adding a reference genome to a flower.
     */

    /*
     * Arguments/options
     */
    char * logLevelString = NULL;
    char * cactusDiskDatabaseString = NULL;
    char *referenceEventString =
            (char *) cactusMisc_getDefaultReferenceEventHeader();
    char *outputFile = NULL;
    Name flowerName = NULL_NAME;

    ///////////////////////////////////////////////////////////////////////////
    // (0) Parse the inputs handed by genomeCactus.py / setup stuff.
    ///////////////////////////////////////////////////////////////////////////

    while (1) {
        static struct option long_options[] = { { "logLevel",
                required_argument, 0, 'a' }, { "cactusDisk", required_argument,
                0, 'c' },  { "flowerName", required_argument,
                        0, 'd' },
                { "referenceEventString", required_argument, 0, 'g' }, {
                        "help", no_argument, 0, 'h' }, { "outputFile",
                        required_argument, 0, 'k' },
                { 0, 0, 0, 0 } };

        int option_index = 0;

        int key = getopt_long(argc, argv, "a:c:d:g:hk:", long_options,
                &option_index);

        if (key == -1) {
            break;
        }

        switch (key) {
            case 'a':
                logLevelString = stString_copy(optarg);
                break;
            case 'c':
                cactusDiskDatabaseString = stString_copy(optarg);
                break;
            case 'd':
                flowerName = cactusMisc_stringToName(optarg);
                break;
            case 'g':
                referenceEventString = stString_copy(optarg);
                break;
            case 'h':
                usage();
                return 0;
            case 'k':
                outputFile = stString_copy(optarg);
                break;
            default:
                usage();
                return 1;
        }
    }

    ///////////////////////////////////////////////////////////////////////////
    // (0) Check the inputs.
    ///////////////////////////////////////////////////////////////////////////

    assert(cactusDiskDatabaseString != NULL);

    //////////////////////////////////////////////
    //Set up logging
    //////////////////////////////////////////////

    st_setLogLevelFromString(logLevelString);

    //////////////////////////////////////////////
    //Load the database
    //////////////////////////////////////////////

    stKVDatabaseConf *kvDatabaseConf = stKVDatabaseConf_constructFromString(
            cactusDiskDatabaseString);
    CactusDisk *cactusDisk = cactusDisk_construct(kvDatabaseConf, 0);
    stKVDatabaseConf_destruct(kvDatabaseConf);
    st_logInfo("Set up the flower disk\n");


    ///////////////////////////////////////////////////////////////////////////
    // Get the set of flowers to manipulate
    ///////////////////////////////////////////////////////////////////////////

    Flower *flower = cactusDisk_getFlower(cactusDisk, flowerName);

    ///////////////////////////////////////////////////////////////////////////
    // Get the reference event name
    ///////////////////////////////////////////////////////////////////////////

    Event *referenceEvent = eventTree_getEventByHeader(
            flower_getEventTree(flower), referenceEventString);
    assert(referenceEvent != NULL);
    Name referenceEventName = event_getName(referenceEvent);

    ///////////////////////////////////////////////////////////////////////////
    // Now process each flower in turn.
    ///////////////////////////////////////////////////////////////////////////
    
    if(outputFile == NULL) {
        st_errAbort("No output file specified\n");
    }
    FILE *fileHandle = fopen(outputFile, "w");
    printFastaSequences(flower, fileHandle, referenceEventName);
    if(fileHandle != NULL) {
        fclose(fileHandle);
    }

    ///////////////////////////////////////////////////////////////////////////
    //Clean up memory
    ///////////////////////////////////////////////////////////////////////////

    cactusDisk_destruct(cactusDisk);

    //return 0; //Exit without clean up is quicker, enable cleanup when doing memory leak detection.

    free(cactusDiskDatabaseString);
    free(referenceEventString);
    free(logLevelString);

    st_logInfo("Cleaned stuff up and am finished\n");
    //while(1);
    return 0;
}
コード例 #13
0
void testFlower_getEventTree(CuTest* testCase) {
    cactusFlowerTestSetup();
    CuAssertTrue(testCase, flower_getEventTree(flower) == eventTree);
    cactusFlowerTestTeardown();
}
コード例 #14
0
ファイル: cactusSequence.c プロジェクト: benedictpaten/cactus
Event *sequence_getEvent(Sequence *sequence) {
	return eventTree_getEvent(flower_getEventTree(sequence_getFlower(sequence)), metaSequence_getEventName(sequence->metaSequence));
}
コード例 #15
0
int main(int argc, char *argv[]) {
    /*
     * Script for adding a reference genome to a flower.
     */

    /*
     * Arguments/options
     */
    char * logLevelString = NULL;
    char * cactusDiskDatabaseString = NULL;
    char * secondaryDatabaseString = NULL;
    char *referenceEventString = (char *) cactusMisc_getDefaultReferenceEventHeader();
    bool bottomUpPhase = 0;

    ///////////////////////////////////////////////////////////////////////////
    // (0) Parse the inputs handed by genomeCactus.py / setup stuff.
    ///////////////////////////////////////////////////////////////////////////

    while (1) {
        static struct option long_options[] = { { "logLevel", required_argument, 0, 'a' }, { "cactusDisk", required_argument, 0, 'b' }, { "secondaryDisk", required_argument, 0, 'd' }, { "referenceEventString", required_argument, 0, 'g' }, { "help", no_argument,
                0, 'h' }, { "bottomUpPhase", no_argument, 0, 'j' }, { 0, 0, 0, 0 } };

        int option_index = 0;

        int key = getopt_long(argc, argv, "a:b:c:d:e:g:hi:j", long_options, &option_index);

        if (key == -1) {
            break;
        }

        switch (key) {
            case 'a':
                logLevelString = stString_copy(optarg);
                break;
            case 'b':
                cactusDiskDatabaseString = stString_copy(optarg);
                break;
            case 'd':
                secondaryDatabaseString = stString_copy(optarg);
                break;
            case 'g':
                referenceEventString = stString_copy(optarg);
                break;
            case 'h':
                usage();
                return 0;
            case 'j':
                bottomUpPhase = 1;
                break;
            default:
                usage();
                return 1;
        }
    }

    ///////////////////////////////////////////////////////////////////////////
    // (0) Check the inputs.
    ///////////////////////////////////////////////////////////////////////////

    assert(cactusDiskDatabaseString != NULL);

    //////////////////////////////////////////////
    //Set up logging
    //////////////////////////////////////////////

    st_setLogLevelFromString(logLevelString);

    //////////////////////////////////////////////
    //Load the database
    //////////////////////////////////////////////

    st_logInfo("referenceEventString = %s\n", referenceEventString);
    st_logInfo("bottomUpPhase = %i\n", bottomUpPhase);

    stKVDatabaseConf *kvDatabaseConf = stKVDatabaseConf_constructFromString(cactusDiskDatabaseString);
    CactusDisk *cactusDisk = cactusDisk_construct(kvDatabaseConf, false, true);
    stKVDatabaseConf_destruct(kvDatabaseConf);
    st_logInfo("Set up the flower disk\n");

    stKVDatabase *sequenceDatabase = NULL;
    if (secondaryDatabaseString != NULL) {
        kvDatabaseConf = stKVDatabaseConf_constructFromString(secondaryDatabaseString);
        sequenceDatabase = stKVDatabase_construct(kvDatabaseConf, 0);
        stKVDatabaseConf_destruct(kvDatabaseConf);
    }

    FlowerStream *flowerStream = flowerWriter_getFlowerStream(cactusDisk, stdin);
    Flower *flower;
    while ((flower = flowerStream_getNext(flowerStream)) != NULL) {
        st_logDebug("Processing flower %" PRIi64 "\n", flower_getName(flower));

        ///////////////////////////////////////////////////////////////////////////
        // Get the appropriate event names
        ///////////////////////////////////////////////////////////////////////////

        st_logInfo("%s\n", eventTree_makeNewickString(flower_getEventTree(flower)));
        Event *referenceEvent = eventTree_getEventByHeader(flower_getEventTree(flower), referenceEventString);
        if (referenceEvent == NULL) {
            st_errAbort("Reference event %s not found in tree. Check your "
                        "--referenceEventString option", referenceEventString);
        }
        Name referenceEventName = event_getName(referenceEvent);

        ///////////////////////////////////////////////////////////////////////////
        // Now do bottom up or top down, depending
        ///////////////////////////////////////////////////////////////////////////
        stList *flowers = stList_construct();
        stList_append(flowers, flower);
        preCacheNestedFlowers(cactusDisk, flowers);
        if (bottomUpPhase) {
            assert(sequenceDatabase != NULL);

            cactusDisk_preCacheSegmentStrings(cactusDisk, flowers);
            bottomUp(flowers, sequenceDatabase, referenceEventName, !flower_hasParentGroup(flower), generateJukesCantorMatrix);

            // Unload the nested flowers to save memory. They haven't
            // been changed, so we don't write them to the cactus
            // disk.
            Flower_GroupIterator *groupIt = flower_getGroupIterator(flower);
            Group *group;
            while ((group = flower_getNextGroup(groupIt)) != NULL) {
                if (!group_isLeaf(group)) {
                    flower_unload(group_getNestedFlower(group));
                }
            }
            flower_destructGroupIterator(groupIt);
            assert(!flower_isParentLoaded(flower));

            // Write this flower to disk.
            cactusDisk_addUpdateRequest(cactusDisk, flower);
        } else {
            topDown(flower, referenceEventName);

            // We've changed the nested flowers, but not this
            // flower. We write the nested flowers to disk, then
            // unload them to save memory. This flower will be
            // unloaded by the flower-stream code.
            Flower_GroupIterator *groupIt = flower_getGroupIterator(flower);
            Group *group;
            while ((group = flower_getNextGroup(groupIt)) != NULL) {
                if (!group_isLeaf(group)) {
                    cactusDisk_addUpdateRequest(cactusDisk, group_getNestedFlower(group));
                    flower_unload(group_getNestedFlower(group));
                }
            }
            flower_destructGroupIterator(groupIt);
        }
        stList_destruct(flowers);
    }

    ///////////////////////////////////////////////////////////////////////////
    // Write the flower(s) back to disk.
    ///////////////////////////////////////////////////////////////////////////

    cactusDisk_write(cactusDisk);
    st_logInfo("Updated the flower on disk\n");

    ///////////////////////////////////////////////////////////////////////////
    //Clean up.
    ///////////////////////////////////////////////////////////////////////////

    if (sequenceDatabase != NULL) {
        stKVDatabase_destruct(sequenceDatabase);
    }

    cactusDisk_destruct(cactusDisk);

    return 0; //Exit without clean up is quicker, enable cleanup when doing memory leak detection.

    free(cactusDiskDatabaseString);
    free(referenceEventString);
    free(logLevelString);

    st_logInfo("Cleaned stuff up and am finished\n");

    return 0;
}