@@ -94,6 +94,81 @@ struct Comp :
9494// Functions
9595// ============================================================================
9696
97+ // --------------------------------------------------------------------------
98+ // Function readIndexOption()
99+ // --------------------------------------------------------------------------
100+
101+ inline void
102+ readIndexOption (std::string & optionString,
103+ std::string const & optionIdentifier,
104+ LambdaOptions const & options)
105+ {
106+ std::ifstream f{(options.indexDir + " /option:" + optionIdentifier).c_str (),
107+ std::ios_base::in | std::ios_base::binary};
108+ if (f.is_open ())
109+ {
110+ auto fit = directionIterator (f, Input ());
111+ readLine (optionString, fit);
112+ f.close ();
113+ }
114+ else
115+ {
116+ throw std::runtime_error (" ERROR: Expected option specifier:\n " + options.indexDir + " /option:" +
117+ optionIdentifier + " \n Your index seems incompatible, try to recreate it "
118+ " and report a bug if the issue persists." );
119+ }
120+ }
121+
122+ // --------------------------------------------------------------------------
123+ // Function validateIndexOptions()
124+ // --------------------------------------------------------------------------
125+
126+ template <typename TRedAlph,
127+ BlastProgram p>
128+ inline int
129+ validateIndexOptions (LambdaOptions const & options)
130+ {
131+ std::string buffer;
132+ readIndexOption (buffer, " alph_translated" , options);
133+ if (buffer != _alphName (TransAlph<p>()))
134+ {
135+ std::cerr << " ERROR: Your index is of translated alphabet type: " << buffer << " \n But lambda expected: "
136+ << _alphName (TransAlph<p>()) << " \n Did you specify the right -p parameter?\n\n " ;
137+ return -1 ;
138+
139+ }
140+ buffer.clear ();
141+ readIndexOption (buffer, " alph_reduced" , options);
142+ if (buffer != _alphName (TRedAlph ()))
143+ {
144+ std::cerr << " ERROR: Your index is of reduced alphabet type: " << buffer << " \n But lambda expected: "
145+ << _alphName (TRedAlph ()) << " \n Did you specify the right -ar parameter?\n\n " ;
146+ return -1 ;
147+ }
148+ buffer.clear ();
149+ readIndexOption (buffer, " db_index_type" , options);
150+ unsigned long b = 0 ;
151+ if ((!lexicalCast (b, buffer)) || (b != static_cast <unsigned long >(options.dbIndexType )))
152+ {
153+ std::cerr << " ERROR: Your index type is: " << _indexName (static_cast <DbIndexType>(std::stoul (buffer)))
154+ << " \n But lambda expected: " << _indexName (options.dbIndexType )
155+ << " \n Did you specify the right -di parameter?\n\n " ;
156+ return -1 ;
157+ }
158+ if (qIsTranslated (p) && sIsTranslated (p))
159+ {
160+ buffer.clear ();
161+ readIndexOption (buffer, " genetic_code" , options);
162+ unsigned long b = 0 ;
163+ if ((!lexicalCast (b, buffer)) || (b != static_cast <unsigned long >(options.geneticCode )))
164+ {
165+ std::cerr << " WARNING: The codon translation table used during indexing and during search are different. "
166+ " This is not a problem per se, but is likely not what you want.\n\n " ;
167+ }
168+ }
169+ return 0 ;
170+ }
171+
97172// --------------------------------------------------------------------------
98173// Function prepareScoring()
99174// --------------------------------------------------------------------------
@@ -281,18 +356,6 @@ loadDbIndexFromDisk(TGlobalHolder & globalHolder,
281356 std::string path = toCString (options.indexDir );
282357 path += " /index" ;
283358
284- // Check if the index is of the old format (pre 0.9.0) by looking for different files
285- // if ((TGlobalHolder::blastProgram != BlastProgram::BLASTN) && // BLASTN indexes are compatible
286- // ((TGlobalHolder::alphReduction && fileExists(toCString(path + ".txt.concat"))) ||
287- // (!TGlobalHolder::alphReduction && TGlobalHolder::indexIsFM && !fileExists(toCString(path + ".lf.drv.wtc.24")))))
288- // {
289- // std::cerr << ((options.verbosity == 0) ? strIdent : std::string())
290- // << " failed.\n"
291- // << "It appears you tried to open an old index (created before 0.9.0) which "
292- // << "is not supported. Please remove the old files and create a new index with lambda_indexer!\n";
293- // return 200;
294- // }
295-
296359 int ret = open (globalHolder.dbIndex , path.c_str (), OPEN_RDONLY );
297360 if (ret != true )
298361 {
0 commit comments