12 #ifndef PT_PARTITION_H
13 #define PT_PARTITION_H
15 #ifndef PT_PREFIXITER_H
18 #ifndef _GLIBCXX_CMATH
28 # define STAGE1_INDEX_BYTES_PER_PASS_OLIGO 3.7 // size of index (for each oligo inserted in one pass)
29 # define STAGE1_INDEX_BYTES_PER_BASE 0.1 // size of index (for each bp in database)
30 # define STAGE1_OTHER_BYTES_PER_PASS_OLIGO 1.0 // non-index data (for each oligo inserted in one pass)
31 # define STAGE1_OTHER_BYTES_PER_BASE 1.15 // non-index data (for each bp in database)
33 # define STAGE1_INDEX_EXTRA_MB 350 // additional constant memory used by index (+ a bit safety)
34 # define STAGE1_OTHER_EXTRA_MB 80 // additional constant memory used elsewhere (+ a bit safety)
38 # define STAGE1_INDEX_BYTES_PER_PASS_OLIGO 3.2 // size of index (for each oligo inserted in one pass)
39 # define STAGE1_INDEX_BYTES_PER_BASE 0 // size of index (for each bp in database)
40 # define STAGE1_OTHER_BYTES_PER_PASS_OLIGO 0.7 // non-index data (for each oligo inserted in one pass)
41 # define STAGE1_OTHER_BYTES_PER_BASE 1 // non-index data (for each bp in database)
43 # define STAGE1_INDEX_EXTRA_MB 150 // additional constant memory used by index (+ a bit safety)
44 # define STAGE1_OTHER_EXTRA_MB 50 // additional constant memory used elsewhere (+ a bit safety)
48 # define PTSERVER_BIN_MB 20 // binary mem footprint of ptserver (incl. libs, w/o DB) detected using pmap
50 #define STAGE1_BYTES_PER_PASS_OLIGO (STAGE1_INDEX_BYTES_PER_PASS_OLIGO + STAGE1_OTHER_BYTES_PER_PASS_OLIGO)
51 #define STAGE1_BYTES_PER_BASE (STAGE1_INDEX_BYTES_PER_BASE + STAGE1_OTHER_BYTES_PER_BASE)
52 #define STAGE1_EXTRA_MB (STAGE1_INDEX_EXTRA_MB + STAGE1_OTHER_EXTRA_MB)
77 for (
size_t i = 0; i<
length; ++i) {
93 prefixes = prefix.
steps();
95 left_prob =
new double[prefixes+1];
98 double prob[prefixes];
101 while (!prefix.
done()) {
104 left_prob[i+1] = left_prob[i]+prob[i];
110 : depth(other.depth),
111 prefixes(other.prefixes)
113 left_prob =
new double[prefixes+1];
114 memcpy(left_prob, other.left_prob,
sizeof(*left_prob)*(prefixes+1));
123 pt_assert(prefix_idx >= 0 && prefix_idx <= prefixes);
124 return left_prob[prefix_idx];
126 double of_range(
int first_idx,
int last_idx)
const {
128 pt_assert(first_idx >= 0 && last_idx<prefixes);
132 double of(
int prefix_idx) {
133 pt_assert(prefix_idx >= 0 && prefix_idx<prefixes);
134 return of_range(prefix_idx, prefix_idx);
141 if (prefixes == 0) best_idx = 0;
147 if (lol >= wanted) best_idx = low;
150 if (loh<wanted) best_idx = high;
152 while ((low+1)<high) {
155 int mid = (low+high)/2;
158 double left_of_mid =
left_of(mid);
159 if (left_of_mid<wanted) {
168 best_idx = fabs(lol-wanted) < fabs(loh-wanted) ? low : high;
183 void forgetChilds() {
206 probe_child->
setValue(probe+1, len-1, wanted);
215 if (decided)
return decision;
222 bool concordant = child[
PT_QU]->decided;
223 bool common_decision = concordant ? child[
PT_QU]->decision :
false;
228 if (child[i]->decided) {
229 if (child[i]->decision != common_decision) {
242 decision = common_decision;
255 void forget_decision_tree() {
264 marked(new bool[max_partitions]),
270 : depth(other.depth),
271 max_partitions(other.max_partitions),
272 marked(new bool[max_partitions]),
275 memcpy(marked, other.marked, max_partitions*
sizeof(*marked));
283 void mark(
int idx1,
int idx2) {
288 for (
int p = idx1; p <= idx2; ++p) {
293 for (
int p = 0; p<max_partitions; ++p) {
299 forget_decision_tree();
305 while (!iter.
done()) {
331 mutable size_t max_probes_in_any_pass;
333 int first_index_of_pass(
int pass)
const {
335 return start_of_pass[pass-1];
337 int last_index_of_pass(
int pass)
const {
339 return start_of_pass[pass]-1;
342 bool have_zero_prob_passes() {
343 for (
int p = 1; p <= passes; ++p) {
349 void calculate_pass_starts() {
351 delete [] start_of_pass;
352 start_of_pass =
new int[passes+1];
354 double prob_per_pass = 1.0/passes;
356 start_of_pass[0] = 0;
357 for (
int p = 1; p < passes; ++p) {
358 double pass_prob = p*prob_per_pass;
364 for (
int p = 0; p<passes; ++p) {
365 if (start_of_pass[p] >= start_of_pass[p+1]) {
366 int nidx = start_of_pass[p]+1;
368 start_of_pass[p+1] = nidx;
372 for (
int p = passes-1; p >= 0; --p) {
373 if (start_of_pass[p] >= start_of_pass[p+1]) {
374 start_of_pass[p] = start_of_pass[p+1]-1;
382 void markPrefixes() {
386 prefix.
mark(first_index_of_pass(current_pass), last_index_of_pass(current_pass));
390 bool legal_pass(
int pass)
const {
return pass >= 1 && pass <= passes; }
396 prefix(prob.get_depth()),
397 start_of_pass(new
int[passes+1]),
398 max_probes_in_any_pass(0)
401 calculate_pass_starts();
406 passes(other.passes),
407 current_pass(other.current_pass),
408 prefix(other.prefix),
409 start_of_pass(new
int[passes+1]),
410 max_probes_in_any_pass(other.max_probes_in_any_pass)
412 memcpy(start_of_pass, other.start_of_pass,
sizeof(*start_of_pass)*(passes+1));
417 delete [] start_of_pass;
421 return prob.
of_range(first_index_of_pass(pass), last_index_of_pass(pass));
428 bool done()
const {
return !legal_pass(current_pass); }
431 if (
done())
return false;
446 if (max_probes_in_any_pass == 0) {
447 for (
int p = 1; p <= passes; ++p) {
449 if (probes>max_probes_in_any_pass) max_probes_in_any_pass = probes;
453 return max_probes_in_any_pass;
472 #error PT_partition.h included twice
473 #endif // PT_PARTITION_H
void mark(int idx1, int idx2)
int find_index_near_leftsum(double wanted) const
static double base_probability(char base)
double pass_probability(int pass) const
#define STAGE1_BYTES_PER_BASE
CONSTEXPR_INLINE unsigned char safeCharIndex(char c)
PrefixProbabilities(const PrefixProbabilities &other)
size_t estimate_probes_for_pass(int pass, size_t overall_base_count) const
Partition(const PrefixProbabilities &prob_, int passes_)
void setValue(const char *probe, size_t len, bool wanted)
int number_of_passes() const
size_t estimate_max_kb_for_any_pass(size_t overall_base_count) const
double calc_probability(const char *prefix, size_t length)
bool isMarked(const char *probe) const
PrefixProbabilities(int depth_)
size_t max_probes_for_passes(const PrefixProbabilities &prob, int passes_wanted, size_t overall_base_count)
size_t estimate_max_probes_for_any_pass(size_t overall_base_count) const
#define STAGE1_BYTES_PER_PASS_OLIGO
DECLARE_ASSIGNMENT_OPERATOR(Partition)
double of(int prefix_idx)
DECLARE_ASSIGNMENT_OPERATOR(MarkedPrefixes)
DECLARE_ASSIGNMENT_OPERATOR(PrefixProbabilities)
MarkedPrefixes(const MarkedPrefixes &other)
MarkedPrefixes(int depth_)
CONSTEXPR_INLINE ULONG estimate_stage1_memusage_kb(ULONG all_bp, ULONG partition_bp)
double left_of(int prefix_idx) const
double of_range(int first_idx, int last_idx) const
Partition(const Partition &other)
bool getValue(const char *probe) const
const char * prefix() const
int get_prefix_count() const
bool contains(const char *probe) const
int max_allowed_passes() const
size_t max_kb_for_passes(const PrefixProbabilities &prob, int passes_wanted, size_t overall_base_count)
GB_ERROR mid(GBL_command_arguments *args, int start_index)