-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
252 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// Created by annika on 09.11.22. | ||
// | ||
#include "SequenceWeights.h" | ||
#include "Util.h" | ||
#include "Debug.h" | ||
|
||
#include <algorithm> | ||
#include <fstream> | ||
|
||
SequenceWeights::SequenceWeights(const char* dataFileName) { | ||
|
||
//parse file and fill weightIndex | ||
std::ifstream tsv(dataFileName); | ||
if (tsv.fail()) { | ||
Debug(Debug::ERROR) << "File " << dataFileName << " not found!\n"; | ||
EXIT(EXIT_FAILURE); | ||
} | ||
|
||
char keyData[255]; | ||
std::string line; | ||
this->indexSize = 0; | ||
unsigned int pos = 0; | ||
while(std::getline(tsv, line)) { | ||
this->indexSize++; | ||
} | ||
|
||
this->weightIndex = new WeightIndexEntry[this->indexSize]; | ||
|
||
tsv.clear(); | ||
tsv.seekg(0); | ||
|
||
while(std::getline(tsv, line)) { | ||
char *current = (char *) line.c_str(); | ||
Util::parseKey(current, keyData); | ||
const std::string key(keyData); | ||
unsigned int keyId = strtoull(key.c_str(), NULL, 10); | ||
|
||
char *restStart = current + key.length(); | ||
restStart = restStart + Util::skipWhitespace(restStart); | ||
float weight = static_cast<float>(strtod(restStart, NULL)); | ||
this->weightIndex[pos].id = keyId; | ||
this->weightIndex[pos].weight = weight; | ||
pos++; | ||
} | ||
} | ||
|
||
float SequenceWeights::getWeightById(unsigned int id) { | ||
|
||
WeightIndexEntry val; | ||
val.id = id; | ||
size_t pos = std::upper_bound(weightIndex, weightIndex + indexSize, val, WeightIndexEntry::compareByIdOnly) - weightIndex; | ||
return (pos < indexSize && weightIndex[pos].id == id ) ? weightIndex[pos].weight : std::numeric_limits<float>::min(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Created by annika on 09.11.22. | ||
// | ||
|
||
#ifndef MMSEQS_SEQUENCEWEIGHTS_H | ||
#define MMSEQS_SEQUENCEWEIGHTS_H | ||
|
||
class SequenceWeights{ | ||
public: | ||
struct WeightIndexEntry { | ||
unsigned int id; | ||
float weight; | ||
|
||
static bool compareByIdOnly(const WeightIndexEntry &x, const WeightIndexEntry &y) { | ||
return x.id <= y.id; | ||
} | ||
}; | ||
|
||
WeightIndexEntry *weightIndex; | ||
unsigned int indexSize; | ||
|
||
SequenceWeights(const char* dataFileName); | ||
|
||
~SequenceWeights(); | ||
|
||
float getWeightById(unsigned int id); | ||
}; | ||
|
||
|
||
#endif //MMSEQS_SEQUENCEWEIGHTS_H |
Oops, something went wrong.