<commit_before>/*
Part of Scallop Transcript Assembler
(c) 2017 by  <NAME>, <NAME>, and Carnegie Mellon University.
See LICENSE for licensing.
*/

#include <cassert>
#include <cstdio>
#include <cmath>

#include "bundle_base.h"

bundle_base::bundle_base()
{
	tid = -1;
	chrm = "";
	lpos = INT32_MAX;
	rpos = 0;
	strand = '.';
	num_long_reads = 0;
}

bundle_base::~bundle_base()
{}

int bundle_base::add_hit(const hit &ht)
{
	if(ht.is_long_read == true) num_long_reads++;

	// store new hit
	hits.push_back(ht);

	// calcuate the boundaries on reference
	if(ht.pos < lpos) lpos = ht.pos;
	if(ht.rpos > rpos) rpos = ht.rpos;

	// set tid
	if(tid == -1) tid = ht.tid;
	assert(tid == ht.tid);

	// set strand
	if(hits.size() <= 1) strand = ht.strand;
	assert(strand == ht.strand);

	// DEBUG
	/*
	if(strand != ht.strand)
	{
		printf("strand = %c, ht.strand = %c, ht.xs = %c,\n", strand, ht.strand, ht.xs);
	}
	*/

	// add intervals
	vector<int64_t> vm;
	vector<int64_t> vi;
	vector<int64_t> vd;
	ht.get_mid_intervals(vm, vi, vd);

	//ht.print();
	for(int k = 0; k < vm.size(); k++)
	{
		int32_t s = high32(vm[k]);
		int32_t t = low32(vm[k]);
		//printf(" add interval %d-%d\n", s, t);
		mmap += make_pair(ROI(s, t), 1);
	}

	for(int k = 0; k < vi.size(); k++)
	{
		int32_t s = high32(vi[k]);
		int32_t t = low32(vi[k]);
		imap += make_pair(ROI(s, t), 1);
	}

	for(int k = 0; k < vd.size(); k++)
	{
		int32_t s = high32(vd[k]);
		int32_t t = low32(vd[k]);
		imap += make_pair(ROI(s, t), 1);
	}

	return 0;
}

bool bundle_base::overlap(const hit &ht) const
{
	if(mmap.find(ROI(ht.pos, ht.pos + 1)) != mmap.end()) return true;
	if(mmap.find(ROI(ht.rpos - 1, ht.rpos)) != mmap.end()) return true;
	return false;
}

int bundle_base::clear()
{
	tid = -1;
	chrm = "";
	lpos = INT32_MAX;
	rpos = 0;
	strand = '.';
	hits.clear();
	mmap.clear();
	imap.clear();
	num_long_reads = 0;
	return 0;
}
<commit_msg>replace INT32_MAX with 1 << 30<commit_after>/*
Part of Scallop Transcript Assembler
(c) 2017 by  <NAME>, <NAME>, and Carnegie Mellon University.
See LICENSE for licensing.
*/

#include <cassert>
#include <cstdio>
#include <cmath>
#include <climits>

#include "bundle_base.h"

bundle_base::bundle_base()
{
	tid = -1;
	chrm = "";
	lpos = 1 << 30;
	rpos = 0;
	strand = '.';
	num_long_reads = 0;
}

bundle_base::~bundle_base()
{}

int bundle_base::add_hit(const hit &ht)
{
	if(ht.is_long_read == true) num_long_reads++;

	// store new hit
	hits.push_back(ht);

	// calcuate the boundaries on reference
	if(ht.pos < lpos) lpos = ht.pos;
	if(ht.rpos > rpos) rpos = ht.rpos;

	// set tid
	if(tid == -1) tid = ht.tid;
	assert(tid == ht.tid);

	// set strand
	if(hits.size() <= 1) strand = ht.strand;
	assert(strand == ht.strand);

	// DEBUG
	/*
	if(strand != ht.strand)
	{
		printf("strand = %c, ht.strand = %c, ht.xs = %c,\n", strand, ht.strand, ht.xs);
	}
	*/

	// add intervals
	vector<int64_t> vm;
	vector<int64_t> vi;
	vector<int64_t> vd;
	ht.get_mid_intervals(vm, vi, vd);

	//ht.print();
	for(int k = 0; k < vm.size(); k++)
	{
		int32_t s = high32(vm[k]);
		int32_t t = low32(vm[k]);
		//printf(" add interval %d-%d\n", s, t);
		mmap += make_pair(ROI(s, t), 1);
	}

	for(int k = 0; k < vi.size(); k++)
	{
		int32_t s = high32(vi[k]);
		int32_t t = low32(vi[k]);
		imap += make_pair(ROI(s, t), 1);
	}

	for(int k = 0; k < vd.size(); k++)
	{
		int32_t s = high32(vd[k]);
		int32_t t = low32(vd[k]);
		imap += make_pair(ROI(s, t), 1);
	}

	return 0;
}

bool bundle_base::overlap(const hit &ht) const
{
	if(mmap.find(ROI(ht.pos, ht.pos + 1)) != mmap.end()) return true;
	if(mmap.find(ROI(ht.rpos - 1, ht.rpos)) != mmap.end()) return true;
	return false;
}

int bundle_base::clear()
{
	tid = -1;
	chrm = "";
	lpos = 1 << 30;
	rpos = 0;
	strand = '.';
	hits.clear();
	mmap.clear();
	imap.clear();
	num_long_reads = 0;
	return 0;
}

{'fraction_non_alphanumeric': 0.2041404612159329, 'fraction_numerical': 0.031184486373165617, 'mean_word_length': 3.3974654377880182, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 22, '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': '7105943', 'n_tokens_mistral': 1919, 'n_tokens_neox': 1755, 'n_words': 398}