<commit_before>/*
 * Copyright (C) 2009-2013 by <NAME> (<EMAIL>)
 *
 * Released under the MIT license, see LICENSE.txt
 */

#include <assert.h>
#include <getopt.h>

#include "cactus.h"
#include "sonLib.h"
#include "endAligner.h"
#include "flowerAligner.h"
#include "commonC.h"
#include "stCaf.h"
#include "stPinchGraphs.h"
#include "stPinchIterator.h"

void usage() {
    fprintf(stderr, "cactus_baseReAligner [options] seq1[fasta] seq2[fasta], version 0.2\n");
    fprintf(stderr,
            "Realigns a set of pairwise alignments, as cigars, read from the command line and written back to the command line\n");
    fprintf(stderr, "-a --logLevel : Set the log level\n");
    fprintf(stderr, "-l --gapGamma : (float [0, 1]) The gap gamma (as in the AMAP function)\n");
    fprintf(stderr,
            "-o --splitMatrixBiggerThanThis : (int >= 0)  No dp matrix bigger than this number squared will be computed.\n");
    fprintf(stderr, "-r --digaonalExpansion : (int >= 0 and even) Number of x-y diagonals to expand around anchors\n");
    fprintf(stderr, "-t --constraintDiagonalTrim : (int >= 0) Amount to trim from ends of each anchor\n");
    fprintf(stderr,
            "-w --alignAmbiguityCharacters : Align ambiguity characters (anything not ACTGactg) as a wildcard\n");
    fprintf(stderr, "-h --help : Print this help screen\n");
}

struct PairwiseAlignment *convertAlignedPairsToPairwiseAlignment(char *seqName1, char *seqName2, int64_t score,
        stList *alignedPairs) {
    //Make pairwise alignment
    int64_t pX = -1, pY = -1, mL = 0;
    struct List *opList = constructEmptyList(0, (void(*)(void *)) destructAlignmentOperation);
    for (int64_t i = 0; i < stList_length(alignedPairs); i++) {
        stIntTuple *alignedPair = stList_get(alignedPairs, i);
        int64_t x = stIntTuple_get(alignedPair, 1);
        int64_t y = stIntTuple_get(alignedPair, 2);
        assert(x - pX > 0);
        assert(y - pY > 0);
        if (x - pX > 1) { //There is an indel.
            if (mL > 0) {
                listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL, 0));
                mL = 0;
            }
            listAppend(opList, constructAlignmentOperation(PAIRWISE_INDEL_X, x - pX -1, 0));
        } else if (y - pY > 1) {
            if (mL > 0) {
                listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL, 0));
                mL = 0;
            }
            listAppend(opList, constructAlignmentOperation(PAIRWISE_INDEL_Y, y - pY - 1, 0));
        }
        mL++;
        pX = x;
        pY = y;
    }
    if (mL > 0) {
        listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL, 0));
    }
    struct PairwiseAlignment *pA = constructPairwiseAlignment(seqName1, 0, pX+1, 1, seqName2, 0, pY+1, 1, score, opList);
    return pA;
}

void rebasePairwiseAlignmentCoordinates(int64_t *start, int64_t *end, int64_t *strand, int64_t coordinateShift,
        bool flipStrand) {
    *start += coordinateShift;
    *end += coordinateShift;
    if (flipStrand) {
        *strand = !(*strand);
    }
}

char *getSubSequence(char *seq, int64_t start, int64_t end, bool strand) {
    return strand ? stString_getSubString(seq, start, end - start) : cactusMisc_reverseComplementString(
            stString_getSubString(seq, end, start - end));
}

stHash *sequences = NULL;
void addToSequencesHash(const char *header, const char *sequence, int64_t length) {
    if (stHash_search(sequences, (char *) header) != NULL) {
        assert(stString_eq(sequence, stHash_search(sequences, header)));
    } else {
        stHash_insert(sequences, stString_copy(header), stString_copy(sequence));
    }
}

