-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathlambda_indexer.cpp
More file actions
216 lines (185 loc) · 7.32 KB
/
Copy pathlambda_indexer.cpp
File metadata and controls
216 lines (185 loc) · 7.32 KB
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
// ==========================================================================
// lambda
// ==========================================================================
// Copyright (c) 2013-2017, Hannes Hauswedell <h2 @ fsfe.org>
// Copyright (c) 2016-2017, 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.
//
// ==========================================================================
// lambda.cpp: Main File for the main application
// ==========================================================================
#include <seqan/basic.h>
#include <seqan/arg_parse.h>
#include <seqan/seq_io.h>
#include <iostream>
#define LAMBDA_INDEXER 1 // some things are different for the indexer binary
#include "lambda_indexer.hpp"
using namespace seqan;
// ==========================================================================
// Forwards
// ==========================================================================
inline int
argConv0(LambdaIndexerOptions const & options);
template <BlastProgram p>
inline int
argConv1(LambdaIndexerOptions const & options,
BlastProgramSelector<p> const &);
template <BlastProgram p,
typename TRedAlph>
inline int
argConv2(LambdaIndexerOptions const & options,
BlastProgramSelector<p> const &,
TRedAlph const &);
template <BlastProgram p,
typename TRedAlph,
typename TIndexSpecSpec>
inline int
realMain(LambdaIndexerOptions const & options,
BlastProgramSelector<p> const &,
TRedAlph const &,
TIndexSpecSpec const &);
// ==========================================================================
// Functions
// ==========================================================================
// --------------------------------------------------------------------------
// Function main()
// --------------------------------------------------------------------------
// Program entry point.
int main(int argc, char const ** argv)
{
// Parse the command line.
seqan::ArgumentParser parser;
LambdaIndexerOptions options;
seqan::ArgumentParser::ParseResult res = parseCommandLine(options, argc, argv);
// If there was an error parsing or built-in argument parser functionality
// was triggered then we exit the program. The return code is 1 if there
// were errors and 0 if there were none.
if (res != seqan::ArgumentParser::PARSE_OK)
return res == seqan::ArgumentParser::PARSE_ERROR;
if (std::string(CMAKE_BUILD_TYPE) != "Release")
std::cerr << "WARNING: This binary is not built in release mode and will be much slower than it should be!\n";
return argConv0(options);
}
inline int
argConv0(LambdaIndexerOptions const & options)
{
switch(options.blastProgram)
{
case BlastProgram::BLASTN:
return argConv1(options, BlastProgramSelector<BlastProgram::BLASTN>());
case BlastProgram::BLASTP:
return argConv1(options, BlastProgramSelector<BlastProgram::BLASTP>());
case BlastProgram::BLASTX:
return argConv1(options, BlastProgramSelector<BlastProgram::BLASTX>());
case BlastProgram::TBLASTN:
return argConv1(options, BlastProgramSelector<BlastProgram::TBLASTN>());
case BlastProgram::TBLASTX:
return argConv1(options, BlastProgramSelector<BlastProgram::TBLASTX>());
default:
break;
}
return -1;
}
/// Alphabet reduction
template <BlastProgram p>
inline int
argConv1(LambdaIndexerOptions const & options,
BlastProgramSelector<p> const &)
{
using TUnred = typename std::conditional<p == BlastProgram::BLASTN, Dna5, AminoAcid>::type;
using Tp = BlastProgramSelector<p>;
switch (options.alphReduction)
{
case 0:
return argConv2(options, Tp(), TUnred());
case 2:
return argConv2(options, Tp(), ReducedAminoAcid<Murphy10>());
#if 0
case 10:
return argConv2(options, ReducedAminoAcid<ClusterReduction<10>>());
case 1:
return argConv2(options, AminoAcid10());
case 8:
return argConv2(options, ReducedAminoAcid<ClusterReduction<8>>());
case 12:
return argConv2(options, ReducedAminoAcid<ClusterReduction<12>>());
#endif
default:
return -1;
}
return -1;
}
template <BlastProgram p,
typename TRedAlph>
inline int
argConv2(LambdaIndexerOptions const & options,
BlastProgramSelector<p> const &,
TRedAlph const &)
{
if (options.algo == "radixsort")
return realMain(options, BlastProgramSelector<p>(), TRedAlph(), RadixSortSACreateTag());
else
return realMain(options, BlastProgramSelector<p>(), TRedAlph(), Nothing());
}
template <BlastProgram p,
typename TRedAlph,
typename TIndexSpecSpec>
inline int
realMain(LambdaIndexerOptions const & options,
BlastProgramSelector<p> const &,
TRedAlph const &,
TIndexSpecSpec const &)
{
using TOrigSet = TCDStringSet<String<OrigSubjAlph<p>>>;
using TTransSet = TCDStringSet<String<TransAlph<p>>>;
TTransSet translatedSeqs;
{
TOrigSet originalSeqs;
int ret = 0;
// ids get saved to disk again immediately and are not kept in memory
ret = loadSubjSeqsAndIds(originalSeqs, options);
if (ret)
return ret;
// preserve lengths of untranslated sequences
if (sIsTranslated(p))
_saveOriginalSeqLengths(originalSeqs.limits, options);
// convert the seg file to seqan binary format
ret = convertMaskingFile(length(originalSeqs), options);
if (ret)
return ret;
// translate or swap depending on program
translateOrSwap(translatedSeqs, originalSeqs, options);
}
// dump translated and unreduced sequences (except where they are included in index)
if ((options.alphReduction != 0) || (options.dbIndexType != 0))
dumpTranslatedSeqs(translatedSeqs, options);
// see if final sequence set actually fits into index
if (!checkIndexSize(translatedSeqs))
return -1;
if (options.dbIndexType == 1)
{
using TIndexSpec = TFMIndex<TIndexSpecSpec>;
generateIndexAndDump<TIndexSpec,TIndexSpecSpec>(translatedSeqs,
options,
BlastProgramSelector<p>(),
TRedAlph());
} else
{
using TIndexSpec = IndexSa<TIndexSpecSpec>;
generateIndexAndDump<TIndexSpec,TIndexSpecSpec>(translatedSeqs,
options,
BlastProgramSelector<p>(),
TRedAlph());
}
return 0;
}