-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathbt2_idx.cpp
86 lines (73 loc) · 2.32 KB
/
bt2_idx.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
79
80
81
82
83
84
85
86
/*
* Copyright 2011, Ben Langmead <[email protected]>
*
* This file is part of Bowtie 2.
*
* Bowtie 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.
*
* Bowtie 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 Bowtie 2. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <stdexcept>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include "bt2_idx.h"
using namespace std;
#ifdef HISAT_CLASS
const std::string gEbwt_ext("hc");
#else
# ifdef BOWTIE_64BIT_INDEX
const std::string gEbwt_ext("bt2l");
# else
const std::string gEbwt_ext("bt2");
# endif // BOWTIE_64BIT_INDEX
#endif
/**
* 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
* "$HISAT_INDEXES/".
*/
string adjustEbwtBase(const string& cmdline,
const string& ebwtFileBase,
bool verbose = false)
{
string str = ebwtFileBase;
ifstream in;
if(verbose) cout << "Trying " << str.c_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();
char const* val = getenv("HISAT_INDEXES");
if(val != NULL) {
string hisat_ndx_path = string(val);
str = hisat_ndx_path + "/" + ebwtFileBase;
if(verbose) cout << "Trying " << str.c_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();
} else {
if(verbose) cout << " worked" << endl;
}
}
}
if(!in.is_open()) {
cerr << "Could not locate a Bowtie index corresponding to basename \"" << ebwtFileBase.c_str() << "\"" << endl;
throw 1;
}
return str;
}
string gLastIOErrMsg;