<commit_before>/*****************************************************************************
 * SV_BreakPoint.cpp
 * (c) 2012 - <NAME>
 * Hall Laboratory
 * Quinlan Laboratory
 * Department of Computer Science
 * Department of Biochemistry and Molecular Genetics
 * Department of Public Health Sciences and Center for Public Health Genomics,
 * University of Virginia
 * <EMAIL>
 *
 * Licenced under the GNU General Public License 2.0 license.
 * ***************************************************************************/


#include "SV_BreakPoint.h"
#include "SV_Evidence.h"
#include "SV_Tools.h"
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <climits>
#include <sstream>
#include <map>


double SV_BreakPoint::p_trim_threshold = 1;;
double SV_BreakPoint::p_merge_threshold = 0;
const int SV_BreakPoint::DELETION;
const int SV_BreakPoint::DUPLICATION;
const int SV_BreakPoint::INVERSION;
const int SV_BreakPoint::TRANSLOCATION;


//{{{ SV_BreakPoint:: SV_BreakPoint(SV_Evidence *e)
SV_BreakPoint::
SV_BreakPoint(SV_Evidence *e)
{
    evidence.push_back(e);

    ids[e->id] = 1;
}
//}}}

//{{{ SV_BreakPoint:: SV_BreakPoint(SV_BreakPoint *a, SV_BreakPoint *b)
SV_BreakPoint::
SV_BreakPoint(SV_BreakPoint *a, SV_BreakPoint *b)
{
    a->init_interval_probabilities();
    b->init_interval_probabilities();

    // a may not overlap b, so we need to check
    // after this ar_overlap_intr will point to the interval in a that
    // overlaps the right interval in b, and al_overlap_intr will point to the
    // interval in a that overlaps the left interval in b
    struct breakpoint_interval *al_overlap_intr = NULL,
                                        *ar_overlap_intr = NULL;

    if ( does_intersect(&(a->interval_l), &(b->interval_l), false) &&
            does_intersect(&(a->interval_r), &(b->interval_r), false) ) {
        al_overlap_intr = &(a->interval_l);
        ar_overlap_intr = &(a->interval_r);
    } else if ( does_intersect(&(a->interval_r), &(b->interval_l), false) &&
                does_intersect(&(a->interval_l), &(b->interval_r), false) ) {
        ar_overlap_intr = &(a->interval_l);
        al_overlap_intr = &(a->interval_r);
    } else {
        throw 0;
    }

    if ( (al_overlap_intr != NULL) && (ar_overlap_intr != NULL) ) {
        CHR_POS r_merged_start,
                r_merged_end,
                l_merged_start,
                l_merged_end;

        log_space *r_merged_prob, *l_merged_prob;

        bool l_merges = test_interval_merge(&(b->interval_l),
                                            al_overlap_intr,
                                            &l_merged_start,
                                            &l_merged_end,
                                            &l_merged_prob);


        bool r_merges = test_interval_merge(&(b->interval_r),
                                            ar_overlap_intr,
                                            &r_merged_start,
                                            &r_merged_end,
                                            &r_merged_prob);

        weight = 0;

        if (r_merges && l_merges) {

            interval_l.i.start = l_merged_start;
            interval_l.i.end = l_merged_end;
            interval_l.p = l_merged_prob;

            interval_r.i.start = r_merged_start;
            interval_r.i.end = r_merged_end;
            interval_r.p = r_merged_prob;

            vector<SV_Evidence*>::iterator ev_it;

            for (ev_it = a->evidence.begin(); ev_it < a->evidence.end(); ++ev_it)
                evidence.push_back(*ev_it);

            for (ev_it = b->evidence.begin(); ev_it < b->evidence.end(); ++ev_it)
                evidence.push_back(*ev_it);

            map<int, int>::iterator id_it;

            for (id_it = a->ids.begin(); id_it != a->ids.end(); ++id_it) {
                if ( ids.find( id_it->first ) == ids.end() )
                    ids[id_it->first] = 0;
                ids[id_it->first] += id_it->second;
            }

            for (id_it = a->ids.begin(); id_it != a->ids.end(); ++id_it) {
                if ( ids.find( id_it->first ) == ids.end() )
                    ids[id_it->first] = 0;
                ids[id_it->first] += id_it->second;
            }<commit_msg>problem merging evidence from 2 breakpoints<commit_after>/*****************************************************************************
 * SV_BreakPoint.cpp
 * (c) 2012 - <NAME>
 * Hall Laboratory
 * Quinlan Laboratory
 * Department of Computer Science
 * Department of Biochemistry and Molecular Genetics
 * Department of Public Health Sciences and Center for Public Health Genomics,
 * University of Virginia
 * <EMAIL>
 *
 * Licenced under the GNU General Public License 2.0 license.
 * ***************************************************************************/


#include "SV_BreakPoint.h"
#include "SV_Evidence.h"
#include "SV_Tools.h"
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <climits>
#include <sstream>
#include <map>


double SV_BreakPoint::p_trim_threshold = 1;;
double SV_BreakPoint::p_merge_threshold = 0;
const int SV_BreakPoint::DELETION;
const int SV_BreakPoint::DUPLICATION;
const int SV_BreakPoint::INVERSION;
const int SV_BreakPoint::TRANSLOCATION;


//{{{ SV_BreakPoint:: SV_BreakPoint(SV_Evidence *e)
SV_BreakPoint::
SV_BreakPoint(SV_Evidence *e)
{
    evidence.push_back(e);

    ids[e->id] = 1;
}
//}}}

//{{{ SV_BreakPoint:: SV_BreakPoint(SV_BreakPoint *a, SV_BreakPoint *b)
SV_BreakPoint::
SV_BreakPoint(SV_BreakPoint *a, SV_BreakPoint *b)
{
    a->init_interval_probabilities();
    b->init_interval_probabilities();

    // a may not overlap b, so we need to check
    // after this ar_overlap_intr will point to the interval in a that
    // overlaps the right interval in b, and al_overlap_intr will point to the
    // interval in a that overlaps the left interval in b
    struct breakpoint_interval *al_overlap_intr = NULL,
                                        *ar_overlap_intr = NULL;

    if ( does_intersect(&(a->interval_l), &(b->interval_l), false) &&
            does_intersect(&(a->interval_r), &(b->interval_r), false) ) {
        al_overlap_intr = &(a->interval_l);
        ar_overlap_intr = &(a->interval_r);
    } else if ( does_intersect(&(a->interval_r), &(b->interval_l), false) &&
                does_intersect(&(a->interval_l), &(b->interval_r), false) ) {
        ar_overlap_intr = &(a->interval_l);
        al_overlap_intr = &(a->interval_r);
    } else {
        throw 0;
    }

    if ( (al_overlap_intr != NULL) && (ar_overlap_intr != NULL) ) {
        CHR_POS r_merged_start,
                r_merged_end,
                l_merged_start,
                l_merged_end;

        log_space *r_merged_prob, *l_merged_prob;

        bool l_merges = test_interval_merge(&(b->interval_l),
                                            al_overlap_intr,
                                            &l_merged_start,
                                            &l_merged_end,
                                            &l_merged_prob);


        bool r_merges = test_interval_merge(&(b->interval_r),
                                            ar_overlap_intr,
                                            &r_merged_start,
                                            &r_merged_end,
                                            &r_merged_prob);

        weight = 0;

        if (r_merges && l_merges) {

            interval_l.i.start = l_merged_start;
            interval_l.i.end = l_merged_end;
            interval_l.p = l_merged_prob;

            interval_r.i.start = r_merged_start;
            interval_r.i.end = r_merged_end;
            interval_r.p = r_merged_prob;

            vector<SV_Evidence*>::iterator ev_it;

            for (ev_it = a->evidence.begin(); ev_it < a->evidence.end(); ++ev_it)
                evidence.push_back(*ev_it);

            for (ev_it = b->evidence.begin(); ev_it < b->evidence.end(); ++ev_it)
                evidence.push_back(*ev_it);

            map<int, int>::iterator id_it;

            for (id_it = a->ids.begin(); id_it != a->ids.end(); ++id_it) {
                if ( ids.find( id_it->first ) == ids.end() )
                    ids[id_it->first] = 0;
                ids[id_it->first] += id_it->second;
            }

            for (id_it = b->ids.begin(); id_it != b->ids.end(); ++id_it) {
                if ( ids.find( id_it->first ) == ids.end() )
                    ids[id_it->first] = 0;
                ids[id_it->first] += id_it->second;
            }
{'fraction_non_alphanumeric': 0.15078070379864833, 'fraction_numerical': 0.003146119785597763, 'mean_word_length': 2.087410071942446, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 91, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7560285', 'n_tokens_mistral': 2704, 'n_tokens_neox': 2533, 'n_words': 541}