Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addressing issue #132 #137

Merged
merged 22 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
97c35c4
adding rtrim function for trailing char in primer files
cmaceves Jul 28, 2022
6b9ed98
adding new variable to primer_trim and adding call to populate primer…
cmaceves Jul 29, 2022
f191550
adding print code for primers to help debug
cmaceves Jul 29, 2022
07dff38
changing the return types of the primer pair populate function to ret…
cmaceves Jul 29, 2022
93dfdac
adding name to print primer statements
cmaceves Jul 29, 2022
fc8a3be
add function to find primer pair
cmaceves Jul 29, 2022
3ce6ee7
passing appropriate information to primer trim function
cmaceves Jul 29, 2022
b5d75f5
reverting back the populate primers function and instead passing by r…
cmaceves Aug 2, 2022
7fc709e
saving for branch switch
cmaceves Aug 2, 2022
6695b56
adding function to get overlapping primers for unpaired reads from pa…
cmaceves Aug 5, 2022
99ccc6e
removing extra unused variable
cmaceves Aug 5, 2022
29b6a30
adding test data, template for test code
cmaceves Aug 30, 2022
3c8792b
updating the primer pair test the call trimming
cmaceves Aug 31, 2022
8011622
removing extra function trim_primers_better and switching the way isi…
cmaceves Jan 23, 2023
75eb684
revert to the original way isize_flag is calculated
cmaceves Jan 24, 2023
69f0ed7
changing loc of declaration of variable for github action macos
cmaceves Jan 25, 2023
f823ae1
changing the declaration of cur_depth back, suppressing warning in co…
cmaceves Jan 25, 2023
73fb315
Revert "revert to the original way isize_flag is calculated"
cmaceves Jan 25, 2023
983d233
attempt to silence specific warning on macos build
cmaceves Jan 25, 2023
66d4d9f
going back to the original way isize was called
cmaceves Jan 25, 2023
1c8ef6c
silencing the unused variable warning
cmaceves Jan 25, 2023
cbac14b
changing workflow to use stable mac version and removing trial flag f…
cmaceves Jan 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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