<commit_before>/*
 * The script builds a cactus tree representation of the chains and nets.
 * The format of the output graph is dot format.
 */
#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <getopt.h>

#include "cactus.h"
#include "avl.h"
#include "commonC.h"
#include "hashTableC.h"

/*
 * Global variables.
 */
static bool edgeColours = 1;
static bool nameLabels = 0;

static void usage() {
    fprintf(stderr, "cactus_graphViewer, version 0.2\n");
    fprintf(stderr, "-a --logLevel : Set the log level\n");
    fprintf(stderr, "-c --netDisk : The location of the net disk directory\n");
    fprintf(stderr,
            "-d --netName : The name of the net (the key in the database)\n");
    fprintf(stderr,
            "-e --outputFile : The file to write the dot graph file in.\n");
    fprintf(
            stderr,
            "-f --chainColours : Do not give chains distinct colours (instead of just black)\n");
    fprintf(stderr, "-g --nameLabels : Give chain and net nodes name labels.\n");
    fprintf(stderr, "-h --help : Print this help screen\n");
}

void addEndNodeToGraph(End *end, FILE *fileHandle) {
    const char *nameString = netMisc_nameToStringStatic(end_getName(end));
    graphViz_addNodeToGraph(nameString, fileHandle, nameString, 0.5, 0.5,
            "circle", "black", 14);
}

void addEdgeToGraph(End *end1, End *end2, const char *colour,
        const char *label, double length, double weight, const char *direction,
        FILE *fileHandle) {
    char *nameString1 = netMisc_nameToString(end_getName(end1));
    char *nameString2 = netMisc_nameToString(end_getName(end2));
    graphViz_addEdgeToGraph(nameString1, nameString2, fileHandle,
            nameLabels ? label : "", colour, length, weight, direction);
    free(nameString1);
    free(nameString2);
}

void addBlockToGraph(Block *block, const char *colour, FILE *fileHandle) {
    static char label[100000];
    End *leftEnd = block_get5End(block);
    End *rightEnd = block_get3End(block);
    addEndNodeToGraph(leftEnd, fileHandle);
    addEndNodeToGraph(rightEnd, fileHandle);
    Block_InstanceIterator *iterator = block_getInstanceIterator(block);
    Segment *segment;
    while ((segment = block_getNext(iterator)) != NULL) {
        segment = segment_getStrand(segment) ? segment : segment_getReverse(
                segment);
        if (segment_getSequence(segment) != NULL) {
            sprintf(label, "%s:%i:%i", netMisc_nameToStringStatic(
                    sequence_getName(segment_getSequence(segment))),
                    segment_getStart(segment), segment_getStart(segment)
                            + segment_getLength(segment));
            addEdgeToGraph(cap_getEnd(segment_get5Cap(segment)), cap_getEnd(
                    segment_get3Cap(segment)), edgeColours ? colour : "black",
                    label, 1.5, 100, "forward", fileHandle);
        }
    }
    block_destructInstanceIterator(iterator);
}

void addTrivialChainsToGraph(Net *net, FILE *fileHandle) {
    /*
     * Add blocks not part of chain to the graph
     */
    Net_BlockIterator *blockIterator = net_getBlockIterator(net);
    Block *block;
    while ((block = net_getNextBlock(blockIterator)) != NULL) {
        if (block_getChain(block) == NULL) {
            addBlockToGraph(block, "black", fileHandle);
        }
    }
    net_destructBlockIterator(blockIterator);
}

