forked from HIITMetagenomics/dsm-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextCollection.cpp
63 lines (51 loc) · 1.6 KB
/
TextCollection.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
#include "TextCollection.h"
#include "FMIndex.h"
//#include "rlcsa_wrapper.h"
#include <iostream>
#include <string>
#include <cstdio>
using std::string;
const string TextCollection::REVERSE_EXTENSION = ".reverse";
const string TextCollection::ROTATION_EXTENSION = ".rotation";
const string TextCollection::FMINDEX_EXTENSION = ".fmi";
const string TextCollection::RLCSA_EXTENSION = ".rlcsa.array";
bool fileexists(string const & filename)
{
FILE *fp = std::fopen(filename.c_str(),"r");
if(!fp)
return false;
std::fclose(fp);
return true;
}
TextCollection * TextCollection::load(string const & filename, string const & samplefile)
{
// Does filename determine index type to be FM-index?
std::size_t found = filename.rfind(FMINDEX_EXTENSION);
if(found != string::npos)
{
return new FMIndex(filename.substr(0, found), samplefile);
}
// Does filename determine index type to be RLCSA?
found = filename.rfind(RLCSA_EXTENSION);
if(found != string::npos)
{
std::cerr << "error: Currently unsupported" << std::endl;
std::abort();
//return new RLCSAWrapper(filename.substr(0, found));
}
// Does filename + RLCSA_EXTENSION exist?
/*if(fileexists(filename + RLCSA_EXTENSION))
{
if(fileexists(filename + FMINDEX_EXTENSION))
{
std::cerr << "Warning: both indexes exist, using " << filename + RLCSA_EXTENSION << " by default." << std::endl;
}
return new RLCSAWrapper(filename);
}*/
// Does filename + FMINDEX_EXTENSION exist?
if(fileexists(filename + FMINDEX_EXTENSION))
{
return new FMIndex(filename, samplefile);
}
return 0;
}