~ubuntu-branches/debian/jessie/arb/jessie

« back to all changes in this revision

Viewing changes to SL/FILTER/AP_filter.cxx

  • Committer: Package Import Robot
  • Author(s): Elmar Pruesse, Andreas Tille, Elmar Pruesse
  • Date: 2014-09-02 15:15:06 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140902151506-jihq58b3iz342wif
Tags: 6.0.2-1
[ Andreas Tille ]
* New upstream version
  Closes: #741890
* debian/upstream -> debian/upstream/metadata
* debian/control:
   - Build-Depends: added libglib2.0-dev
   - Depends: added mafft, mrbayes
* debian/rules
   - Add explicite --remove-section=.comment option to manual strip call
* cme fix dpkg-control
* arb-common.dirs: Do not create unneeded lintian dir
* Add turkish debconf translation (thanks for the patch to Mert Dirik
  <mertdirik@gmail.com>)
  Closes: #757497

[ Elmar Pruesse ]
* patches removed:
   - 10_config.makefiles.patch,
     80_no_GL.patch
       removed in favor of creating file from config.makefile.template via 
       sed in debian/control
   - 20_Makefile_main.patch
       merged upstream
   - 21_Makefiles.patch
       no longer needed
   - 30_tmpfile_CVE-2008-5378.patch: 
       merged upstream
   - 50_fix_gcc-4.8.patch:
       merged upstream
   - 40_add_libGLU.patch:
       libGLU not needed for arb_ntree)
   - 60_use_debian_packaged_raxml.patch:
       merged upstream
   - 70_hardening.patch
       merged upstream
   - 72_add_math_lib_to_linker.patch
       does not appear to be needed
* patches added:
   - 10_upstream_r12793__show_db_load_progress:
       backported patch showing progress while ARB is loading a database
       (needed as indicator/splash screen while ARB is launching)
   - 20_upstream_r12794__socket_permissions:
       backported security fix
   - 30_upstream_r12814__desktop_keywords:
       backported add keywords to desktop (fixes lintian warning)
   - 40_upstream_r12815__lintian_spelling:
       backported fix for lintian reported spelling errors
   - 50_private_nameservers
       change configuration to put nameservers into users home dirs
       (avoids need for shared writeable directory)
   - 60_use_debian_phyml
       use phyml from debian package for both interfaces in ARB
* debian/rules:
   - create config.makefile from override_dh_configure target
   - use "make tarfile" in override_dh_install
   - remove extra cleaning not needed for ARB 6
   - use "dh_install --list-missing" to avoid missing files
   - added override_dh_fixperms target
* debian/control:
   - added libarb-dev package
   - Depends: added phyml, xdg-utils
   - Suggests: removed phyml
   - fix lintian duplicate-short-description (new descriptions)