void addChainsToGraph(Net *net, FILE *fileHandle) {
    /*
     * Add blocks part of a chain to the graph.
     */
    Net_ChainIterator *chainIterator = net_getChainIterator(net);
    Chain *chain;
    while ((chain = net_getNextChain(chainIterator)) != NULL) {
        int32_t i, j;
        const char *chainColour;
        while ((chainColour = graphViz_getColour(chainColour)) != NULL) { //ensure the chain colours don't match the trivial block chains and the adjacencies.
            if (strcmp(chainColour, "black") != 0
                    && strcmp(chainColour, "grey") != 0) {
                break;
            }
        }
        Block **blocks = chain_getBlockChain(chain, &i);
        for (j = 0; j < i; j++) {
            addBlockToGraph(blocks[j], chainColour, fileHandle);
        }
        free(blocks);
    }<commit_msg>fixed small bug in build. <commit_after>/*
 * The script builds a cactus tree representation of the chains and nets.
 * The format of the output graph is dot format.
 */
#include <assert.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <getopt.h>

#include "cactus.h"
#include "avl.h"
#include "commonC.h"
#include "hashTableC.h"

/*
 * Global variables.
 */
static bool edgeColours = 1;
static bool nameLabels = 0;

static void usage() {
    fprintf(stderr, "cactus_graphViewer, version 0.2\n");
    fprintf(stderr, "-a --logLevel : Set the log level\n");
    fprintf(stderr, "-c --netDisk : The location of the net disk directory\n");
    fprintf(stderr,
            "-d --netName : The name of the net (the key in the database)\n");
    fprintf(stderr,
            "-e --outputFile : The file to write the dot graph file in.\n");
    fprintf(
            stderr,
            "-f --chainColours : Do not give chains distinct colours (instead of just black)\n");
    fprintf(stderr, "-g --nameLabels : Give chain and net nodes name labels.\n");
    fprintf(stderr, "-h --help : Print this help screen\n");
}

void addEndNodeToGraph(End *end, FILE *fileHandle) {
    const char *nameString = netMisc_nameToStringStatic(end_getName(end));
    graphViz_addNodeToGraph(nameString, fileHandle, nameString, 0.5, 0.5,
            "circle", "black", 14);
}

void addEdgeToGraph(End *end1, End *end2, const char *colour,
        const char *label, double length, double weight, const char *direction,
        FILE *fileHandle) {
    char *nameString1 = netMisc_nameToString(end_getName(end1));
    char *nameString2 = netMisc_nameToString(end_getName(end2));
    graphViz_addEdgeToGraph(nameString1, nameString2, fileHandle,
            nameLabels ? label : "", colour, length, weight, direction);
    free(nameString1);
    free(nameString2);
}

void addBlockToGraph(Block *block, const char *colour, FILE *fileHandle) {
    static char label[100000];
    End *leftEnd = block_get5End(block);
    End *rightEnd = block_get3End(block);
    addEndNodeToGraph(leftEnd, fileHandle);
    addEndNodeToGraph(rightEnd, fileHandle);
    Block_InstanceIterator *iterator = block_getInstanceIterator(block);
    Segment *segment;
    while ((segment = block_getNext(iterator)) != NULL) {
        segment = segment_getStrand(segment) ? segment : segment_getReverse(
                segment);
        if (segment_getSequence(segment) != NULL) {
            sprintf(label, "%s:%i:%i", netMisc_nameToStringStatic(
                    sequence_getName(segment_getSequence(segment))),
                    segment_getStart(segment), segment_getStart(segment)
                            + segment_getLength(segment));
            addEdgeToGraph(cap_getEnd(segment_get5Cap(segment)), cap_getEnd(
                    segment_get3Cap(segment)), edgeColours ? colour : "black",
                    label, 1.5, 100, "forward", fileHandle);
        }
    }
    block_destructInstanceIterator(iterator);
}

void addTrivialChainsToGraph(Net *net, FILE *fileHandle) {
    /*
     * Add blocks not part of chain to the graph
     */
    Net_BlockIterator *blockIterator = net_getBlockIterator(net);
    Block *block;
    while ((block = net_getNextBlock(blockIterator)) != NULL) {
        if (block_getChain(block) == NULL) {
            addBlockToGraph(block, "black", fileHandle);
        }
    }
    net_destructBlockIterator(blockIterator);
}

void addChainsToGraph(Net *net, FILE *fileHandle) {
    /*
     * Add blocks part of a chain to the graph.
     */
    Net_ChainIterator *chainIterator = net_getChainIterator(net);
    Chain *chain;
    while ((chain = net_getNextChain(chainIterator)) != NULL) {
        int32_t i, j;
        const char *chainColour;
        while ((chainColour = graphViz_getColour()) != NULL) { //ensure the chain colours don't match the trivial block chains and the adjacencies.
            if (strcmp(chainColour, "black") != 0
                    && strcmp(chainColour, "grey") != 0) {
                break;
            }
        }
        Block **blocks = chain_getBlockChain(chain, &i);
        for (j = 0; j < i; j++) {
            addBlockToGraph(blocks[j], chainColour, fileHandle);
        }
        free(blocks);
    }
{'fraction_non_alphanumeric': 0.11838115232097038, 'fraction_numerical': 0.009330534173081408, 'mean_word_length': 2.9389067524115755, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4888048', 'n_tokens_mistral': 2632, 'n_tokens_neox': 2570, 'n_words': 691}