void mapGenes(Flower *flower, FILE *fileHandle, struct bed *gene, char *species){ st_logInfo("Flower %s\n", cactusMisc_nameToString(flower_getName(flower))); printOpeningTag("geneMap", fileHandle); fprintf(fileHandle, "\n"); int level = 0;//Flower level while(gene != NULL){ //Get the start of the target sequence: st_logInfo("Gene %s:\n", gene->name); Cap *startCap; struct List *capList = flower_getThreadStarts(flower, species); for(int i=0; i < capList->length; i++){ startCap = capList->list[i]; st_logInfo("Cap %d, %s\n", i, cactusMisc_nameToString(cap_getName(startCap))); //Traverse cactus and get regions that overlap with exons of the gene, report the involved chains relations fprintf(fileHandle, "\t<gene name=\"%s\" target=\"%s\" start=\"%" PRIi64 "\" end=\"%" PRIi64 "\" exonCount=\"%" PRIi64 "\" strand=\"%c\">\n", gene->name, species, gene->chromStart, gene->chromEnd, gene->blockCount, gene->strand[0]); fprintf(fileHandle, "\t\t<exon id=\"0\" start=\"%" PRIi64 "\" end=\"%" PRIi64 "\">\n", gene->chromStart, gene->chromStart + gene->blockSizes->list[0]); mapGene(startCap, level, 0, gene, fileHandle); fprintf(fileHandle, "\t</gene>\n"); } gene = gene->next; } printClosingTag("geneMap", fileHandle); return; }
void makeCactusTree_chain(Chain *chain, FILE *fileHandle, const char *parentNodeName, const char *parentEdgeColour) { //Write the flower nodes. char *chainNameString = cactusMisc_nameToString(chain_getName(chain)); const char *edgeColour = graphViz_getColour(); addNodeToGraph(chainNameString, fileHandle, chain_getAverageInstanceBaseLength(chain) / totalProblemSize, "box", chainNameString); //Write in the parent edge. if (parentNodeName != NULL) { graphViz_addEdgeToGraph(parentNodeName, chainNameString, fileHandle, "", parentEdgeColour, 10, 1, "forward"); } //Create the linkers to the nested flowers. Link *link = chain_getFirst(chain); while(link != NULL) { Group *group = link_getGroup(link); assert(group != NULL); assert(!group_isLeaf(group)); if (!group_isLeaf(group)) { makeCactusTree_flower(group_getNestedFlower(group), fileHandle, chainNameString, edgeColour); } link = link_getNextLink(link); } free(chainNameString); }
void mapBlockToExon(Cap *cap, int level, FILE *fileHandle){ fprintf(fileHandle, "\t\t\t<block>\n"); Block *block = end_getBlock(cap_getEnd(cap)); Chain *chain = block_getChain(block); int start = cap_getCoordinate(cap); int end = cap_getCoordinate(cap_getOtherSegmentCap(cap)) +1; fprintf(fileHandle, "\t\t\t\t<blockName>%s</blockName>\n", cactusMisc_nameToString(block_getName(block))); if(chain != NULL){ fprintf(fileHandle, "\t\t\t\t<chainName>%s</chainName>\n", cactusMisc_nameToString(chain_getName(chain))); }else{ fprintf(fileHandle, "\t\t\t\t<chainName>NA</chainName>\n"); } fprintf(fileHandle, "\t\t\t\t<level>%d</level>\n", level); fprintf(fileHandle, "\t\t\t\t<start>%d</start>\n", start); fprintf(fileHandle, "\t\t\t\t<end>%d</end>\n", end); fprintf(fileHandle, "\t\t\t</block>\n"); st_logInfo("mapBlockToExon: start: %d, end: %d\n", start, end); }
static char *formatSequenceHeader(Sequence *sequence) { const char *sequenceHeader = sequence_getHeader(sequence); if (strlen(sequenceHeader) > 0) { char *cA = st_malloc(sizeof(char) * (1 + strlen(sequenceHeader))); sscanf(sequenceHeader, "%s", cA); return cA; } else { return cactusMisc_nameToString(sequence_getName(sequence)); } }
void makeCactusTree_terminalNode(Flower *flower, FILE *fileHandle, const char *parentNodeName, const char *parentEdgeColour) { char *groupNameString = cactusMisc_nameToString(flower_getName(flower)); double scalingFactor = flower_getTotalBaseLength(flower) / totalProblemSize; assert(scalingFactor <= 1.001); assert(scalingFactor >= -0.001); addNodeToGraph(groupNameString, fileHandle, scalingFactor, "triangle", groupNameString); //Write in the parent edge. if (parentNodeName != NULL) { graphViz_addEdgeToGraph(parentNodeName, groupNameString, fileHandle, "", parentEdgeColour, 10, 1, "forward"); } free(groupNameString); }
void testCactusDisk_getUniqueID_Unique(CuTest* testCase) { cactusDiskTestSetup(); stSortedSet *uniqueNames = stSortedSet_construct3(testCactusDisk_getUniqueID_UniqueP, free); for (int64_t i = 0; i < 100000; i++) { //Gets a billion ids, checks we are good. Name uniqueName = cactusDisk_getUniqueID(cactusDisk); CuAssertTrue(testCase, uniqueName > 0); CuAssertTrue(testCase, uniqueName < INT64_MAX); CuAssertTrue(testCase, uniqueName != NULL_NAME); char *cA = cactusMisc_nameToString(uniqueName); CuAssertTrue(testCase, stSortedSet_search(uniqueNames, cA) == NULL); CuAssertTrue(testCase, cactusMisc_stringToName(cA) == uniqueName); stSortedSet_insert(uniqueNames, cA); } stSortedSet_destruct(uniqueNames); cactusDiskTestTeardown(); }
void testCactusDisk_getUniqueID_UniqueIntervals(CuTest* testCase) { cactusDiskTestSetup(); stSortedSet *uniqueNames = stSortedSet_construct3(testCactusDisk_getUniqueID_UniqueP, free); for (int64_t i = 0; i < 10; i++) { //Gets a billion ids, checks we are good. int64_t intervalSize = st_randomInt(0, 100000); Name uniqueName = cactusDisk_getUniqueIDInterval(cactusDisk, intervalSize); for(int64_t j=0; j<intervalSize; j++) { CuAssertTrue(testCase, uniqueName > 0); CuAssertTrue(testCase, uniqueName < INT64_MAX); CuAssertTrue(testCase, uniqueName != NULL_NAME); char *cA = cactusMisc_nameToString(uniqueName); CuAssertTrue(testCase, stSortedSet_search(uniqueNames, cA) == NULL); CuAssertTrue(testCase, cactusMisc_stringToName(cA) == uniqueName); stSortedSet_insert(uniqueNames, cA); uniqueName++; } } stSortedSet_destruct(uniqueNames); cactusDiskTestTeardown(); }
void makeCactusTree_flower(Flower *flower, FILE *fileHandle, const char *parentNodeName, const char *parentEdgeColour) { if(flower_isTerminal(flower)) { makeCactusTree_terminalNode(flower, fileHandle, parentNodeName, parentEdgeColour); } else { //Write the flower nodes. char *flowerNameString = cactusMisc_nameToString(flower_getName(flower)); const char *edgeColour = graphViz_getColour(); addNodeToGraph(flowerNameString, fileHandle, flower_getTotalBaseLength(flower) / totalProblemSize, "ellipse", flowerNameString); //Write in the parent edge. if (parentNodeName != NULL) { graphViz_addEdgeToGraph(parentNodeName, flowerNameString, fileHandle, "", parentEdgeColour, 10, 1, "forward"); } //Create the chains. Flower_ChainIterator *chainIterator = flower_getChainIterator(flower); Chain *chain; while ((chain = flower_getNextChain(chainIterator)) != NULL) { makeCactusTree_chain(chain, fileHandle, flowerNameString, edgeColour); } flower_destructChainIterator(chainIterator); //Create the diamond node char *diamondNodeNameString = st_malloc(sizeof(char) * (strlen( flowerNameString) + 2)); sprintf(diamondNodeNameString, "z%s", flowerNameString); const char *diamondEdgeColour = graphViz_getColour(); //Create all the groups linked to the diamond. Flower_GroupIterator *groupIterator = flower_getGroupIterator(flower); Group *group; double size = 0.0; //get the size of the group organising node.. int64_t nonTrivialGroupCount = 0; while ((group = flower_getNextGroup(groupIterator)) != NULL) { assert(!group_isLeaf(group)); if (group_isTangle(group)) { size += group_getTotalBaseLength(group); nonTrivialGroupCount++; } } flower_destructGroupIterator(groupIterator); if(nonTrivialGroupCount == 0) { assert(flower_getParentGroup(flower) == 0); } else { //assert(nonTrivialGroupCount > 0); addNodeToGraph(diamondNodeNameString, fileHandle, size / totalProblemSize, "diamond", ""); graphViz_addEdgeToGraph(flowerNameString, diamondNodeNameString, fileHandle, "", edgeColour, 10, 1, "forward"); groupIterator = flower_getGroupIterator(flower); while ((group = flower_getNextGroup(groupIterator)) != NULL) { if (group_isTangle(group)) { assert(!group_isLeaf(group)); makeCactusTree_flower(group_getNestedFlower(group), fileHandle, diamondNodeNameString, diamondEdgeColour); } } flower_destructGroupIterator(groupIterator); } free(flowerNameString); free(diamondNodeNameString); } }