* debian/*.install:
   - "unrolled" confusing globbing to select files
   - pick files from debian/tmp
   - moved all config files to /etc/arb
* debian/arb-common.templates: updated
* scripts:
   - removed arb-add-pt-server
   - launch-wrapper: 
     - only add demo.arb to newly created $ARBUSERDATA
     - pass commandline arguments through bin/arb wrapper
   - preinst: removing old PT server index files on upgrade from 5.5*
   - postinst: set setgid on shared PT dir
* rewrote arb.1 manfile
* added file icon for ARB databases
* using upstream arb_tcp.dat

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// =============================================================== //
 
2
//                                                                 //
 
3
//   File      : AP_filter.cxx                                     //
 
4
//   Purpose   :                                                   //
 
5
//                                                                 //
 
6
//   Institute of Microbiology (Technical University Munich)       //
 
7
//   http://www.arb-home.de/                                       //
 
8
//                                                                 //
 
9
// =============================================================== //
 
10
 
 
11
#include "AP_filter.hxx"
 
12
#include <arbdb.h>
 
13
 
 
14
 
 
15
// ------------------
 
16
//      AP_filter
 
17
 
 
18
void AP_filter::init(size_t size) {
 
19
    filter_mask        = new bool[size];
 
20
    filter_len         = size;
 
21
    update             = AP_timer();
 
22
    simplify_type      = AWT_FILTER_SIMPLIFY_NOT_INITIALIZED;
 
23
    simplify[0]        = 0; // silence cppcheck-warning
 
24
    bootstrap          = NULL;
 
25
    filterpos_2_seqpos = NULL;
 
26
#if defined(ASSERTION_USED)
 
27
    checked_for_validity = false;
 
28
#endif
 
29
}
 
30
 
 
31
 
 
32
AP_filter::AP_filter(size_t size) {
 
33
    make_permeable(size);
 
34
}
 
35
 
 
36
AP_filter::AP_filter(const AP_filter& other)
 
37
    : filter_mask(new bool[other.filter_len]),
 
38
      filter_len(other.filter_len),
 
39
      real_len(other.real_len),
 
40
      update(other.update),
 
41
      simplify_type(other.simplify_type),
 
42
      bootstrap(NULL),
 
43
      filterpos_2_seqpos(NULL)
 
44
{
 
45
    memcpy(filter_mask, other.filter_mask, filter_len*sizeof(*filter_mask));
 
46
    memcpy(simplify, other.simplify, sizeof(simplify)*sizeof(*simplify));
 
47
    if (other.bootstrap) {
 
48
        bootstrap = new size_t[real_len];
 
49
        memcpy(bootstrap, other.bootstrap, real_len*sizeof(*bootstrap));
 
50
    }
 
51
    if (other.filterpos_2_seqpos) {
 
52
        filterpos_2_seqpos = new size_t[real_len];
 
53
        memcpy(filterpos_2_seqpos, other.filterpos_2_seqpos, real_len*sizeof(*filterpos_2_seqpos));
 
54
    }
 
55
#if defined(ASSERTION_USED)
 
56
    checked_for_validity = other.checked_for_validity;
 
57
#endif
 
58
}
 
59
 
 
60
AP_filter::~AP_filter() {
 
61
    delete [] bootstrap;
 
62
    delete [] filter_mask;
 
63
    delete [] filterpos_2_seqpos;
 
64
}
 
65
 
 
66
AP_filter::AP_filter(const char *ifilter, const char *zerobases, size_t size) {
 
67
    if (!ifilter || !*ifilter) {
 
68
        make_permeable(size);
 
69
    }
 
70
    else {
 
71
        init(size);
 
72
 
 
73
        bool   char2mask[256];
 
74
        size_t i;
 
75
 
 
76
        for (i = 0; i<256; ++i) char2mask[i] = true;
 
77
        if (zerobases) {
 
78
            for (i = 0; zerobases[i]; ++i) char2mask[safeCharIndex(zerobases[i])] = false;
 
79
        }
 
80
        else {
 
81
            char2mask['0'] = false;
 
82
        }
 
83
 
 
84
        real_len = 0;
 
85
        for (i = 0; i < size && ifilter[i]; ++i) {
 
86
            real_len += int(filter_mask[i] = char2mask[safeCharIndex(ifilter[i])]);
 
87
        }
 
88
        for (; i < size; i++) {
 
89
            filter_mask[i] = true;
 
90
            real_len++;
 
91
        }
 
92
    }
 
93
}
 
94
 
 
95
void AP_filter::make_permeable(size_t size) {
 
96
    init(size);
 
97
    real_len = filter_len;
 
98
    for (size_t i = 0; i < size; i++) filter_mask[i] = true;
 
99
}
 
100
 
 
101
char *AP_filter::to_string() const {
 
102
    af_assert(checked_for_validity);
 
103
 
 
104
    char *data = (char*)malloc(filter_len+1);
 
105
 
 
106
    for (size_t i=0; i<filter_len; ++i) {
 
107
        data[i] = "01"[filter_mask[i]];
 
108
    }
 
109
    data[filter_len] = 0;
 
110
 
 
111
    return data;
 
112
}
 
113
 
 
114
 
 
115
void AP_filter::enable_simplify(AWT_FILTER_SIMPLIFY type) {
 
116
    if (type != simplify_type) {
 
117
        int i;
 
118
        for (i=0; i<32; i++) {
 
119
            simplify[i] = '.';
 
120
        }
 
121
        for (; i<256; i++) {
 
122
            simplify[i] = i;
 
123
        }
 
124
        switch (type) {
 
125
            case AWT_FILTER_SIMPLIFY_DNA:
 
126
                simplify[(unsigned char)'g'] = 'a';
 
127
                simplify[(unsigned char)'G'] = 'A';
 
128
                simplify[(unsigned char)'u'] = 'c';
 
129
                simplify[(unsigned char)'t'] = 'c';
 
130
                simplify[(unsigned char)'U'] = 'C';
 
131
                simplify[(unsigned char)'T'] = 'C';
 
132
                break;
 
133
            case AWT_FILTER_SIMPLIFY_PROTEIN:
 
134
                af_assert(0);                           // not implemented or impossible!?
 
135
                break;
 
136
            case AWT_FILTER_SIMPLIFY_NONE:
 
137
                break;
 
138
            default:
 
139
                af_assert(0);
 
140
                break;
 
141
        }
 
142
 
 
143
        simplify_type = type;
 
144
    }
 
145
}
 
146
 
 
147
void AP_filter::calc_filterpos_2_seqpos() {
 
148
    af_assert(checked_for_validity);
 
149
    af_assert(real_len>0);
 
150
 
 
151
    delete [] filterpos_2_seqpos;
 
152
    filterpos_2_seqpos = new size_t[real_len];
 
153
    size_t i, j;
 
154
    for (i=j=0; i<filter_len; ++i) {
 
155
        if (filter_mask[i]) {
 
156
            filterpos_2_seqpos[j++] = i;
 
157
        }
 
158
    }
 
159
}
 
160
 
 
161
void AP_filter::enable_bootstrap() {
 
162
    af_assert(checked_for_validity);
 
163
    af_assert(real_len>0);
 
164
 
 
165
    delete [] bootstrap;
 
166
    bootstrap = new size_t[real_len];
 
167
 
 
168
    af_assert(filter_len < RAND_MAX);
 
169
 
 
170
    for (size_t i = 0; i<real_len; ++i) {
 
171
        int r = GB_random(real_len);
 
172
        af_assert(r >= 0);     // otherwise overflow in random number generator
 
173
        bootstrap[i] = r;
 
174
    }
 
175
}
 
176
 
 
177
char *AP_filter::blowup_string(char *filtered_string, char fillChar) const {
 
178
    /*! blow up 'filtered_string' to unfiltered length
 
179
     * by inserting 'fillChar' at filtered positions
 
180
     */
 
