1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : PRD_Pair.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Wolfram Foerster in February 2001 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // =============================================================== // |
---|
11 | |
---|
12 | #include "PRD_Pair.hxx" |
---|
13 | #include <arb_mem.h> |
---|
14 | #include <cstdlib> |
---|
15 | |
---|
16 | using namespace std; |
---|
17 | |
---|
18 | // |
---|
19 | // Constructors |
---|
20 | // |
---|
21 | Pair::Pair (Item *one_, Item *two_, double rating_) { |
---|
22 | one = one_; |
---|
23 | two = two_; |
---|
24 | rating = rating_; |
---|
25 | } |
---|
26 | |
---|
27 | Pair::Pair () { |
---|
28 | one = NULp; |
---|
29 | two = NULp; |
---|
30 | rating = -1.0; |
---|
31 | } |
---|
32 | |
---|
33 | const char *Pair::get_primers (const char *sequence_) { |
---|
34 | if (!one || !two) return NULp; |
---|
35 | |
---|
36 | static char *result = NULp; |
---|
37 | static int result_len = 0; |
---|
38 | |
---|
39 | int max_result = (one ? one->length : 6) + (two ? two->length : 6) + 2; |
---|
40 | if (max_result > result_len) { |
---|
41 | free(result); |
---|
42 | result = NULp; |
---|
43 | } |
---|
44 | |
---|
45 | if (!result) { |
---|
46 | ARB_alloc(result, max_result+1); |
---|
47 | result_len = max_result; |
---|
48 | } |
---|
49 | |
---|
50 | char *pone = one->getPrimerSequence(sequence_); |
---|
51 | char *ptwo = two->getPrimerSequence(sequence_); |
---|
52 | |
---|
53 | sprintf(result, "%s\n%s", pone, ptwo); |
---|
54 | |
---|
55 | free(ptwo); |
---|
56 | free(pone); |
---|
57 | |
---|
58 | return result; |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | const char * Pair::get_result (const char *sequence_, int max_primer_length, int max_position_length, int max_length_length) { |
---|
63 | static char *result = NULp; |
---|
64 | static int result_len = 0; |
---|
65 | char *primer; |
---|
66 | |
---|
67 | int max_result = (one ? one->length : 6) + (two ? two->length : 6) + 200; |
---|
68 | if (max_result>result_len) { |
---|
69 | free(result); |
---|
70 | result = NULp; |
---|
71 | } |
---|
72 | |
---|
73 | if (!result) { |
---|
74 | ARB_alloc(result, max_result+1); |
---|
75 | result_len = max_result; |
---|
76 | } |
---|
77 | |
---|
78 | char *r = result; |
---|
79 | |
---|
80 | r += sprintf(r, "%7.3f ", rating); |
---|
81 | |
---|
82 | if (one) { |
---|
83 | primer = one->getPrimerSequence(sequence_); |
---|
84 | r += one->sprint(r, primer, " ", max_primer_length, max_position_length, max_length_length); |
---|
85 | free(primer); |
---|
86 | } |
---|
87 | else { |
---|
88 | r += sprintf(r, "(error),"); |
---|
89 | } |
---|
90 | |
---|
91 | if (two) { |
---|
92 | primer = two->getPrimerSequence(sequence_); |
---|
93 | r += two->sprint(r, primer, "", max_primer_length, max_position_length, max_length_length); |
---|
94 | free(primer); |
---|
95 | } |
---|
96 | else { |
---|
97 | r += sprintf(r, "(error)"); |
---|
98 | } |
---|
99 | |
---|
100 | return result; |
---|
101 | } |
---|
102 | |
---|
103 | |
---|
104 | // |
---|
105 | // print pair with the values of the items |
---|
106 | // |
---|
107 | void Pair::print (const char *prefix_, const char *suffix_, const char *sequence_) { |
---|
108 | const char *result = get_result(sequence_, 0, 0, 0); |
---|
109 | printf("%s[%s]%s", prefix_, result, suffix_); |
---|
110 | } |
---|