Skip to content

Commit

Permalink
fixes #6 allowing all technologies to have their barcode tag ending w…
Browse files Browse the repository at this point in the history
…ith -1
  • Loading branch information
clemaitre committed Mar 24, 2022
1 parent 328f565 commit f6cc571
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
7 changes: 4 additions & 3 deletions src/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ typedef vector<bool> barcode;
/**
Supported sequencing technologies
*/
enum SequencingTechnology {Undefined = 0, TenX, Haplotagging, TELLSeq, stLFR};
enum SequencingTechnology {Undefined = 0, TenXandTELLSeq, Haplotagging, stLFR};

extern SequencingTechnology techno;

Expand Down Expand Up @@ -55,13 +55,14 @@ string retrieveNucleotidesContent(const string& barcode);
Check whether a barcode is valid or not.
A barcode is considered as valid if it is not empty, if it does not contain any "N" for 10x and TELL-Seq,
if it is not "0_0_0" for stLFR data, and does not contain a "00" substring for Haplotagging data.
The function takes care of determining the employed sequencing technoly.
The function takes care of determining the employed sequencing technology.
It also removes the unwanted "-1" if it exsits at the end of the barcode.
@param barcode the barcode to verify
@throws runtime_error thrown if the sequencing technology could not be recognized
@return true if the barcode is valid, false otherwise
*/
bool isValidBarcode(const string& barcode);
bool isValidBarcode(string& barcode);

/**
Translate a string to a barcode in 2 bits per nucleotide format.
Expand Down
31 changes: 14 additions & 17 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ SequencingTechnology determineSequencingTechnology(const string& barcode) {
const char* HaplotaggingPattern = "^A[0-9][0-9]C[0-9][0-9]B[0-9][0-9]D[0-9][0-9]$";
regex_t stLFRReg;
const char* stLFRPattern = "^[0-9]+_[0-9]+_[0-9]+$";
regex_t TELLSeqReg;
const char* TELLSeqPattern = "^[ACGT]+$";
regex_t TenXandTELLSeqReg;
const char* TenXandTELLSeqPattern = "^[ACGT]+$";

int rc;
size_t nmatch = 1;
Expand All @@ -25,14 +25,12 @@ SequencingTechnology determineSequencingTechnology(const string& barcode) {
throw runtime_error("regcomp: An error occured with pattern " + string(stLFRPattern) + ".");
}

if (0 != (rc = regcomp(&TELLSeqReg, TELLSeqPattern, REG_EXTENDED))) {
throw runtime_error("regcomp: An error occured with pattern " + string(TELLSeqPattern) + ".");
if (0 != (rc = regcomp(&TenXandTELLSeqReg, TenXandTELLSeqPattern, REG_EXTENDED))) {
throw runtime_error("regcomp: An error occured with pattern " + string(TenXandTELLSeqPattern) + ".");
}

if (0 == (rc = regexec(&TELLSeqReg, barcode.c_str(), nmatch, pmatch, 0))) {
res = TELLSeq;
} else if (barcode.substr(barcode.length() - 2) == "-1") {
res = TenX;
if (0 == (rc = regexec(&TenXandTELLSeqReg, barcode.c_str(), nmatch, pmatch, 0))) {
res = TenXandTELLSeq;
} else if (0 == (rc = regexec(&HaplotaggingReg, barcode.c_str(), nmatch, pmatch, 0))) {
res = Haplotagging;
} else if (0 == (rc = regexec(&stLFRReg, barcode.c_str(), nmatch, pmatch, 0))) {
Expand All @@ -52,10 +50,7 @@ string retrieveNucleotidesContent(const string& barcode) {

string res;
switch (techno) {
case TenX:
res = barcode.substr(0, barcode.length() - 2);
break;
case TELLSeq:
case TenXandTELLSeq:
res = barcode;
break;
case Haplotagging:
Expand All @@ -74,21 +69,23 @@ string retrieveNucleotidesContent(const string& barcode) {
return res;
}

bool isValidBarcode(const string& barcode) {
bool isValidBarcode(string& barcode) {
if (barcode.empty()) {
return false;
}

// first remove "-1" at the end of the barcode if exists
if (barcode.substr(barcode.length() - 2) == "-1"){
barcode = barcode.substr(0, barcode.length() - 2);
}

if (techno == Undefined) {
techno = determineSequencingTechnology(barcode);
}

bool res;
switch (techno) {
case TenX:
res = (barcode.find("N") == string::npos);
break;
case TELLSeq:
case TenXandTELLSeq:
res = (barcode.find("N") == string::npos);
break;
case Haplotagging:
Expand Down

0 comments on commit f6cc571

Please sign in to comment.