Skip to content

Commit

Permalink
Minor cleanups.
Browse files Browse the repository at this point in the history
  • Loading branch information
OndrejSladky committed Mar 21, 2024
1 parent 23638a8 commit 4c095bb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 376 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ verify: $(PROG) $(SCRIPTS)/verify.py $(DATA)/spneumoniae.fa
quick-verify: $(PROG) $(SCRIPTS)/verify.py $(DATA)/spneumoniae.fa
python $(SCRIPTS)/verify.py $(DATA)/spneumoniae.fa --quick --interpath $(DATA)/spyogenes.fa

$(PROG): $(SRC)/main.cpp $(SRC)/$(wildcard *.cpp *.h *.hpp) src/version.h
$(PROG): $(SRC)/main.cpp $(SRC)/$(wildcard *.cpp *.h *.hpp) src/version.h $(wildcard $(UINT256)/*.cpp $(UINT256)/*.h $(UINT256)/*.include)
./create-version.sh
$(CXX) $(CXXFLAGS) $(SRC)/main.cpp $(UINT256)/uint256_t.cpp $(SRC)/kthread.c -o $@ $(LDFLAGS)

Expand Down
4 changes: 2 additions & 2 deletions src/kmers.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const char letters[4] {'A', 'C', 'G', 'T'};
/// Return the index-th nucleotide from the encoded k-mer.
template <typename kmer_t>
inline char NucleotideAtIndex(kmer_t encoded, int k, int index) {
return letters[(unsigned long)(encoded >> ((k - index - kmer_t(1)) << kmer_t(1))) & kmer_t(3)];
return letters[(uint32_t)(encoded >> ((k - index - kmer_t(1)) << kmer_t(1))) & kmer_t(3)];
}

/// Convert the encoded KMer representation to string.
Expand All @@ -123,7 +123,7 @@ std::string NumberToKMer(kmer_t encoded, int length) {
std::string ret(length, 'N');
for (int i = 0; i < length; ++i) {
// The last two bits correspond to one nucleotide.
ret[length - i -1] = letters[(unsigned long)encoded & 3];
ret[length - i -1] = letters[(uint32_t)(encoded & 3)];
// Move to the next letter.
encoded >>= 2;
}
Expand Down
4 changes: 2 additions & 2 deletions src/prophasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void NextSimplitig(KHT *kMers, kmer_t begin, std::ostream& of, int k, bool comp
} else {
// Extend the simplitig to the right.
eraseKMer(kMers, next, k, complements);
simplitig.emplace_back(letters[(unsigned int)ext]);
simplitig.emplace_back(letters[(uint32_t)ext]);
last = next;
}
} else {
Expand All @@ -71,7 +71,7 @@ void NextSimplitig(KHT *kMers, kmer_t begin, std::ostream& of, int k, bool comp
} else {
// Extend the simplitig to the left.
eraseKMer(kMers, next, k, complements);
simplitig.emplace_front(letters[(unsigned int)ext]);
simplitig.emplace_front(letters[(uint32_t)ext]);
first = next;
}
}
Expand Down
265 changes: 0 additions & 265 deletions src/uint256_t/uint256_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,9 @@ const uint256_t uint256_0(0);
const uint256_t uint256_1(1);
const uint256_t uint256_max(uint128_t(-1), uint128_t(-1));

/*
uint256_t::uint256_t(const std::string & s, uint8_t base) {
init_from_base(s.c_str(), base);
}
uint256_t::uint256_t(const char * s, uint8_t base) {
init_from_base(s, base);
}
*/

uint256_t::uint256_t(const bool & b)
: uint256_t((uint8_t) b)
{}
/*
void uint256_t::init_from_base(const char * s, uint8_t base) {
*this = 0;
uint256_t power(1);
uint8_t digit;
int pos = strlen(s) - 1;
while(pos >= 0) {
digit = 0;
if('0' <= s[pos] && s[pos] <= '9') {
digit = s[pos] - '0';
} else if('a' <= s[pos] && s[pos] <= 'z') {
digit = s[pos] - 'a' + 10;
}
*this += digit * power;
pos--;
power *= base;
}
}
*/

uint256_t & uint256_t::operator=(const bool & rhs) {
UPPER = 0;
Expand Down Expand Up @@ -321,133 +291,6 @@ uint256_t & uint256_t::operator-=(const uint256_t & rhs){
return *this;
}

/*
uint256_t uint256_t::operator*(const uint128_t & rhs) const{
return *this * uint256_t(rhs);
}
*/

/*
uint256_t uint256_t::operator*(const uint256_t & rhs) const{
// split values into 4 64-bit parts
uint128_t top[4] = {UPPER.upper(), UPPER.lower(), LOWER.upper(), LOWER.lower()};
uint128_t bottom[4] = {rhs.upper().upper(), rhs.upper().lower(), rhs.lower().upper(), rhs.lower().lower()};
uint128_t products[4][4];
// multiply each component of the values
for(int y = 3; y > -1; y--){
for(int x = 3; x > -1; x--){
products[3 - y][x] = top[x] * bottom[y];
}
}
// first row
uint128_t fourth64 = uint128_t(products[0][3].lower());
uint128_t third64 = uint128_t(products[0][2].lower()) + uint128_t(products[0][3].upper());
uint128_t second64 = uint128_t(products[0][1].lower()) + uint128_t(products[0][2].upper());
uint128_t first64 = uint128_t(products[0][0].lower()) + uint128_t(products[0][1].upper());
// second row
third64 += uint128_t(products[1][3].lower());
second64 += uint128_t(products[1][2].lower()) + uint128_t(products[1][3].upper());
first64 += uint128_t(products[1][1].lower()) + uint128_t(products[1][2].upper());
// third row
second64 += uint128_t(products[2][3].lower());
first64 += uint128_t(products[2][2].lower()) + uint128_t(products[2][3].upper());
// fourth row
first64 += uint128_t(products[3][3].lower());
// combines the values, taking care of carry over
return uint256_t(first64 << uint128_64, uint128_0) +
uint256_t(third64.upper(), third64 << uint128_64) +
uint256_t(second64, uint128_0) +
uint256_t(fourth64);
}
*/

/*
uint256_t & uint256_t::operator*=(const uint128_t & rhs){
return *this *= uint256_t(rhs);
}
uint256_t & uint256_t::operator*=(const uint256_t & rhs){
*this = *this * rhs;
return *this;
}
*/

/*
std::pair <uint256_t, uint256_t> uint256_t::divmod(const uint256_t & lhs, const uint256_t & rhs) const{
// Save some calculations /////////////////////
if (rhs == uint256_0){
throw std::domain_error("Error: division or modulus by 0");
}
else if (rhs == uint256_1){
return std::pair <uint256_t, uint256_t> (lhs, uint256_0);
}
else if (lhs == rhs){
return std::pair <uint256_t, uint256_t> (uint256_1, uint256_0);
}
else if ((lhs == uint256_0) || (lhs < rhs)){
return std::pair <uint256_t, uint256_t> (uint256_0, lhs);
}
std::pair <uint256_t, uint256_t> qr(uint256_0, lhs);
uint256_t copyd = rhs << (lhs.bits() - rhs.bits());
uint256_t adder = uint256_1 << (lhs.bits() - rhs.bits());
if (copyd > qr.second){
copyd >>= uint256_1;
adder >>= uint256_1;
}
while (qr.second >= rhs){
if (qr.second >= copyd){
qr.second -= copyd;
qr.first |= adder;
}
copyd >>= uint256_1;
adder >>= uint256_1;
}
return qr;
}
uint256_t uint256_t::operator/(const uint128_t & rhs) const{
return *this / uint256_t(rhs);
}
uint256_t uint256_t::operator/(const uint256_t & rhs) const{
return divmod(*this, rhs).first;
}
uint256_t & uint256_t::operator/=(const uint128_t & rhs){
return *this /= uint256_t(rhs);
}
uint256_t & uint256_t::operator/=(const uint256_t & rhs){
*this = *this / rhs;
return *this;
}
uint256_t uint256_t::operator%(const uint128_t & rhs) const{
return *this % uint256_t(rhs);
}
uint256_t uint256_t::operator%(const uint256_t & rhs) const{
return *this - (rhs * (*this / rhs));
}
uint256_t & uint256_t::operator%=(const uint128_t & rhs){
return *this %= uint256_t(rhs);
}
uint256_t & uint256_t::operator%=(const uint256_t & rhs){
*this = *this % rhs;
return *this;
}
*/

uint256_t & uint256_t::operator++(){
*this += uint256_1;
return *this;
Expand Down Expand Up @@ -486,70 +329,6 @@ const uint128_t & uint256_t::lower() const {
return LOWER;
}

/*
std::vector<uint8_t> uint256_t::export_bits() const {
std::vector<uint8_t> ret;
ret.reserve(32);
UPPER.export_bits(ret);
LOWER.export_bits(ret);
return ret;
}
std::vector<uint8_t> uint256_t::export_bits_truncate() const {
std::vector<uint8_t> ret = export_bits();
//prune the zeroes
int i = 0;
while (ret[i] == 0 && i < 64) i++;
ret.erase(ret.begin(), ret.begin() + i);
return ret;
}
uint16_t uint256_t::bits() const{
uint16_t out = 0;
if (UPPER){
out = 128;
uint128_t up = UPPER;
while (up){
up >>= uint128_1;
out++;
}
}
else{
uint128_t low = LOWER;
while (low){
low >>= uint128_1;
out++;
}
}
return out;
}
*/

/*
std::string uint256_t::str(uint8_t base, const unsigned int & len) const{
if ((base < 2) || (base > 36)){
throw std::invalid_argument("Base must be in the range 2-36");
}
std::string out = "";
if (!(*this)){
out = "0";
}
else{
std::pair <uint256_t, uint256_t> qr(*this, uint256_0);
do{
qr = divmod(qr.first, base);
out = "0123456789abcdefghijklmnopqrstuvwxyz"[(uint8_t) qr.second] + out;
} while (qr.first);
}
if (out.size() < len){
out = std::string(len - out.size(), '0') + out;
}
return out;
}
*/

uint256_t operator&(const uint128_t & lhs, const uint256_t & rhs){
return rhs & lhs;
}
Expand Down Expand Up @@ -710,47 +489,3 @@ uint128_t & operator-=(uint128_t & lhs, const uint256_t & rhs){
lhs = (-(rhs - lhs)).lower();
return lhs;
}

/*
uint256_t operator*(const uint128_t & lhs, const uint256_t & rhs){
return rhs * lhs;
}
uint128_t & operator*=(uint128_t & lhs, const uint256_t & rhs){
lhs = (rhs * lhs).lower();
return lhs;
}
uint256_t operator/(const uint128_t & lhs, const uint256_t & rhs){
return uint256_t(lhs) / rhs;
}
uint128_t & operator/=(uint128_t & lhs, const uint256_t & rhs){
lhs = (uint256_t(lhs) / rhs).lower();
return lhs;
}
uint256_t operator%(const uint128_t & lhs, const uint256_t & rhs){
return uint256_t(lhs) % rhs;
}
uint128_t & operator%=(uint128_t & lhs, const uint256_t & rhs){
lhs = (uint256_t(lhs) % rhs).lower();
return lhs;
}
*/

/*
std::ostream & operator<<(std::ostream & stream, const uint256_t & rhs){
if (stream.flags() & stream.oct){
stream << rhs.str(8);
}
else if (stream.flags() & stream.dec){
stream << rhs.str(10);
}
else if (stream.flags() & stream.hex){
stream << rhs.str(16);
}
return stream;
}
*/
Loading

0 comments on commit 4c095bb

Please sign in to comment.