Skip to content

Commit 69933ac

Browse files
author
Rob Patro
committed
merge changes add Avi's citation
2 parents 20973e8 + d46150a commit 69933ac

74 files changed

Lines changed: 17016 additions & 4429 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 17 additions & 28 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()
@@ -175,20 +178,6 @@ ExternalProject_Add(libdivsufsort
175178
)
176179
set(SUFFARRAY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/external/install/include)
177180

178-
message("Build system will fetch and build SparseHash")
179-
message("==================================================================")
180-
ExternalProject_Add(libsparsehash
181-
DOWNLOAD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external
182-
DOWNLOAD_COMMAND curl -k -L https://github.com/COMBINE-lab/sparsehash/archive/sparsehash-2.0.2.tar.gz -o sparsehash-2.0.2.tar.gz &&
183-
tar -xzf sparsehash-2.0.2.tar.gz
184-
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/sparsehash-sparsehash-2.0.2
185-
BUILD_IN_SOURCE TRUE
186-
INSTALL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/external/install
187-
CONFIGURE_COMMAND sh -c "CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} ./configure --prefix=<INSTALL_DIR>"
188-
INSTALL_COMMAND make install
189-
)
190-
191-
192181
if (NOT CEREAL_ROOT)
193182
set(CEREAL_ROOT ${GAT_SOURCE_DIR}/external/install)
194183
endif()

License.md

Lines changed: 676 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ Since RapMap uses Jellyfish, it must be released under the GPL. However, this i
9292

9393
# Citation
9494

95-
Use this bibtex entry to cite RapMap
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.
9697

9798
```
9899
@article{Srivastava15062016,
@@ -109,5 +110,4 @@ journal = {Bioinformatics}
109110
}
110111
```
111112

112-
Other formats can be found here:
113-
http://bioinformatics.oxfordjournals.org/citmgr?gca=bioinfo%3B32%2F12%2Fi192
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
}

