comparison gene_fraction/src/FastaRecord.cpp @ 0:f95150c37d38 draft default tip

planemo upload for repository https://github.com/ChrisD11/Tools commit ddc95e5d6b5f2c0a5340c0bc384aa822db8856d5
author chrisd
date Sun, 21 Feb 2016 23:31:55 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f95150c37d38
1 #include "FastaRecord.h"
2
3 #include <algorithm>
4
5 FastaRecord::FastaRecord(std::string gene_id, std::string gene) :
6 _gene_id(gene_id), _gene(gene), _base_hits(_gene.length(), 0),
7 _gene_hits(0) {}
8
9 std::string FastaRecord::gene_id() const { return _gene_id; }
10
11 std::string FastaRecord::gene() const { return _gene; }
12
13 void FastaRecord::update_gene_hits() {
14 _gene_hits++;
15 }
16
17 int FastaRecord::gene_hits() const {
18 return _gene_hits;
19 }
20
21 int FastaRecord::get_base_hits() const {
22 return static_cast<int>(count(_base_hits.begin(), _base_hits.end(), 1));
23 }
24
25 int FastaRecord::find_gene(const std::vector<FastaRecord> &records,
26 const std::string &gene_id, std::string seq) {
27 int gene_index;
28
29 std::vector<FastaRecord>::const_iterator low;
30 // binary search for fasta record index
31 low = std::lower_bound(records.begin(), records.end(), FastaRecord(gene_id, seq),
32 [](const FastaRecord &a, const FastaRecord &b)
33 { return a.gene_id() < b.gene_id(); });
34 gene_index = (low - records.begin());
35
36 return gene_index;
37 }
38
39 void FastaRecord::sort_by_gene_id(std::vector<FastaRecord> &records) {
40 // sort records by gene id
41 sort(records.begin(), records.end(), [](const FastaRecord &a, const FastaRecord &b) { return a.gene_id() < b.gene_id(); });
42 }
43
44 void FastaRecord::reset_base_hits(std::vector<FastaRecord> &records) {
45 for_each(records.begin(), records.end(), [](FastaRecord &a) { std::fill(a.base_hits().begin(), a.base_hits().end(), 0); });
46 }
47
48 void FastaRecord::reset_gene_hits(std::vector<FastaRecord> &records) {
49 for_each(records.begin(), records.end(), [](FastaRecord &a) { a._gene_hits = 0; });
50 }
51
52 std::vector<int> &FastaRecord::base_hits() {
53 return _base_hits;
54 }
55
56
57
58
59
60
61
62