Skip to content

Commit cdb5c8a

Browse files
committed
Add back support for generic db
1 parent e34f40d commit cdb5c8a

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/util/createdb.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ int createdb(int argc, const char **argv, const Command& command) {
2828
}
2929

3030
bool dbInput = false;
31+
bool isSeqDb = false;
3132
if (FileUtil::fileExists(par.db1dbtype.c_str()) == true) {
3233
if (filenames.size() > 1) {
3334
Debug(Debug::ERROR) << "Only one database can be used with database input\n";
3435
EXIT(EXIT_FAILURE);
3536
}
3637
dbInput = true;
38+
// if par.hdr1 is not an empty string and the file exists
39+
if (par.hdr1 != "" && FileUtil::fileExists(par.hdr1.c_str()) == true ) {
40+
isSeqDb = true;
41+
}
3742
par.createdbMode = Parameters::SEQUENCE_SPLIT_MODE_HARD;
3843
}
3944

@@ -102,8 +107,10 @@ int createdb(int argc, const char **argv, const Command& command) {
102107
if (dbInput == true) {
103108
reader = new DBReader<unsigned int>(par.db1.c_str(), par.db1Index.c_str(), 1, DBReader<unsigned int>::USE_DATA | DBReader<unsigned int>::USE_INDEX | DBReader<unsigned int>::USE_LOOKUP);
104109
reader->open(DBReader<unsigned int>::LINEAR_ACCCESS);
105-
hdrReader = new DBReader<unsigned int>(par.hdr1.c_str(), par.hdr1Index.c_str(), 1, DBReader<unsigned int>::USE_DATA | DBReader<unsigned int>::USE_INDEX);
106-
hdrReader->open(DBReader<unsigned int>::LINEAR_ACCCESS);
110+
if (isSeqDb) {
111+
hdrReader = new DBReader<unsigned int>(par.hdr1.c_str(), par.hdr1Index.c_str(), 1, DBReader<unsigned int>::USE_DATA | DBReader<unsigned int>::USE_INDEX);
112+
hdrReader->open(DBReader<unsigned int>::LINEAR_ACCCESS);
113+
}
107114
fileCount = reader->getSize();
108115
}
109116

@@ -131,9 +138,13 @@ int createdb(int argc, const char **argv, const Command& command) {
131138
KSeqWrapper* kseq = NULL;
132139
std::string seq = ">";
133140
if (dbInput == true) {
134-
seq.append(hdrReader->getData(fileIdx, 0));
135-
seq.append(reader->getData(fileIdx, 0));
136-
kseq = new KSeqBuffer(seq.c_str(), seq.length());
141+
if (isSeqDb) {
142+
seq.append(reader->getData(fileIdx, 0));
143+
seq.append(hdrReader->getData(fileIdx, 0));
144+
kseq = new KSeqBuffer(seq.c_str(), seq.length());
145+
} else {
146+
kseq = new KSeqBuffer(reader->getData(fileIdx, 0), reader->getEntryLen(fileIdx) - 1);
147+
}
137148
} else {
138149
kseq = KSeqFactory(filenames[fileIdx].c_str());
139150
}
@@ -266,8 +277,10 @@ int createdb(int argc, const char **argv, const Command& command) {
266277
if (dbInput == true) {
267278
reader->close();
268279
delete reader;
269-
hdrReader->close();
270-
delete hdrReader;
280+
if (isSeqDb) {
281+
hdrReader->close();
282+
delete hdrReader;
283+
}
271284
}
272285

273286
if (entries_num == 0) {

0 commit comments

Comments
 (0)