include/FastxParser.hpp

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#ifndef __FASTX_PARSER__
2+
#define __FASTX_PARSER__
3+
4+
#include "fcntl.h"
5+
#include "unistd.h"
6+
#include <atomic>
7+
#include <cstdio>
8+
#include <cstdlib>
9+
#include <iostream>
10+
#include <thread>
11+
#include <vector>
12+
13+
extern "C" {
14+
#include "kseq.h"
15+
}
16+
17+
#include "concurrentqueue.h"
18+
19+
#ifndef __FASTX_PARSER_PRECXX14_MAKE_UNIQUE__
20+
#define __FASTX_PARSER_PRECXX14_MAKE_UNIQUE__
21+
22+
#if __cplusplus >= 201402L
23+
#include <memory>
24+
using std::make_unique
25+
#else
26+
27+
#include <cstddef>
28+
#include <memory>
29+
#include <type_traits>
30+
#include <utility>
31+
32+
template <class T> struct _Unique_if {
33+
using _Single_object = std::unique_ptr<T>;
34+
};
35+
36+
template <class T> struct _Unique_if<T[]> {
37+
using _Unknown_bound = std::unique_ptr<T[]>;
38+
};
39+
40+
template <class T, size_t N> struct _Unique_if<T[N]> {
41+
using _Known_bound = void;
42+
};
43+
44+
template <class T, class... Args>
45+
typename _Unique_if<T>::_Single_object make_unique(Args&&... args) {
46+
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
47+
}
48+
49+
template <class T>
50+
typename _Unique_if<T>::_Unknown_bound make_unique(size_t n) {
51+
using U = typename std::remove_extent<T>::type;
52+
return std::unique_ptr<T>(new U[n]());
53+
}
54+
55+
template <class T, class... Args>
56+
typename _Unique_if<T>::_Known_bound make_unique(Args&&...) = delete;
57+
58+
#endif // C++11
59+
#endif //__FASTX_PARSER_PRECXX14_MAKE_UNIQUE__
60+
61+
namespace fastx_parser {
62+
struct ReadSeq {
63+
std::string seq;
64+
std::string name;
65+
~ReadSeq() {}
66+
};
67+
68+
struct ReadPair {
69+
ReadSeq first;
70+
ReadSeq second;
71+
};
72+
73+
template <typename T> class ReadChunk {
74+
public:
75+
ReadChunk(size_t want) : group_(want), want_(want), have_(want) {}
76+
inline void have(size_t num) { have_ = num; }
77+
inline size_t size() { return have_; }
78+
inline size_t want() const { return want_; }
79+
T& operator[](size_t i) { return group_[i]; }
80+
typename std::vector<T>::iterator begin() { return group_.begin(); }
81+
typename std::vector<T>::iterator end() { return group_.begin() + have_; }
82+
83+
private:
84+
std::vector<T> group_;
85+
size_t want_;
86+
size_t have_;
87+
};
88+
89+
template <typename T> class ReadGroup {
90+
public:
91+
ReadGroup(moodycamel::ProducerToken&& pt, moodycamel::ConsumerToken&& ct)
92+
: pt_(std::move(pt)), ct_(std::move(ct)) {}
93+
moodycamel::ConsumerToken& consumerToken() { return ct_; }
94+
moodycamel::ProducerToken& producerToken() { return pt_; }
95+
// get a reference to the chunk this ReadGroup owns
96+
std::unique_ptr<ReadChunk<T>>& chunkPtr() { return chunk_; }
97+
// get a *moveable* reference to the chunk this ReadGroup owns
98+
std::unique_ptr<ReadChunk<T>>&& takeChunkPtr() { return std::move(chunk_); }
99+
inline void have(size_t num) { chunk_->have(num); }
100+
inline size_t size() { return chunk_->size(); }
101+
inline size_t want() const { return chunk_->want(); }
102+
T& operator[](size_t i) { return (*chunk_)[i]; }
103+
typename std::vector<T>::iterator begin() { return chunk_->begin(); }
104+
typename std::vector<T>::iterator end() {
105+
return chunk_->begin() + chunk_->size();
106+
}
107+
void setChunkEmpty() { chunk_.release(); }
108+
bool empty() const { return chunk_.get() == nullptr; }
109+
110+
private:
111+
std::unique_ptr<ReadChunk<T>> chunk_{nullptr};
112+
moodycamel::ProducerToken pt_;
113+
moodycamel::ConsumerToken ct_;
114+
};
115+
116+
template <typename T> class FastxParser {
117+
public:
118+
FastxParser(std::vector<std::string> files, uint32_t numConsumers,
119+
uint32_t numParsers = 1, uint32_t chunkSize = 1000);
120+
121+
FastxParser(std::vector<std::string> files, std::vector<std::string> files2,
122+
uint32_t numConsumers, uint32_t numParsers = 1,
123+
uint32_t chunkSize = 1000);
124+
~FastxParser();
125+
bool start();
126+
ReadGroup<T> getReadGroup();
127+
bool refill(ReadGroup<T>& rg);
128+
void finishedWithGroup(ReadGroup<T>& s);
129+
130+
private:
131+
moodycamel::ProducerToken getProducerToken_();
132+
moodycamel::ConsumerToken getConsumerToken_();
133+
134+
std::vector<std::string> inputStreams_;
135+
std::vector<std::string> inputStreams2_;
136+
uint32_t numParsers_;
137+
std::atomic<uint32_t> numParsing_;
138+
std::vector<std::unique_ptr<std::thread>> parsingThreads_;
139+
size_t blockSize_;
140+
moodycamel::ConcurrentQueue<std::unique_ptr<ReadChunk<T>>> readQueue_,
141+
seqContainerQueue_;
142+
143+
// holds the indices of files (file-pairs) to be processed
144+
moodycamel::ConcurrentQueue<uint32_t> workQueue_;
145+
146+
std::vector<std::unique_ptr<moodycamel::ProducerToken>> produceReads_;
147+
std::vector<std::unique_ptr<moodycamel::ConsumerToken>> consumeContainers_;
148+
};
149+
}
150+
#endif // __FASTX_PARSER__

0 commit comments

Comments
 (0)