Skip to content

Commit 5fbfa46

Browse files
authored
Merge pull request #33 from COMBINE-lab/refactor
Refactor
2 parents 222a785 + fafe54d commit 5fbfa46

14 files changed

Lines changed: 1379 additions & 769 deletions

CMakeLists.txt

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ enable_testing()
44

55
project (RapMap)
66

7-
set(CPACK_PACKAGE_VERSION "0.3.0")
7+
set(CPACK_PACKAGE_VERSION "0.4.0")
88
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
9-
set(CPACK_PACKAGE_VERSION_MINOR "3")
9+
set(CPACK_PACKAGE_VERSION_MINOR "4")
1010
set(CPACK_PACKAGE_VERSION_PATCH "0")
1111
set(PROJECT_VERSION ${CPACK_PACKAGE_VERSION})
1212
set(CPACK_GENERATOR "TGZ")
1313
set(CPACK_SOURCE_GENERATOR "TGZ")
1414
set(CPACK_PACKAGE_VENDOR "Stony Brook University")
15-
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "RapMap - Wicked-fast quasi/pseudo/lightweight alignment")
15+
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "RapMap - Wicked-fast qasi-mapping")
1616
set(CPACK_PACKAGE_NAME
1717
"${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
1818
set(CPACK_SOURCE_PACKAGE_FILE_NAME
@@ -26,8 +26,12 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
2626
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2 -DEMPHF_USE_POPCOUNT")
2727
#endif(SSE4_2_FOUND)
2828

29-
set (WARNING_IGNORE_FLAGS "-Wno-deprecated-register -Wno-c++11-narrowing -Wno-unknown-pragmas")
30-
set (BOOST_CXX_FLAGS "-Wno-deprecated-register -std=c++11")
29+
if (APPLE)
30+
set (WARNING_IGNORE_FLAGS "-Wno-deprecated-register -Wno-unknon-pragmas -Wreturn-type -Werror=return-type")
31+
else()
32+
set (WARNING_IGNORE_FLAGS "-Wno-unknown-pragmas -Wreturn-type -Werror=return-type")
33+
endif()
34+
3135
## Prefer static to dynamic libraries
3236
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
3337

@@ -38,7 +42,14 @@ else()
3842
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
3943
endif()
4044

41-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -funroll-loops -fPIC -fomit-frame-pointer -O4 -DHAVE_ANSI_TERM -Wall -std=c++11 -Wno-unknown-pragmas -Wreturn-type -Werror=return-type")
45+
46+
if (QUIET_BUILD)
47+
set(WALL "")
48+
else()
49+
set(WALL "-Wall")
50+
endif()
51+
52+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -funroll-loops -fPIC -fomit-frame-pointer -O4 -DHAVE_ANSI_TERM ${WALL} -std=c++11")
4253

4354
##
4455
# OSX is strange (some might say, stupid in this regard). Deal with it's quirkines here.
@@ -98,10 +109,6 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
98109
endif()
99110

100111
set (WARNING_IGNORE_FLAGS "${WARNING_IGNORE_FLAGS} -Wno-unused-local-typedefs")
101-
set (BOOST_TOOLSET "gcc")
102-
set (BOOST_CONFIGURE_TOOLSET "--with-toolset=gcc")
103-
set (BCXX_FLAGS "-std=c++11")
104-
set (BOOST_EXTRA_FLAGS toolset=gcc cxxflags=${BCXX_FLAGS})
105112
# Tentatively, we support clang now
106113
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
107114
set(CLANG TRUE)
@@ -111,10 +118,6 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
111118
if (HAVE_LIBCPP)
112119
message ("It appears that you're compiling with clang and that libc++ is available, so I'll use that")
113120
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
114-
set (BOOST_TOOLSET "clang")
115-
set (BOOST_CONFIGURE_TOOLSET "--with-toolset=clang")
116-
set (BCXX_FLAGS "-stdlib=libc++ -DBOOST_HAS_INT128")
117-
set (BOOST_EXTRA_FLAGS toolset=clang cxxflags=${BCXX_FLAGS} linkflags="-stdlib=libc++")
118121
set (JELLYFISH_CXX_FLAGS "-stdlib=libc++")
119122
# Otherwise, use libstdc++ (and make it static)
120123
else()

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,25 @@ RapMap is experimental, and the code, at this point, is subject to me testing ou
8989
# License
9090

9191
Since RapMap uses Jellyfish, it must be released under the GPL. However, this is currently the only GPL dependency. If it can be replaced, I'd like to re-license RapMap under the BSD license. I'd be happy to accept pull-requests that replace the Jellyfish components with a library released under a more liberal license (BSD-compatible), but note that I will *not* accept such pull requests if they reduce the speed or increase the memory consumption over the Jellyfish-based version.
92+
93+
# Citation
94+
95+
If you use RapMap, or wish to cite the quasi-mapping concept or our algorithm for computing quasi-mappings, please
96+
use this bibtex entry.
97+
98+
```
99+
@article{Srivastava15062016,
100+
author = {Srivastava, Avi and Sarkar, Hirak and Gupta, Nitish and Patro, Rob},
101+
title = {RapMap: a rapid, sensitive and accurate tool for mapping RNA-seq reads to transcriptomes},
102+
volume = {32},
103+
number = {12},
104+
pages = {i192-i200},
105+
year = {2016},
106+
doi = {10.1093/bioinformatics/btw277},
107+
URL = {http://bioinformatics.oxfordjournals.org/content/32/12/i192.abstract},
108+
eprint = {http://bioinformatics.oxfordjournals.org/content/32/12/i192.full.pdf+html},
109+
journal = {Bioinformatics}
110+
}
111+
```
112+
113+
Other citation formats for the RapMap paper are available [here](http://bioinformatics.oxfordjournals.org/citmgr?gca=bioinfo%3B32%2F12%2Fi192).

include/BooMap.hpp

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ class BooMap {
5252
data_.emplace_back(k, v);
5353
}
5454

55+
bool validate_hash(){
56+
for( auto& e : data_ ) {
57+
if (e.first != data_[boophf_->lookup(e.first)].first) {
58+
std::cerr << "lookup of " << e.first << " failed!\n";
59+
}
60+
}
61+
return true;
62+
}
63+
5564
bool build(int nthreads=1) {
5665
size_t numElem = data_.size();
5766
KeyIterator<decltype(data_.begin())> kb(data_.begin());
@@ -60,11 +69,8 @@ class BooMap {
6069
BooPHFT* ph = new BooPHFT(numElem, keyIt, nthreads);
6170
boophf_.reset(ph);
6271
std::cerr << "reordering keys and values to coincide with phf ... ";
63-
std::vector<size_t> inds; inds.reserve(data_.size());
64-
for (size_t i = 0; i < data_.size(); ++i) {
65-
inds.push_back(ph->lookup(data_[i].first));
66-
}
67-
reorder_destructive_(inds.begin(), inds.end(), data_.begin());
72+
reorder_fn_();
73+
//validate_hash();
6874
std::cerr << "done\n";
6975
built_ = true;
7076
return built_;
@@ -164,6 +170,50 @@ class BooMap {
164170
return true;
165171
}
166172

173+
174+
void reorder_fn_() {
175+
/* Adapted from code at: http://blog.merovius.de/2014/08/12/applying-permutation-in-constant.html */
176+
// Note, we can actually do this with out the bitvector by using the high-order bit
177+
// of the start of the suffix array intervals (since they are signed integers and negative
178+
// positions are forbidden).
179+
std::vector<bool> bits(data_.size(), false);
180+
for ( size_t i = 0; i < data_.size(); ++i ) {
181+
if (!bits[i]) {
182+
decltype(data_.front()) v = data_[i];
183+
auto j = boophf_->lookup(data_[i].first);
184+
while (i != j) {
185+
auto pj = boophf_->lookup(data_[j].first);
186+
std::swap(data_[j], v);
187+
bits[j] = 1;
188+
j = pj;
189+
}
190+
data_[i] = v;
191+
}
192+
}
193+
194+
/* http://blog.merovius.de/2014/08/12/applying-permutation-in-constant.html
195+
for i := 0; i < len(vals); i++ {
196+
if perm[i] < 0 {
197+
// already correct - unmark and go on
198+
// (note that ^a is the bitwise negation
199+
perm[i] = ^perm[i]
200+
continue
201+
}
202+
203+
v, j := vals[i], perm[i]
204+
for j != i {
205+
vals[j], v = v, vals[j]
206+
// When we find this element in the future, we must not swap it any
207+
// further, so we mark it here
208+
perm[j], j = ^perm[j], perm[j]
209+
}
210+
vals[i] = v
211+
}
212+
}
213+
*/
214+
}
215+
216+
167217
// From : http://stackoverflow.com/questions/838384/reorder-vector-using-a-vector-of-indices
168218
template< typename order_iterator, typename value_iterator >
169219
void reorder_destructive_( order_iterator order_begin, order_iterator order_end, value_iterator v ) {

include/BooPHF.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,11 @@ we need this 2-functors scheme because HashFunctors won't work with unordered_ma
533533
//for debug purposes
534534
void print() const
535535
{
536-
printf("bit array of size %lli: \n",_size);
536+
printf("bit array of size %lu: \n",_size);
537537
for(uint64_t ii = 0; ii< _size; ii++)
538538
{
539539
if(ii%10==0)
540-
printf(" (%llu) ",ii);
540+
printf(" (%lu) ",ii);
541541
int val = (_bitArray[ii >> 6] >> (ii & 63 ) ) & 1;
542542
printf("%i",val);
543543
}
@@ -546,7 +546,7 @@ we need this 2-functors scheme because HashFunctors won't work with unordered_ma
546546
printf("rank array : size %lu \n",_ranks.size());
547547
for (uint64_t ii = 0; ii< _ranks.size(); ii++)
548548
{
549-
printf("%llu : %lli, ",ii,_ranks[ii]);
549+
printf("%lu : %lu, ",ii,_ranks[ii]);
550550
}
551551
printf("\n");
552552
}

0 commit comments

Comments
 (0)