Skip to content

Commit

Permalink
make regex static and initliaze once
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaura committed Jan 14, 2022
1 parent 5430735 commit b293731
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 3 additions & 1 deletion include/SingleCellProtocols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ namespace alevin{

// Custom geometry specification using regex for extraction
struct CustomGeo {
// store regex for reads 1 and 2
// store regex string for reads 1 and 2
static std::string reg[2];
// store positions of matches for bc and umi
static std::vector<int> b[2], u[2];
Expand All @@ -237,6 +237,8 @@ namespace alevin{
boost::smatch match[2];
// store the success of regex search
bool rgx_search[2];
// store the regex
static boost::regex rgx[2];
// required
static uint32_t barcodeLength, umiLength;
BarcodeEnd end;
Expand Down
8 changes: 4 additions & 4 deletions src/AlevinUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,8 @@ namespace alevin {
std::string& bc){
std::string barcode="";
for(int r=0; r < 2; r++) {
boost::regex rgx(pt.reg[r]);
pt.rgx_search[r] = (r == 0) ? boost::regex_search(read1,pt.match[r],rgx) :
boost::regex_search(read2,pt.match[r],rgx); // using std::string instead of read1/2 results in blank umi. strange!
pt.rgx_search[r] = (r == 0) ? boost::regex_search(read1,pt.match[r],pt.rgx[r]) :
boost::regex_search(read2,pt.match[r],pt.rgx[r]); // using std::string instead of read1/2 results in blank umi. strange!
if(!pt.b[r].empty()) { // if read r has barcode
if(pt.rgx_search[r]){ // if rgx search was successful
for(int i : pt.b[r]) {
Expand Down Expand Up @@ -1473,7 +1472,8 @@ namespace alevin {
}
// std::cout << "reg[0]: " << customGeo.reg[0] << std::endl;
// std::cout << "reg[1]: " << customGeo.reg[1] << std::endl;

customGeo.rgx[0] = customGeo.reg[0];
customGeo.rgx[1] = customGeo.reg[1];
// validate that BC and UMI lengths are OK
uint32_t maxBC{31};
uint32_t maxUMI{31};
Expand Down
2 changes: 1 addition & 1 deletion src/SingleCellProtocols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ namespace alevin{
extern uint32_t CustomGeo::barcodeLength, CustomGeo::umiLength;
// bool alevin::protocols::CustomGeo::bioReadFound;
extern bool CustomGeo::bioReadFound;

extern boost::regex CustomGeo::rgx[2];
}// protocols
}//alevin

0 comments on commit b293731

Please sign in to comment.