Skip to content

Commit

Permalink
Merge pull request #137 from andersen-lab/issue_132
Browse files Browse the repository at this point in the history
addressing issue #132
  • Loading branch information
cmaceves committed Feb 1, 2023
2 parents e09697d + cbac14b commit 4d65778
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:

build-macos:

runs-on: [ macos-latest ]
runs-on: [ macos-11 ]

steps:
- uses: actions/checkout@master
Expand Down
17 changes: 17 additions & 0 deletions data/primer_pair_test/test_primer_pair.bed
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MN908947.3 3507 3531 nCoV-2019_11_RIGHT 1 -
MN908947.3 3460 3482 nCoV-2019_12_LEFT 2 +
MN908947.3 3826 3853 nCoV-2019_12_RIGHT 2 -
MN908947.3 3771 3795 nCoV-2019_13_LEFT 1 +
MN908947.3 4142 4164 nCoV-2019_13_RIGHT 1 -
MN908947.3 4054 4077 nCoV-2019_14_LEFT 2 +
MN908947.3 4044 4068 nCoV-2019_14_LEFT_alt4 2 +
MN908947.3 4428 4450 nCoV-2019_14_RIGHT 2 -
MN908947.3 4402 4424 nCoV-2019_14_RIGHT_alt2 2 -
MN908947.3 4294 4321 nCoV-2019_15_LEFT 1 +
MN908947.3 4295 4322 nCoV-2019_15_LEFT_alt1_ssi1 1 +
MN908947.3 4296 4322 nCoV-2019_15_LEFT_alt1 1 +
MN908947.3 4674 4696 nCoV-2019_15_RIGHT 1 -
MN908947.3 4666 4689 nCoV-2019_15_RIGHT_alt3 1 -
MN908947.3 4636 4658 nCoV-2019_16_LEFT 2 +
MN908947.3 4995 5017 nCoV-2019_16_RIGHT 2 -
MN908947.3 4939 4966 nCoV-2019_17_LEFT 1 +
7 changes: 7 additions & 0 deletions data/primer_pair_test/test_primer_pair_trim.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
nCoV-2019_12_LEFT nCoV-2019_12_RIGHT
nCoV-2019_13_LEFT nCoV-2019_13_RIGHT
nCoV-2019_14_LEFT nCoV-2019_14_RIGHT
nCoV-2019_14_LEFT_alt4 nCoV-2019_14_RIGHT_alt2
nCoV-2019_15_LEFT nCoV-2019_15_RIGHT
nCoV-2019_15_LEFT_alt1 nCoV-2019_15_RIGHT_alt3
nCoV-2019_16_LEFT nCoV-2019_16_RIGHT
Binary file not shown.
2 changes: 1 addition & 1 deletion src/call_consensus_pileup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ret_t get_consensus_allele(std::vector<allele> ad, uint8_t min_qual, double thre
std::vector<allele> nuc_pos;
allele tmp_a;
char n;
uint32_t max_l = 0, max_depth = 0, tmp_depth = 0, cur_depth = 0, total_max_depth = 0, gap_depth = 0, total_indel_depth = 0;
uint32_t max_l = 0, max_depth = 0, cur_depth = 0, tmp_depth = 0, total_max_depth = 0, gap_depth = 0, total_indel_depth = 0;
uint8_t ambg_n = 1, ctr = 0;
double q = 0, tq = 0, cur_threshold = 0;
std::vector<allele>::iterator it;
Expand Down
2 changes: 1 addition & 1 deletion src/interval_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void IntervalTree::inOrder(ITNode *root){

// A stand-alone function to create a tree containing the coordinates of each amplicon
// based on user-specified primer pairs
IntervalTree populate_amplicons(std::string pair_info_file, std::vector<primer> primers){
IntervalTree populate_amplicons(std::string pair_info_file, std::vector<primer> &primers){
int amplicon_start = -1;
int amplicon_end = -1;
IntervalTree tree = IntervalTree();
Expand Down
2 changes: 1 addition & 1 deletion src/interval_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ class IntervalTree{
void inOrder() {inOrder(_root);}
};

IntervalTree populate_amplicons(std::string pair_info_file, std::vector<primer> primers);
IntervalTree populate_amplicons(std::string pair_info_file, std::vector<primer> &primers);

#endif
84 changes: 73 additions & 11 deletions src/primer_bed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,40 @@ std::vector<primer> get_primers(std::vector<primer> p, unsigned int pos){
return primers_with_mismatches;
}

//function to trim trailing spaces
std::string& rtrim(std::string& str, const std::string& chars = "\t\n\v\f\r ")
{
str.erase(str.find_last_not_of(chars) + 1);
return str;
}

// Assumes unique primer names in BED file
//returns the index of a primer by name
int get_primer_indice(std::vector<primer> p, std::string name){
//iterate through the primers from the bed file
for(std::vector<primer>::iterator it = p.begin(); it != p.end(); ++it) {
if(it->get_name().compare(name) == 0){
//check if the two strings are the same
if(it->get_name().compare(rtrim(name)) == 0){
return it - p.begin();
}
}
return -1;
}

//function using the tab seperated primer pair file
int populate_pair_indices(std::vector<primer> &primers, std::string path){
/*
* @param primers: the primer vector to add pair info to
* @param path: the path to the primer pair file
*/

//load primer pair file
std::ifstream fin(path.c_str());
std::string line, cell, p1,p2;
std::stringstream line_stream;
std::vector<primer>::iterator it;
int32_t indice;
//iterate the primer pair file line by line
while (std::getline(fin, line)){
line_stream << line;
std::getline(line_stream, cell, '\t');
Expand All @@ -257,22 +275,31 @@ int populate_pair_indices(std::vector<primer> &primers, std::string path){
std::getline(line_stream, cell, '\t');
p2 = cell;
line_stream.clear();

p1 = rtrim(p1);
p2 = rtrim(p2);

if(!p1.empty() && !p2.empty()){
for(it = primers.begin(); it != primers.end(); ++it) {
if (it->get_name() == p1) {
indice = get_primer_indice(primers, p2);
if (indice != -1)
it->set_pair_indice(indice);
else
std::cout << "Primer pair for " << p1 << " not found in BED file." <<std::endl;
} else if (it->get_name() == p2){
indice = get_primer_indice(primers, p1);
//search for primer name in pair file
if (it->get_name() == p1) {
//make sure it's pair exists
indice = get_primer_indice(primers, p2);
if (indice != -1){
it->set_pair_indice(indice);
}else{
std::cout << "Primer pair for " << p1 << " not found in BED file." <<std::endl;
}
} else if (it->get_name() == p2){
indice = get_primer_indice(primers, p1);
if(indice != -1)
it->set_pair_indice(indice);
else
std::cout << "Primer pair for " << p2 << " not found in BED file." << std::endl;
}
}
}
} else {
std::cout << "Primer pair is empty." << std::endl;
}
}
return 0;
Expand All @@ -287,4 +314,39 @@ primer get_min_start(std::vector<primer> primers){
primer get_max_end(std::vector<primer> primers){
auto minmax_start = std::minmax_element(primers.begin(), primers.end(), [] (primer lhs, primer rhs) {return lhs.get_end() < rhs.get_end();});
return *(minmax_start.second);
}
}

//give a primer index, find its pair and return the primer
primer fetch_primer_pair(int16_t index, std::vector<primer> primers){
/*
* @param index: the pair index for the primer of interest
* @return pair_primer: the primer object that's pairs with the primer of interest
*/
std::vector<primer>::iterator it;
primer pair_primer;
for(it = primers.begin(); it != primers.end(); ++it) {
if(it->get_indice() == index){
return *it;
}
}
return(pair_primer);
}

void print_all_primer_info(std::vector<primer> primers){
std::vector<primer>::iterator it;
for(it = primers.begin(); it != primers.end(); ++it) {
std::cout << "Primer name: " << it->get_name() << std::endl;
std::cout<< "Primer start: " << it->get_start() << std::endl;
std::cout<< "Primer end: " << it->get_end() << std::endl;
std::cout<< "Indice: " << it->get_indice() << std::endl;
std::cout<< "Pair indice: " << it->get_pair_indice() << std::endl;
}
}

void print_primer_info(primer primer){
std::cout << "Primer name: " << primer.get_name() << std::endl;
std::cout<< "Primer start: " << primer.get_start() << std::endl;
std::cout<< "Primer end: " << primer.get_end() << std::endl;
std::cout<< "Indice: " << primer.get_indice() << std::endl;
std::cout<< "Pair indice: " << primer.get_pair_indice() << std::endl;
}
3 changes: 3 additions & 0 deletions src/primer_bed.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ std::vector<primer> populate_from_file(std::string path, int32_t offset);
std::vector<primer> populate_from_file(std::string path);
std::vector<primer> get_primers(std::vector<primer> p, unsigned int pos);
int get_primer_indice(std::vector<primer> p, std::string name);
primer fetch_primer_pair(int16_t index, std::vector<primer> primers);
int populate_pair_indices(std::vector<primer> &primers, std::string path);
void print_primer_info(primer primers);
void print_all_primer_info(std::vector<primer> primers);
primer get_min_start(std::vector<primer> primers);
primer get_max_end(std::vector<primer> primers);

Expand Down
Loading

0 comments on commit 4d65778

Please sign in to comment.