File: gfm.cpp

package info (click to toggle)
hisat2 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,756 kB
  • sloc: cpp: 86,309; python: 12,230; sh: 2,171; perl: 936; makefile: 375
file content (72 lines) | stat: -rw-r--r-- 2,328 bytes parent folder | download | duplicates (2)
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
/*
 * Copyright 2015, Daehwan Kim <infphilo@gmail.com>
 *
 * This file is part of HISAT 2.
 *
 * HISAT 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.
 *
 * HISAT 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 HISAT 2.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <string>
#include "gfm.h"

using namespace std;

#ifdef BOWTIE_64BIT_INDEX

const std::string gfm_ext("ht2l");

#else

const std::string gfm_ext("ht2");

#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
 * "$HISAT2_INDEXES/".
 */
string adjustEbwtBase(const string& cmdline,
                      const string& gfmFileBase,
                      bool verbose)
{
    string str = gfmFileBase;
    ifstream in;
    if(verbose) cout << "Trying " << str.c_str() << endl;
    in.open((str + ".1." + gfm_ext).c_str(), ios_base::in | ios::binary);
    if(!in.is_open()) {
        if(verbose) cout << "  didn't work" << endl;
        in.close();
        if(getenv("HISAT2_INDEXES") != NULL) {
            str = string(getenv("HISAT2_INDEXES")) + "/" + gfmFileBase;
            if(verbose) cout << "Trying " << str.c_str() << endl;
            in.open((str + ".1." + gfm_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 HISAT2 index corresponding to basename \"" << gfmFileBase.c_str() << "\"" << endl;
        throw 1;
    }
    return str;
}