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