181
    af_assert(checked_for_validity);
 
182
 
 
183
    char   *blownup = (char*)malloc(filter_len+1);
 
184
    size_t  f       = 0;
 
185
 
 
186
    for (size_t i = 0; i<filter_len; ++i) {
 
187
        blownup[i] = use_position(i) ? filtered_string[f++] : fillChar;
 
188
    }
 
189
 
 
190
    return blownup;
 
191
}
 
192
 
 
193
 
 
194
// -------------------
 
195
//      AP_weights
 
196
 
 
197
AP_weights::AP_weights(const AP_filter *fil)
 
198
    : len(fil->get_filtered_length())
 
199
    , weights(new GB_UINT4[len])
 
200
{
 
201
    for (size_t i = 0; i<len; ++i) weights[i] = 1;
 
202
}
 
203
 
 
204
AP_weights::AP_weights(const GB_UINT4 *w, size_t wlen, const AP_filter *fil)
 
205
    : len(fil->get_filtered_length())
 
206
    , weights(new GB_UINT4[len])
 
207
{
 
208
    af_assert(wlen == fil->get_length());
 
209
 
 
210
    size_t i, j;
 
211
    for (j=i=0; j<wlen; ++j) {
 
212
        if (fil->use_position(j)) {
 
213
            weights[i++] = w[j];
 
214
        }
 
215
    }
 
216
    af_assert(j <= fil->get_length());
 
217
    af_assert(i == fil->get_filtered_length());
 
218
}
 
219
 
 
220
AP_weights::AP_weights(const AP_weights& other)
 
221
    : len(other.len)
 
222
    , weights(new GB_UINT4[len])
 
223
{
 
224
    memcpy(weights, other.weights, len*sizeof(*weights));
 
225
}
 
226
 
 
227
AP_weights::~AP_weights() {
 
228
    delete [] weights;
 
229
}
 
230
 
 
231
long AP_timer() {
 
232
    static long time = 0;
 
233
    return ++time;
 
234
}
 
235
 
 
236