1 | #include "PRD_Item.hxx" |
---|
2 | #include "PRD_SequenceIterator.hxx" |
---|
3 | |
---|
4 | #include <arb_mem.h> |
---|
5 | |
---|
6 | #include <cstdlib> |
---|
7 | #include <cstring> |
---|
8 | |
---|
9 | using namespace std; |
---|
10 | |
---|
11 | // |
---|
12 | // Constructors |
---|
13 | // |
---|
14 | Item::Item(PRD_Sequence_Pos pos_, PRD_Sequence_Pos offset_, int length_, int ratio_, int temperature_, Item *next_) |
---|
15 | { |
---|
16 | end_pos = pos_; |
---|
17 | start_pos = -1; |
---|
18 | offset = offset_; |
---|
19 | length = length_; |
---|
20 | GC_ratio = ratio_; |
---|
21 | temperature = temperature_; |
---|
22 | next = next_; |
---|
23 | } |
---|
24 | Item::Item () |
---|
25 | { |
---|
26 | end_pos = -1; |
---|
27 | start_pos = -1; |
---|
28 | offset = -1; |
---|
29 | length = -1; |
---|
30 | GC_ratio = -1; |
---|
31 | temperature = -1; |
---|
32 | next = NULL; |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | // |
---|
37 | // print |
---|
38 | // |
---|
39 | void Item::print (const char *prefix_, const char *suffix_) |
---|
40 | { |
---|
41 | printf("%s[(%li,%li,%i),(%i,%i)]%s", prefix_, start_pos, offset, length, GC_ratio, temperature, suffix_); |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | // |
---|
46 | // sprint |
---|
47 | // |
---|
48 | int Item::sprint (char *buf, const char *primer, const char *suffix_, int max_primer_length, int max_position_length, int max_length_length) |
---|
49 | { |
---|
50 | return sprintf(buf, "| %-*s %*li %*i %3i %3i%s", |
---|
51 | max_primer_length, primer, |
---|
52 | max_position_length, start_pos+1, // +1 for biologists ;-) |
---|
53 | max_length_length, length, |
---|
54 | GC_ratio, temperature, suffix_); |
---|
55 | } |
---|
56 | |
---|
57 | inline char *PRD_strdup(const char *s) { |
---|
58 | size_t len = strlen(s); |
---|
59 | char *result = ARB_alloc<char>(len+1); |
---|
60 | strcpy(result, s); |
---|
61 | return result; |
---|
62 | } |
---|
63 | |
---|
64 | // |
---|
65 | // getPrimerSequence |
---|
66 | // |
---|
67 | // note : the sequence isn't stored in the Item, therefore must be given |
---|
68 | // |
---|
69 | char* Item::getPrimerSequence(const char *sequence_) |
---|
70 | { |
---|
71 | char *primer; |
---|
72 | if (length <= 0) return PRD_strdup("Item::getPrimerSequence : length <= 0 :("); |
---|
73 | |
---|
74 | ARB_alloc(primer, length+1); |
---|
75 | SequenceIterator *iterator = new SequenceIterator(sequence_, end_pos, SequenceIterator::IGNORE, length, SequenceIterator::BACKWARD); // init iterator |
---|
76 | |
---|
77 | for (int i = length-1; i >= 0; --i) // grab as many bases as length is |
---|
78 | primer[i] = iterator->nextBase(); |
---|
79 | primer[length] = '\x00'; // finish string |
---|
80 | |
---|
81 | start_pos = iterator->pos; |
---|
82 | |
---|
83 | delete iterator; // give up iterator |
---|
84 | |
---|
85 | return primer; |
---|
86 | } |
---|