ARB
PRD_Item.cxx
Go to the documentation of this file.
1 #include "PRD_Item.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  end_pos = pos_;
16  start_pos = -1;
17  offset = offset_;
18  length = length_;
19  GC_ratio = ratio_;
20  temperature = temperature_;
21  next = next_;
22 }
24  end_pos = -1;
25  start_pos = -1;
26  offset = -1;
27  length = -1;
28  GC_ratio = -1;
29  temperature = -1;
30  next = NULp;
31 }
32 
33 
34 //
35 // print
36 //
37 void Item::print (const char *prefix_, const char *suffix_) {
38  printf("%s[(%li,%li,%i),(%i,%i)]%s", prefix_, start_pos, offset, length, GC_ratio, temperature, suffix_);
39 }
40 
41 
42 //
43 // sprint
44 //
45 int Item::sprint (char *buf, const char *primer, const char *suffix_, int max_primer_length, int max_position_length, int max_length_length) {
46  return sprintf(buf, "| %-*s %*li %*i %3i %3i%s",
47  max_primer_length, primer,
48  max_position_length, start_pos+1, // +1 for biologists ;-)
49  max_length_length, length,
50  GC_ratio, temperature, suffix_);
51 }
52 
53 inline char *PRD_strdup(const char *s) {
54  size_t len = strlen(s);
55  char *result = ARB_alloc<char>(len+1);
56  strcpy(result, s);
57  return result;
58 }
59 
60 //
61 // getPrimerSequence
62 //
63 // note : the sequence isn't stored in the Item, therefore must be given
64 //
65 char* Item::getPrimerSequence(const char *sequence_) {
66  char *primer;
67  if (length <= 0) return PRD_strdup("Item::getPrimerSequence : length <= 0 :(");
68 
69  ARB_alloc(primer, length+1);
70  SequenceIterator *iterator = new SequenceIterator(sequence_, end_pos, SequenceIterator::IGNORE, length, SequenceIterator::BACKWARD); // init iterator
71 
72  for (int i = length-1; i >= 0; --i) // grab as many bases as length is
73  primer[i] = iterator->nextBase();
74  primer[length] = '\x00'; // finish string
75 
76  start_pos = iterator->pos;
77 
78  delete iterator; // give up iterator
79 
80  return primer;
81 }
string result
void print(const char *prefix_, const char *suffix_)
Definition: PRD_Item.cxx:37
unsigned char nextBase()
STL namespace.
PRD_Sequence_Pos pos
Definition: PRD_Item.hxx:9
TYPE * ARB_alloc(size_t nelem)
Definition: arb_mem.h:56
char * getPrimerSequence(const char *sequence_)
Definition: PRD_Item.cxx:65
int sprint(char *buf, const char *prefix_, const char *suffix_, int max_primer_length, int max_position_length, int max_length_length)
Definition: PRD_Item.cxx:45
char * PRD_strdup(const char *s)
Definition: PRD_Item.cxx:53
static const int BACKWARD
#define NULp
Definition: cxxforward.h:116
Item()
Definition: PRD_Item.cxx:23
#define offset(field)
Definition: GLwDrawA.c:73
long int PRD_Sequence_Pos
Definition: PRD_Globals.hxx:21
size_t length
static const int IGNORE
GB_write_int const char s
Definition: AW_awar.cxx:154