File: ht2_init.cpp

package info (click to toggle)
hisat2 2.2.1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,448 kB
  • sloc: cpp: 97,109; python: 11,075; perl: 7,279; sh: 2,328; ansic: 1,458; makefile: 532; javascript: 273; java: 116
file content (215 lines) | stat: -rw-r--r-- 4,788 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
 * Copyright 2018, Chanhee Park <parkchanhee@gmail.com> and Daehwan Kim <infphilo@gmail.com>
 *
 * This file is part of HISAT 2.
 *
 * HISAT 2 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * HISAT 2 is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with HISAT 2.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <iostream>

#include "ds.h"
#include "repeat.h"
#include "rfm.h"

#include "ht2.h"
#include "ht2_handle.h"

using namespace std;


MemoryTally gMemTally;

static const struct ht2_options ht2_default_options = {
    .offRate = -1,

    .useMm = false,
    .useShmem = false,
    .mmSweep = false,
    .noRefNames = false,
    .noSplicedAlignment = false, 
    .gVerbose = false, 
    .startVerbose = false,
    .sanityCheck = 0,

    .useHaplotype = false,
};

static void free_handle(struct ht2_handle *hp)
{
    if(hp->altdb) {
        delete hp->altdb;
    }

    if(hp->raltdb) {
        delete hp->raltdb;
    }

    if(hp->repeatdb) {
        delete hp->repeatdb;
    }

    if(hp->gfm) {
        if(hp->gfm->isInMemory()) {
            hp->gfm->evictFromMemory();
        }
        delete hp->gfm;
    }

    if(hp->rgfm) {
        if(hp->rgfm->isInMemory()) {
            hp->rgfm->evictFromMemory();
        }
        delete hp->rgfm;
    }

    delete hp;
}


static void init_handle(struct ht2_handle *hp)
{

    struct ht2_options *opt = &hp->options;

    hp->altdb = new ALTDB<index_t>();
    hp->repeatdb = new RepeatDB<TIndexOffU>();
    hp->raltdb = new ALTDB<index_t>();

    hp->gfm = new HGFM<TIndexOffU, local_index_t>(
            hp->ht2_idx_name,
            hp->altdb,
            NULL,
            NULL,
            -1,
            true,
            opt->offRate,
            0,
            opt->useMm,
            opt->useShmem,
            opt->mmSweep,
            !opt->noRefNames,
            true,
            true,
            true,
            !opt->noSplicedAlignment,
            opt->gVerbose,
            opt->startVerbose,
            false,
            opt->sanityCheck,
            opt->useHaplotype);


    // Load the other half of the index into memory
    assert(!hp->gfm->isInMemory());

    hp->gfm->loadIntoMemory(
            -1,
            true,
            true,
            true,
            !opt->noRefNames,
            opt->startVerbose);

    hp->rgfm = new RFM<TIndexOffU>(
            hp->ht2_idx_name + ".rep",
            hp->raltdb,
            hp->repeatdb,
            NULL,
            -1,
            true,
            opt->offRate,
            0,
            opt->useMm,
            opt->useShmem,
            opt->mmSweep,
            !opt->noRefNames,
            true,
            true,
            true,
            !opt->noSplicedAlignment,
            opt->gVerbose,
            opt->startVerbose,
            false,
            opt->sanityCheck,
            false);


    assert(!hp->rgfm->isInMemory());
    hp->rgfm->loadIntoMemory(
            -1,
            true,
            true,
            true,
            !opt->noRefNames,
            opt->startVerbose);

    hp->repeatdb->construct(hp->gfm->rstarts(), hp->gfm->nFrag());
}

EXPORT
ht2_handle_t ht2_init(const char *name, ht2_option_t *options)
{
    struct ht2_handle *handle = new ht2_handle;

    handle->ht2_idx_name = name;
    if(options) {
        memcpy(&handle->options, options, sizeof(struct ht2_options));
    } else {
        memcpy(&handle->options, &ht2_default_options, sizeof(struct ht2_options));
    }

    // Init
    init_handle(handle);

    handle->tmp_str = name;

    return (ht2_handle_t)handle;
}

EXPORT
void ht2_close(ht2_handle_t handle)
{
    struct ht2_handle *hp = (struct ht2_handle *)handle;
    if(hp == NULL) {
        return;
    }

    free_handle(hp);
}


EXPORT
ht2_error_t ht2_init_options(ht2_option_t *options)
{
    if(options == NULL) {
        return HT2_ERR;
    }

    memcpy(options, &ht2_default_options, sizeof(ht2_default_options));

    return HT2_OK;
}

EXPORT
void ht2_test_1(ht2_handle_t handle)
{
    struct ht2_handle *hp = (struct ht2_handle *)handle;

    size_t refname_size = hp->gfm->_refnames.size();
    cerr << "ht2lib: " << "gfm refnames: " << refname_size << endl;
    for(size_t i = 0; i < refname_size; i++) {
        cerr << "ht2lib: " << " " << i << " -> " << hp->gfm->_refnames[i] << endl;
    }
}