source: branches/alilink/PRIMER_DESIGN/PRD_Item.cxx

Last change on this file was 16768, checked in by westram, 7 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1#include "PRD_Item.hxx"
2#include "PRD_SequenceIterator.hxx"
3
4#include <arb_mem.h>
5
6#include <cstdlib>
7#include <cstring>
8
9using namespace std;
10
11//
12// Constructors
13//
14Item::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}
23Item::Item () {
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//
37void 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//
45int 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
53inline 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//
65char* 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}
Note: See TracBrowser for help on using the repository browser.