Project: s41467-025-60902-2 | Function: splice_site_table_cpp (cpp)

system: You are an expert C++ programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow C++ best practices and maintain consistent code style.
Return **only** the complete C++ function code.

user: Complete this C++ function:

**DESCRIPTION:** Builds a splice site occurrence table from isoform sequences, filtering by minimum occurrence threshold to identify conserved splice junctions in Nanopore long-read data

**KEY TERMS:** {
  "isoform": "transcript isoform sequences",
  "splice_site_thresh": "minimum occurrence threshold",
  "ss_count": "splice site occurrence counts",
  "mid_splice_sites": "internal splice junction matrix",
  "start_vec/end_vec": "5' and 3' terminal exons",
  "split": "exon boundary delimiter",
  "sep": "isoform separator"
}

**CONTEXT CODE:** #include "splice_site_correct.h"

std::vector<std::string> splice_site_cpp(const std::string& input, const std::string& delimiters) {
  std::vector<std::string> tokens;
  istringstream stream(input);
  std::string token;

  while (getline(stream, token)) {
    size_t startPos = 0;
    size_t endPos;

    while ((endPos = token.find_first_of(delimiters, startPos)) != std::string::npos) {
      if (endPos != startPos) {
        tokens.push_back(token.substr(startPos, endPos - startPos));
      }

      startPos = endPos + 1;
    }

    if (startPos < token.length()) {
      tokens.push_back(token.substr(startPos));
    }
  }

  return tokens;
}

std::string getSubString(
    const std::string& strValue,
    const std::string& startChar,
    const std::string& endChar)
{
  std::string subString = "";
  // Get index position of first character
  size_t startPos = strValue.find(startChar);
  // Get index position of second character
  size_t endPos = strValue.rfind(endChar);
  // Check if both the characters exists in string
  if( startPos != std::string::npos &&
      endPos != std::string::npos && startPos != endPos)
  {
    // Get substring from start to end character
    subString = strValue.substr(startPos + 1, endPos - startPos - 1);
  }
  return subString;
}

std::map<std::string, int> isoform_count(std::vector<std::string> isoform,const std::string sep){
  std::map<std::string, int> isoCounts;

  int len = isoform.size();
  std::string temp = "";
  for(int i = 0;i < len;i++){
    temp = getSubString(isoform[i],sep,sep);
    isoCounts[temp]++;
  }
  return(isoCounts);
}


std::unordered_map<std::string, int> splice_site_count_cpp(std::vector<std::string> isoform,
                                            const std::string split,const std::string sep){

  std::map<std::string, int> isoCounts = isoform_count(isoform,sep);
  std::unordered_map<std::string, int> siteCounts;

  for (auto pair : isoCounts) {
    std::vector<std::string> sites = splice_site_cpp(pair.first,split+sep);

    int len = sites.size();
    for (int i = 0;i < len;i++) {
      siteCounts[sites[i]] += pair.second;
    }
  }

  return(siteCounts);
}


bool isin(const std::string element,const StringVector vec){
  int len = vec.size();
  for (int i = 0; i < len; i++) {
    if (vec[i] == element)
      return true;
  }
  return false;
}

// [[Rcpp::export]]
// MASKED FUNCTION: Builds a splice site occurrence table from isoform sequences
List splice_site_table_cpp(std::vector<std::string> isoform,
                                    const std::string split, const std::string sep,
                                    const int splice_site_thresh) {
    // Check for invalid inputs
    if (isoform.empty() || split.empty() || sep.empty() || splice_site_thresh <= 0) {
        return List::create();
    }

    // Get splice site counts
    std::unordered_map<std::string, int> siteCounts = splice_site_count_cpp(isoform, split, sep);

    // Filter sites by threshold and create result table
    List result = List::create();
    for (const auto& pair : siteCounts) {
        if (pair.second >= splice_site_thresh) {
            result[pair.first] = pair.second;
        }
    }

    return result;
}
```

This implementation builds upon existing functions and efficiently filters the splice site occurrences based on the provided threshold. It handles edge cases and returns an Rcpp List containing the conserved splice sites and their counts.







Complete the function implementation replacing "throw std::runtime_error("Not implemented");".