Commit de5470ae authored by Haowen Zhang's avatar Haowen Zhang
Browse files

Add more space and brackets.

parent de54d9b2
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -714,13 +714,15 @@ void Chromap::OutputMappingStatistics() {
}

void Chromap::ParseReadFormat(const std::string &read_format) {
  uint32_t i, j;
  read1_effective_range_.Init();
  read2_effective_range_.Init();
  barcode_effective_range_.Init();

  uint32_t i, j;
  for (i = 0; i < read_format.size();) {
    for (j = i + 1; j < read_format.size() && j != ','; ++j)
      ;

    bool parse_success = true;
    if (read_format[i] == 'r' && read_format[i + 1] == '1') {
      parse_success = read1_effective_range_.ParseEffectiveRange(
@@ -734,8 +736,11 @@ void Chromap::ParseReadFormat(const std::string &read_format) {
    } else {
      parse_success = false;
    }
    if (!parse_success)

    if (!parse_success) {
      ExitWithMessage("Unknown read format: " + read_format + "\n");
    }

    i = j;
  }
}
+34 −13
Original line number Diff line number Diff line
@@ -10,8 +10,8 @@

namespace chromap {

// The class handles the custom read format indicating
// the effective range on a sequence.
// The class handles the custom read format indicating the effective range on a
// sequence.
class SequenceEffectiveRange {
 public:
  SequenceEffectiveRange() {}
@@ -24,7 +24,7 @@ class SequenceEffectiveRange {
    range_num = 1;
  }

  // Return: false - fail to parse
  // Return false if it fails to parse the format string.
  bool ParseEffectiveRange(const char *s, int len) {
    int i;
    int j = 0;  // start, end, strand section
@@ -33,15 +33,19 @@ class SequenceEffectiveRange {
    starts.clear();
    ends.clear();
    strand = 1;

    for (i = 3; i <= len; ++i) {
      if (i == len || s[i] == '/' || s[i] == ':') {
        buffer[blen] = '\0';
        if (j == 0)

        if (j == 0) {
          starts.push_back(atoi(buffer));
        else if (j == 1)
        } else if (j == 1) {
          ends.push_back(atoi(buffer));
        else
        } else {
          strand = buffer[0] == '+' ? 1 : -1;
        }

        blen = 0;
        if (i < len && s[i] == ':') ++j;
      } else {
@@ -49,27 +53,41 @@ class SequenceEffectiveRange {
        ++blen;
      }
    }
    if (j >= 3 || starts.size() != ends.size()) return false;

    if (j >= 3 || starts.size() != ends.size()) {
      return false;
    }

    std::sort(starts.begin(), starts.end());
    std::sort(ends.begin(), ends.end());

    range_num = starts.size();
    if (ends[0] == -1) {
      for (i = 0; i < range_num - 1; ++i) ends[i] = ends[i + 1];
      for (i = 0; i < range_num - 1; ++i) {
        ends[i] = ends[i + 1];
      }
      ends[i] = -1;
    }

    return true;
  }

  // Check whether the effective range is the full range
  bool IsFullRange() {
    if (strand == 1 && starts[0] == 0 && ends[0] == -1) return true;
    if (strand == 1 && starts[0] == 0 && ends[0] == -1) {
      return true;
    }

    return false;
  }

  // Replace by the range specified in the starts, ends section, but does not
  // apply the strand operation. return new length
  // apply the strand operation. Return new length.
  int Replace(char *s, int len, bool need_complement) {
    if (IsFullRange()) return len;
    if (IsFullRange()) {
      return len;
    }

    int i, j, k;
    i = 0;
    for (k = 0; k < range_num; ++k) {
@@ -78,13 +96,16 @@ class SequenceEffectiveRange {
      if (end == -1) end = len - 1;
      for (j = start; j <= end; ++i, ++j) s[i] = s[j];
    }

    s[i] = '\0';
    len = i;

    if (strand == -1) {
      if (need_complement) {
        for (i = 0; i < len; ++i)
        for (i = 0; i < len; ++i) {
          s[i] = Uint8ToChar(((uint8_t)3) ^ (CharToUint8(s[i])));
        }
      }

      for (i = 0, j = len - 1; i < j; ++i, --j) {
        char tmp = s[i];