int main(int argc, char *argv[]) {
    char * logLevelString = NULL;
    float gapGamma = 0.5;
    int64_t i, j;
    PairwiseAlignmentParameters *pairwiseAlignmentBandingParameters = pairwiseAlignmentBandingParameters_construct();

    /*
     * Parse the options.
     */
    while (1) {
        static struct option long_options[] = { { "logLevel", required_argument, 0, 'a' }, { "help", no_argument, 0,
                'h' }, { "gapGamma", required_argument, 0, 'l' }, { "splitMatrixBiggerThanThis", required_argument, 0,
                'o' }, { "diagonalExpansion", required_argument, 0, 'r' }, { "constraintDiagonalTrim",
                required_argument, 0, 't' }, { "alignAmbiguityCharacters", no_argument, 0, 'w' }, { 0, 0, 0, 0 } };

        int option_index = 0;

        int key = getopt_long(argc, argv, "a:hl:o:r:t:wx:y:", long_options, &option_index);

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

        switch (key) {
            case 'a':
                logLevelString = stString_copy(optarg);
                st_setLogLevelFromString(logLevelString);
                break;
            case 'h':
                usage();
                return 0;<commit_msg>Adding in binary to realign blast hits.<commit_after>/*
 * Copyright (C) 2009-2013 by <NAME> (<EMAIL>)
 *
 * Released under the MIT license, see LICENSE.txt
 */

#include <assert.h>
#include <getopt.h>

#include "cactus.h"
#include "sonLib.h"
#include "endAligner.h"
#include "flowerAligner.h"
#include "commonC.h"
#include "stCaf.h"
#include "stPinchGraphs.h"
#include "stPinchIterator.h"

void usage() {
    fprintf(stderr, "cactus_baseReAligner [options] seq1[fasta] seq2[fasta], version 0.2\n");
    fprintf(stderr,
            "Realigns a set of pairwise alignments, as cigars, read from the command line and written back to the command line\n");
    fprintf(stderr, "-a --logLevel : Set the log level\n");
    fprintf(stderr, "-l --gapGamma : (float [0, 1]) The gap gamma (as in the AMAP function)\n");
    fprintf(stderr,
            "-o --splitMatrixBiggerThanThis : (int >= 0)  No dp matrix bigger than this number squared will be computed.\n");
    fprintf(stderr, "-r --digaonalExpansion : (int >= 0 and even) Number of x-y diagonals to expand around anchors\n");
    fprintf(stderr, "-t --constraintDiagonalTrim : (int >= 0) Amount to trim from ends of each anchor\n");
    fprintf(stderr,
            "-w --alignAmbiguityCharacters : Align ambiguity characters (anything not ACTGactg) as a wildcard\n");
    fprintf(stderr, "-h --help : Print this help screen\n");
}

struct PairwiseAlignment *convertAlignedPairsToPairwiseAlignment(char *seqName1, char *seqName2, int64_t score,
        stList *alignedPairs) {
    //Make pairwise alignment
    int64_t pX = -1, pY = -1, mL = 0;
    struct List *opList = constructEmptyList(0, (void(*)(void *)) destructAlignmentOperation);
    for (int64_t i = 0; i < stList_length(alignedPairs); i++) {
        stIntTuple *alignedPair = stList_get(alignedPairs, i);
        int64_t x = stIntTuple_get(alignedPair, 1);
        int64_t y = stIntTuple_get(alignedPair, 2);
        assert(x - pX > 0);
        assert(y - pY > 0);
        if (x - pX > 1) { //There is an indel.
            if (mL > 0) {
                listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL, 0));
                mL = 0;
            }
            listAppend(opList, constructAlignmentOperation(PAIRWISE_INDEL_X, x - pX -1, 0));
        } else if (y - pY > 1) {
            if (mL > 0) {
                listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL, 0));
                mL = 0;
            }
            listAppend(opList, constructAlignmentOperation(PAIRWISE_INDEL_Y, y - pY - 1, 0));
        }
        mL++;
        pX = x;
        pY = y;
    }
    if (mL > 0) {
        listAppend(opList, constructAlignmentOperation(PAIRWISE_MATCH, mL, 0));
    }
    struct PairwiseAlignment *pA = constructPairwiseAlignment(seqName1, 0, pX+1, 1, seqName2, 0, pY+1, 1, score, opList);
    return pA;
}

void rebasePairwiseAlignmentCoordinates(int64_t *start, int64_t *end, int64_t *strand, int64_t coordinateShift,
        bool flipStrand) {
    *start += coordinateShift;
    *end += coordinateShift;
    if (flipStrand) {
        *strand = !(*strand);
    }
}

char *getSubSequence(char *seq, int64_t start, int64_t end, bool strand) {
    return strand ? stString_getSubString(seq, start, end - start) : cactusMisc_reverseComplementString(
            stString_getSubString(seq, end, start - end));
}

stHash *sequences = NULL;
void addToSequencesHash(const char *header, const char *sequence, int64_t length) {
    if (stHash_search(sequences, (char *) header) != NULL) {
        assert(stString_eq(sequence, stHash_search(sequences, header)));
    } else {
        stHash_insert(sequences, stString_copy(header), stString_copy(sequence));
    }
}

int main(int argc, char *argv[]) {
    char * logLevelString = NULL;
    float gapGamma = 0.2;
    int64_t i, j;
    PairwiseAlignmentParameters *pairwiseAlignmentBandingParameters = pairwiseAlignmentBandingParameters_construct();
    pairwiseAlignmentBandingParameters->constraintDiagonalTrim = 3;
    pairwiseAlignmentBandingParameters->splitMatrixBiggerThanThis = 100;
    pairwiseAlignmentBandingParameters->diagonalExpansion = 10;

    /*
     * Parse the options.
     */
    while (1) {
        static struct option long_options[] = { { "logLevel", required_argument, 0, 'a' }, { "help", no_argument, 0,
                'h' }, { "gapGamma", required_argument, 0, 'l' }, { "splitMatrixBiggerThanThis", required_argument, 0,
                'o' }, { "diagonalExpansion", required_argument, 0, 'r' }, { "constraintDiagonalTrim",
                required_argument, 0, 't' }, { "alignAmbiguityCharacters", no_argument, 0, 'w' }, { 0, 0, 0, 0 } };

        int option_index = 0;

        int key = getopt_long(argc, argv, "a:hl:o:r:t:wx:y:", long_options, &option_index);

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

        switch (key) {
            case 'a':
                logLevelString = stString_copy(optarg);
                st_setLogLevelFromString(logLevelString);
                break;
            case 'h':
                usage();
                return 0;
{'fraction_non_alphanumeric': 0.12606902102827247, 'fraction_numerical': 0.01931783881678237, 'mean_word_length': 2.8084291187739465, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 34, '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': '5962211', 'n_tokens_mistral': 3416, 'n_tokens_neox': 3166, 'n_words': 845}