Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
262 lines (228 loc) · 8.9 KB

File metadata and controls

262 lines (228 loc) · 8.9 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
// ==========================================================================
// lambda
// ==========================================================================
// Copyright (c) 2013-2024, Hannes Hauswedell <h2 @ fsfe.org>
// Copyright (c) 2016-2020, Knut Reinert and Freie Universität Berlin
// All rights reserved.
//
// This file is part of Lambda.
//
// Lambda is Free Software: you can redistribute it and/or modify it
// under the terms found in the LICENSE[.md|.rst] file distributed
// together with this file.
//
// Lambda 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.
//
// ==========================================================================
// mkindex.cpp: Main File for building the index
// ==========================================================================
#include <initializer_list>
#include <iostream>
#include <cereal/types/map.hpp>
#include <cereal/types/string.hpp>
#include <cereal/types/vector.hpp>
#include <bio/io/stream/transparent_ostream.hpp>
#include "shared_definitions.hpp"
#include "shared_misc.hpp"
#include "shared_options.hpp"
#include "mkindex_misc.hpp"
#include "mkindex_options.hpp"
// #include "mkindex_saca.hpp"
#include "mkindex_algo.hpp"
#include "view_reduce_to_bisulfite.hpp"
// ==========================================================================
// Forwards
// ==========================================================================
void argConv0(LambdaIndexerOptions & options);
template <DbIndexType c_indexType>
void argConv1(LambdaIndexerOptions & options);
template <DbIndexType c_indexType, AlphabetEnum c_origAlph>
void argConv2(LambdaIndexerOptions const & options);
template <DbIndexType c_indexType, AlphabetEnum c_origAlph, AlphabetEnum c_transAlph>
void argConv3a(LambdaIndexerOptions const & options);
template <DbIndexType c_indexType, AlphabetEnum c_origAlph, AlphabetEnum c_transAlph>
void argConv3b(LambdaIndexerOptions const & options);
template <DbIndexType c_indexType, AlphabetEnum c_origAlph, AlphabetEnum c_transAlph, AlphabetEnum c_redAlph>
void realMain(LambdaIndexerOptions const & options);
// --------------------------------------------------------------------------
// Function main()
// --------------------------------------------------------------------------
// Program entry point.
int mkindexMain(int const argc, char const ** argv)
{
LambdaIndexerOptions options;
#ifdef NDEBUG
try
{
parseCommandLine(options, argc, argv);
}
catch (sharg::parser_error const & ext) // catch user errors
{
std::cerr << "\n\nERROR: during command line parsing\n"
<< " \"" << ext.what() << "\"\n";
return -1;
}
#else
parseCommandLine(options, argc, argv);
#endif
#ifdef NDEBUG
try
{
argConv0(options);
}
catch (std::bad_alloc const & e)
{
std::cerr << "ERROR: Lambda ran out of memory :(\n"
" You need to split your file into smaller segments.\n";
return -1;
}
catch (std::exception const & e)
{
std::cerr << "\n\nERROR: The following unspecified exception was thrown:\n"
<< " \"" << e.what() << "\"\n"
<< " If the problem persists, report an issue at https://github.com/seqan/lambda/issues "
<< "and include this output, as well as the output of `lambda3 --version`, thanks!\n";
return -1;
}
#else
// In debug mode we don't catch the exceptions so that we get a backtrace from SeqAn's handler
argConv0(options);
#endif
return 0;
}
void argConv0(LambdaIndexerOptions & options)
{
switch (options.indexFileOptions.indexType)
{
case DbIndexType::FM_INDEX:
return argConv1<DbIndexType::FM_INDEX>(options);
case DbIndexType::BI_FM_INDEX:
#if LAMBDA_WITH_BIFM
return argConv1<DbIndexType::BI_FM_INDEX>(options);
#else
throw std::runtime_error{
"To create bidirectional indexes, you need to rebuild lambda with LAMBDA_WITH_BIFM=1 ."};
#endif
default:
throw 42;
}
}
template <DbIndexType c_indexType>
void argConv1(LambdaIndexerOptions & options)
{
if (options.indexFileOptions.origAlph == AlphabetEnum::UNDEFINED)
{
myPrint(options, 1, "Detecting database alphabet... ");
options.indexFileOptions.origAlph = detectSeqFileAlphabet(options.dbFile);
myPrint(options, 1, _alphabetEnumToName(options.indexFileOptions.origAlph), " detected.\n");
myPrint(options, 2, "\n");
}
switch (options.indexFileOptions.origAlph)
{
case AlphabetEnum::DNA5:
return argConv2<c_indexType, AlphabetEnum::DNA5>(options);
case AlphabetEnum::AMINO_ACID:
return argConv3a<c_indexType, AlphabetEnum::AMINO_ACID, AlphabetEnum::AMINO_ACID>(options);
default:
throw 43;
}
}
template <DbIndexType c_indexType, AlphabetEnum c_origAlph>
void argConv2(LambdaIndexerOptions const & options)
{
switch (options.indexFileOptions.transAlph)
{
case AlphabetEnum::DNA5:
return argConv3b<c_indexType, c_origAlph, AlphabetEnum::DNA5>(options);
case AlphabetEnum::AMINO_ACID:
return argConv3a<c_indexType, c_origAlph, AlphabetEnum::AMINO_ACID>(options);
default:
throw 44;
}
}
template <DbIndexType c_indexType, AlphabetEnum c_origAlph, AlphabetEnum c_transAlph>
void argConv3a(LambdaIndexerOptions const & options)
{
switch (options.indexFileOptions.redAlph)
{
case AlphabetEnum::AMINO_ACID:
return realMain<c_indexType, c_origAlph, c_transAlph, AlphabetEnum::AMINO_ACID>(options);
case AlphabetEnum::MURPHY10:
return realMain<c_indexType, c_origAlph, c_transAlph, AlphabetEnum::MURPHY10>(options);
case AlphabetEnum::LI10:
return realMain<c_indexType, c_origAlph, c_transAlph, AlphabetEnum::LI10>(options);
default:
throw 45;
}
}
template <DbIndexType c_indexType, AlphabetEnum c_origAlph, AlphabetEnum c_transAlph>
void argConv3b(LambdaIndexerOptions const & options)
{
switch (options.indexFileOptions.redAlph)
{
case AlphabetEnum::DNA5:
return realMain<c_indexType, c_origAlph, c_transAlph, AlphabetEnum::DNA5>(options);
case AlphabetEnum::DNA4:
return realMain<c_indexType, c_origAlph, c_transAlph, AlphabetEnum::DNA4>(options);
case AlphabetEnum::DNA3BS:
return realMain<c_indexType, c_origAlph, c_transAlph, AlphabetEnum::DNA3BS>(options);
default:
throw 364;
}
}
template <DbIndexType c_dbIndexType, AlphabetEnum c_origAlph, AlphabetEnum c_transAlph, AlphabetEnum c_redAlph>
void realMain(LambdaIndexerOptions const & options)
{
index_file<c_dbIndexType, c_origAlph, c_redAlph> f;
f.options = options.indexFileOptions;
{
TaccToIdRank accToIdRank;
// ids get saved to disk again immediately and are not kept in memory
std::tie(f.ids, f.seqs, accToIdRank) = loadSubjSeqsAndIds<_alphabetEnumToType<c_origAlph>>(options);
if (options.hasSTaxIds)
{
std::vector<bool> taxIdIsPresent;
// read taxonomic IDs
std::tie(f.sTaxIds, taxIdIsPresent) = mapTaxIDs(accToIdRank, std::ranges::size(f.seqs), options);
if (!options.taxDumpDir.empty())
{
// read and create taxonomic tree
std::tie(f.taxonParentIDs, f.taxonHeights, f.taxonNames) =
parseAndStoreTaxTree(taxIdIsPresent, options);
}
}
}
// see if final sequence set actually fits into index
// checkIndexSize(translatedSeqs, options, seqan::BlastProgramSelector<p>());
auto transSbjSeqs = f.seqs | sbjTransView<c_origAlph, c_transAlph, c_redAlph>;
auto redSbjSeqs = transSbjSeqs | redView<c_transAlph, c_redAlph>;
f.index = generateIndex<c_dbIndexType == DbIndexType::BI_FM_INDEX>(redSbjSeqs, options);
myPrint(options, 1, "Writing Index to disk...");
double s = sysTime();
{
std::string filename(options.indexFilePath);
bio::io::transparent_ostream os{
filename,
{.compression_level = 5, .threads = options.threads}
};
if (filename.ends_with(".lba") || filename.ends_with(".lba.gz"))
{
cereal::BinaryOutputArchive oarchive(os);
oarchive(cereal::make_nvp("lambda index", f));
}
else if (filename.ends_with(".lta") || filename.ends_with(".lta.gz"))
{
cereal::JSONOutputArchive oarchive(os);
oarchive(cereal::make_nvp("lambda index", f));
}
else
{
throw 59;
}
}
double e = sysTime() - s;
myPrint(options, 1, " done.\n");
myPrint(options, 2, "Runtime: ", e, "s \n");
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.