forked from BenLangmead/bowtie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebwt.cpp
78 lines (69 loc) · 1.9 KB
/
ebwt.cpp
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
/*
* ebwt.cpp
*
* Created on: Sep 23, 2009
* Author: Ben Langmead
*/
#include <string>
#include <stdexcept>
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;
#ifdef BOWTIE_64BIT_INDEX
std::string gEbwt_ext("ebwtl");
#else
std::string gEbwt_ext("ebwt");
#endif // BOWTIE_64BIT_INDEX
string gLastIOErrMsg;
/**
* Try to find the Bowtie index specified by the user. First try the
* exact path given by the user. Then try the user-provided string
* appended onto the path of the "indexes" subdirectory below this
* executable, then try the provided string appended onto
* "$BOWTIE_INDEXES/".
*/
string adjustEbwtBase(const string& cmdline,
const string& ebwtFileBase,
bool verbose = false)
{
string str = ebwtFileBase;
ifstream in;
if(verbose) cout << "Trying " << str << endl;
in.open((str + ".1." + gEbwt_ext).c_str(), ios_base::in | ios::binary);
if(!in.is_open()) {
if(verbose) cout << " didn't work" << endl;
in.close();
str = cmdline;
size_t st = str.find_last_of("/\\");
if(st != string::npos) {
str.erase(st);
str += "/indexes/";
} else {
str = "indexes/";
}
str += ebwtFileBase;
if(verbose) cout << "Trying " << str << endl;
in.open((str + ".1." + gEbwt_ext).c_str(), ios_base::in | ios::binary);
if(!in.is_open()) {
if(verbose) cout << " didn't work" << endl;
in.close();
if(getenv("BOWTIE_INDEXES") != NULL) {
str = string(getenv("BOWTIE_INDEXES")) + "/" + ebwtFileBase;
if(verbose) cout << "Trying " << str << endl;
in.open((str + ".1.ebwt").c_str(), ios_base::in | ios::binary);
if(!in.is_open()) {
if(verbose) cout << " didn't work" << endl;
in.close();
} else {
if(verbose) cout << " worked" << endl;
}
}
}
}
if(!in.is_open()) {
cerr << "Could not locate a Bowtie index corresponding to basename \"" << ebwtFileBase << "\"" << endl;
throw 1;
}
return str;
}