12 #include <PT_server_prototypes.h>
25 inline void aisc_link(dll_public *dll, PT_probematch *match) {
aisc_link(reinterpret_cast<dllpublic_ext*>(dll), reinterpret_cast<dllheader_ext*>(match)); }
57 int *accepted_N_mismatches;
61 void init_accepted_N_mismatches(
int ignored_Nmismatches,
int when_less_than_Nmismatches);
66 max_ambig(probe_length),
67 accepted_N_mismatches(new
int[max_ambig+1]),
70 init_accepted_N_mismatches(pt_local.pm_nmatches_ignored, pt_local.pm_nmatches_limit);
73 delete [] accepted_N_mismatches;
79 bool reached = pt_local.pm_max_hits>0 && pt_local.ppm.cnt >= pt_local.pm_max_hits;
80 if (reached) pt_local.matches_truncated = 1;
86 return accepted_N_mismatches[ambig];
99 void MatchRequest::init_accepted_N_mismatches(
int ignored_Nmismatches,
int when_less_than_Nmismatches) {
107 when_less_than_Nmismatches =
std::min(when_less_than_Nmismatches, max_ambig+1);
108 ignored_Nmismatches =
std::min(ignored_Nmismatches, when_less_than_Nmismatches-1);
110 accepted_N_mismatches[0] = 0;
112 for (mm = 1; mm<when_less_than_Nmismatches; ++mm) {
113 accepted_N_mismatches[mm] = mm>ignored_Nmismatches ? mm-ignored_Nmismatches : 0;
116 for (; mm <= max_ambig; ++mm) {
117 accepted_N_mismatches[mm] = mm;
123 if (is_ambig || probe != seq) {
124 if (is_ambig) ambig++;
else plain++;
141 PT_probematch *ml = create_PT_probematch();
174 while (entry && !enough) {
192 while ((base = probe[height])) {
193 int ref = loc[height];
194 if (ref ==
PT_QU)
break;
206 while ((base = probe[height]));
217 if (probe[height] ==
PT_QU) {
226 enough =
add_hit(loc, mismatches);
234 while (entry && !enough) {
239 enough =
add_hit(dloc, entry_mismatches);
256 int son_height = height+1;
258 int base = probe[son_height];
267 if (!son_mismatches.
accepted())
break;
286 const PT_probematch *mach1 = (
const PT_probematch*)PT_probematch_ptr1;
287 const PT_probematch *mach2 = (
const PT_probematch*)PT_probematch_ptr2;
290 if (mach1->wmismatches > mach2->wmismatches)
return 1;
291 if (mach1->wmismatches < mach2->wmismatches)
return -1;
294 int cmp = mach1->mismatches - mach2->mismatches;
296 cmp = mach1->N_mismatches - mach2->N_mismatches;
298 if (mach1->wmismatches < mach2->wmismatches) cmp = -1;
299 else if (mach1->wmismatches > mach2->wmismatches) cmp = 1;
301 cmp = mach1->b_pos - mach2->b_pos;
303 cmp = mach1->name - mach2->name;
316 int list_len = locs->pm->get_count();
318 PT_probematch **my_list;
ARB_calloc(my_list, list_len);
320 PT_probematch *match = locs->pm;
321 for (
int i=0; match; i++) {
327 for (
int i=0; i<list_len; i++) {
343 return (
double)(((double)(pos * (seq_len - 1 - pos)) / (
double)((seq_len - 1) * (seq_len - 1)))* (double)(y2*4.0) + y1);
348 int slen = strlen(sequence);
351 for (p=0; p<slen; p++) {
367 freedup(locs->pm_sequence, probestring);
371 while (PT_probematch *ml = locs->pm) destroy_PT_probematch(ml);
372 locs->matches_truncated = 0;
374 #if defined(DEBUG) && 0
375 printf(
"Current bond values:\n");
376 for (
int y = 0;
y<4;
y++) {
377 for (
int x = 0; x<4; x++) {
378 printf(
"%5.2f", locs->bond[
y*4+x].val);
384 int probe_len = strlen(probestring);
391 int max_poss_mismatches = probe_len/2;
393 if (locs->pm_max > max_poss_mismatches) {
396 max_poss_mismatches == 1 ?
"" :
"es",
403 if (locs->pm_complement_first) {
408 freedup(locs->pm_sequence, probestring);
419 if (locs->pm_also_revcomp) {
430 splits_for_match_overlay[
locs] =
Splits(locs);
456 int len = strlen(str);
457 if (len>curr_max) curr_max = len;
462 PT_probematch *ml = locs->pm;
476 for (; ml; ml = ml->next) {
491 else if (len > width) {
494 memcpy(buf, text, width);
499 int spaces = width-len;
502 memset(sp, spacer, spaces);
522 int pr_len = strlen(ml->sequence);
523 PT_local *
locs = (PT_local *)ml->mh.parent->parent;
525 const int CONTEXT_SIZE = 9;
527 char *ref = ARB_calloc<char>(CONTEXT_SIZE+1+pr_len+1+CONTEXT_SIZE+1);
528 memset(ref,
'.', CONTEXT_SIZE+1);
531 const char *
seq = &*seqPtr;
533 const Splits& splits = splits_for_match_overlay[
locs];
535 for (
int pr_pos = CONTEXT_SIZE-1, al_pos = ml->rpos-1;
536 pr_pos >= 0 && al_pos >= 0;
539 if (!seq[al_pos])
break;
542 ref[CONTEXT_SIZE] =
'-';
546 bool display_right_context =
true;
548 char *pref = ref+CONTEXT_SIZE+1;
550 for (
int pr_pos = 0, al_pos = ml->rpos;
554 int ps = ml->sequence[pr_pos];
555 int ts = seq[al_pos];
563 double h = splits.
check(ml->sequence[pr_pos], ts);
564 if (h>=0.0) r = tolower(r);
571 display_right_context =
false;
572 for (; pr_pos < pr_len; pr_pos++) {
582 char *cref = ref+CONTEXT_SIZE+1+pr_len+1;
586 int al_pos = ml->rpos+pr_len;
588 if (display_right_context) {
590 pr_pos < CONTEXT_SIZE && al_pos < al_size;
597 if (al_pos < al_size) strcpy(cref,
"<more>");
602 freeset(result, ref);
640 freeset(result, memfile.
release());
666 if (ml->N_mismatches >= 0) {
678 freeset(result, memfile.
release());
682 return "There are no targets";
692 for (; ml; ml = ml->next) {
695 ml->g_pos = ml->b_pos;
696 ml->b_pos += gene_pos;
699 fprintf(stderr,
"Error in gene-pt-server: gene w/o position info\n");
722 memfile.
put(
char(1));
724 for (PT_probematch *ml = locs->pm; ml; ml = ml->next) {
726 memfile.
put(
char(1));
728 memfile.
put(
char(1));
753 for (PT_probematch *ml = locs->pm; ml; ml = ml->next) {
755 memfile.
put((
char)1);
756 memfile.
nprintf(30,
"%2i", ml->mismatches);
757 memfile.
put((
char)1);
758 memfile.
nprintf(30,
"%1.1f", ml->wmismatches);
759 memfile.
put((
char)1);
783 memfile.
put((
char)1);
813 #define TEST_WEIGHTED_MISMATCH(probe,seq,expected) TEST_EXPECT_SIMILAR(weights.get(probe,seq), expected, EPS)
815 void TEST_weighted_mismatches() {
817 PT_bond bonds[16] = {
818 { 0.0 }, { 0.0 }, { 0.5 }, { 1.1 },
819 { 0.0 }, { 0.0 }, { 1.5 }, { 0.0 },
820 { 0.5 }, { 1.5 }, { 0.4 }, { 0.9 },
821 { 1.1 }, { 0.0 }, { 0.9 }, { 0.0 },
828 TEST_WEIGHTED_MISMATCH(
PT_A,
PT_A, 0.0);
829 TEST_WEIGHTED_MISMATCH(
PT_A,
PT_C, 1.1);
830 TEST_WEIGHTED_MISMATCH(
PT_A,
PT_G, 0.2);
831 TEST_WEIGHTED_MISMATCH(
PT_A,
PT_T, 1.1);
833 TEST_WEIGHTED_MISMATCH(
PT_C,
PT_A, 1.0);
834 TEST_WEIGHTED_MISMATCH(
PT_C,
PT_C, 0.0);
835 TEST_WEIGHTED_MISMATCH(
PT_C,
PT_G, 1.1);
836 TEST_WEIGHTED_MISMATCH(
PT_C,
PT_T, 0.6);
838 TEST_WEIGHTED_MISMATCH(
PT_G,
PT_A, 1.5);
839 TEST_WEIGHTED_MISMATCH(
PT_G,
PT_C, 1.5);
840 TEST_WEIGHTED_MISMATCH(
PT_G,
PT_G, 0.0);
841 TEST_WEIGHTED_MISMATCH(
PT_G,
PT_T, 1.5);
843 TEST_WEIGHTED_MISMATCH(
PT_T,
PT_A, 1.1);
844 TEST_WEIGHTED_MISMATCH(
PT_T,
PT_C, 1.1);
845 TEST_WEIGHTED_MISMATCH(
PT_T,
PT_G, 0.6);
846 TEST_WEIGHTED_MISMATCH(
PT_T,
PT_T, 0.0);
849 TEST_WEIGHTED_MISMATCH(
PT_N,
PT_A, 0.9);
850 TEST_WEIGHTED_MISMATCH(
PT_N,
PT_C, 0.925);
851 TEST_WEIGHTED_MISMATCH(
PT_N,
PT_G, 0.475);
852 TEST_WEIGHTED_MISMATCH(
PT_N,
PT_T, 0.8);
854 TEST_WEIGHTED_MISMATCH(
PT_A,
PT_N, 0.6);
855 TEST_WEIGHTED_MISMATCH(
PT_C,
PT_N, 0.675);
856 TEST_WEIGHTED_MISMATCH(
PT_G,
PT_N, 1.125);
857 TEST_WEIGHTED_MISMATCH(
PT_T,
PT_N, 0.7);
859 TEST_WEIGHTED_MISMATCH(
PT_N,
PT_N, 0.775);
861 TEST_WEIGHTED_MISMATCH(
PT_QU,
PT_N, 0.775);
struct probe_input_data * data
const char * aisc_unlink(dllheader_ext *object)
MatchRequest(PT_local &locs, int probe_length)
AliDataPtr format(AliDataPtr data, const size_t wanted_len, GB_ERROR &error)
void complement_probe(char *Probe, int len)
bytestring * match_string(const PT_local *locs)
bool add_hits_for_children(POS_TREE2 *pt, const Mismatches &mismatch)
void GB_sort(void **array, size_t first, size_t behind_last, gb_compare_function compare, void *client_data)
void cat_spaced_left(GBS_strstruct &memfile, const char *text, int width)
char * ARB_strdup(const char *str)
static const char * get_match_info_formatted(PT_probematch *ml, const format_props &format)
const char * GBS_global_string(const char *templat,...)
static void pt_sort_match_list(PT_local *locs)
int MP_count_all_species(const PT_local *)
bool collect_hits_for(const char *probe, POS_TREE2 *pt, Mismatches &mismatch, int height)
int get_match_start(const PT_probematch *ml)
void cat(const char *from)
const char * get_match_acc(const PT_probematch *ml)
static format_props detect_format_props(const PT_local *locs, bool show_gpos)
const char * virt_name(const PT_probematch *ml)
void reverse_probe(char *seq, int len)
void enter_stage(Stage stage_)
int get_match_stop(const PT_probematch *ml)
static const char * get_match_hinfo_formatted(PT_probematch *ml, const format_props &format)
char * ARB_strduplen(const char *p, unsigned len)
void cat_dashed_left(GBS_strstruct &memfile, const char *text, int width)
static int pt_sort_compare_match(const void *PT_probematch_ptr1, const void *PT_probematch_ptr2, void *)
int probe_match(PT_local *locs, aisc_string probestring)
static int weights[MAX_BASETYPES][MAX_BASETYPES]
int compress_data(char *probestring)
PT_local & get_PT_local() const
long PT_abs_2_ecoli_rel(long pos)
bool add_hit(const DataLoc &at, const Mismatches &mismatch)
CONSTEXPR_INLINE bool is_std_base(char b)
ASSERTING_CONSTEXPR_INLINE int info2bio(int infopos)
static std::map< PT_local *, Splits > splits_for_match_overlay
void cat_internal(GBS_strstruct &memfile, int len, const char *text, int width, char spacer, bool align_left)
const char * virt_fullname(const PT_probematch *ml)
const AbsLoc & at() const
void cat_dashed_right(GBS_strstruct &memfile, const char *text, int width)
bytestring * MP_all_species_string(const PT_local *)
const char * get_match_overlay(const PT_probematch *ml)
double get_weighted() const
void count_weighted(char probe, char seq, int height)
PT * PT_read_son(PT *node, PT_base base)
void count_versus(const ReadableDataLoc &loc, const char *probe, int height)
void cat_spaced_right(GBS_strstruct &memfile, const char *text, int width)
CONSTEXPR_INLINE char base_2_readable(char base)
int accept_N_mismatches(int ambig) const
Mismatches(MatchRequest &req_)
PT_local & get_PT_local() const
TYPE * ARB_calloc(size_t nelem)
static void pt_build_pos_to_weight(PT_MATCH_TYPE type, const char *sequence)
void pt_export_error(PT_local *locs, const char *error)
void nprintf(size_t maxlen, const char *templat,...) __ATTR__FORMAT_MEMBER(2)
POS_TREE2 *& TREE_ROOT2()
char * probe_2_readable(char *id_string, int len)
double get(int probe, int seq) const
static void gene_rel_2_abs(PT_probematch *ml)
void aisc_link(dll_public *dll, PT_probematch *match)
double check(char base, char ref) const
const char * get_data() const
double get_mismatch_weight(char probe, char seq) const
bool hit_limit_reached() const
GB_transaction ta(gb_var)
int allowed_mismatches() const
char * create_reversed_probe(char *probe, int len)
CONSTEXPR_INLINE bool is_ambig_base(char b)
bytestring * MP_match_string(const PT_local *locs)
void set_max(const char *str, int &curr_max)
size_t get_position() const
CONSTEXPR_INLINE double calc_position_wmis(int pos, int seq_len, double y1, double y2)