comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:0fd352f62446
1 #include "Sam.h"
2 #include "alignment_util.h"
3
4 #include <string>
5 #include <vector>
6 #include <fstream>
7 #include <iostream>
8
9 Sam::Sam(std::string sam_fp) : _sam_fp(sam_fp) {}
10
11 void Sam::read_se_sam(const std::string &sam_fp, bool best) {
12 std::ifstream in(sam_fp.c_str());
13 if(!in) {
14 std::cerr << "Could not open sam file " << sam_fp << std::endl;
15 exit(EXIT_FAILURE);
16 }
17
18 std::string alignment;
19 while(getline(in, alignment)) {
20 if(alignment[0] == '@')
21 continue;
22 //std::vector<std::string> parts = split_alignment(alignment);
23 if(se_fields_are_good(alignment, best)) {
24 alignments.push_back(alignment);
25 }
26 }
27 sort_by_qname(alignments);
28 }
29
30 void Sam::read_pe_sam(const std::string &sam_fp, bool best) {
31 std::ifstream in(sam_fp.c_str());
32 if(!in) {
33 std::cerr << "Could not open sam file " << sam_fp << std::endl;
34 exit(EXIT_FAILURE);
35 }
36
37 std::string alignment;
38 while(getline(in, alignment)) {
39 if(alignment[0] == '@')
40 continue;
41 //std::vector<std::string> parts = split_alignment(alignment);
42 if(pe_fields_are_good(alignment, best)) {
43 alignments.push_back(alignment);
44 }
45 }
46 sort_by_qname(alignments);
47 }
48
49 void Sam::sort_by_qname(std::vector<Alignment> &v) {
50 sort(v.begin(), v.end(),
51 [](const Alignment &a, const Alignment &b)
52 { return a.qname() < b.qname(); });
53 }
54
55
56
57