Mercurial > repos > chrisd > testshed
diff snp_caller/src/Sam.cpp @ 0:0fd352f62446 draft default tip
planemo upload for repository https://github.com/ChrisD11/Duplicon commit 3ee0594c692faac542ffa58f4339d79b9b8aefbd-dirty
author | chrisd |
---|---|
date | Sun, 21 Feb 2016 06:05:24 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/snp_caller/src/Sam.cpp Sun Feb 21 06:05:24 2016 -0500 @@ -0,0 +1,57 @@ +#include "Sam.h" +#include "alignment_util.h" + +#include <string> +#include <vector> +#include <fstream> +#include <iostream> + +Sam::Sam(std::string sam_fp) : _sam_fp(sam_fp) {} + +void Sam::read_se_sam(const std::string &sam_fp, bool best) { + std::ifstream in(sam_fp.c_str()); + if(!in) { + std::cerr << "Could not open sam file " << sam_fp << std::endl; + exit(EXIT_FAILURE); + } + + std::string alignment; + while(getline(in, alignment)) { + if(alignment[0] == '@') + continue; + //std::vector<std::string> parts = split_alignment(alignment); + if(se_fields_are_good(alignment, best)) { + alignments.push_back(alignment); + } + } + sort_by_qname(alignments); +} + +void Sam::read_pe_sam(const std::string &sam_fp, bool best) { + std::ifstream in(sam_fp.c_str()); + if(!in) { + std::cerr << "Could not open sam file " << sam_fp << std::endl; + exit(EXIT_FAILURE); + } + + std::string alignment; + while(getline(in, alignment)) { + if(alignment[0] == '@') + continue; + //std::vector<std::string> parts = split_alignment(alignment); + if(pe_fields_are_good(alignment, best)) { + alignments.push_back(alignment); + } + } + sort_by_qname(alignments); +} + +void Sam::sort_by_qname(std::vector<Alignment> &v) { + sort(v.begin(), v.end(), + [](const Alignment &a, const Alignment &b) + { return a.qname() < b.qname(); }); +} + + + +