| 1 | /* |
|---|
| 2 | Copyright (c) 2006-2018 Elmar Pruesse <elmar.pruesse@ucdenver.edu> |
|---|
| 3 | |
|---|
| 4 | This file is part of SINA. |
|---|
| 5 | SINA is free software: you can redistribute it and/or modify it under |
|---|
| 6 | the terms of the GNU General Public License as published by the Free |
|---|
| 7 | Software Foundation, either version 3 of the License, or (at your |
|---|
| 8 | option) any later version. |
|---|
| 9 | |
|---|
| 10 | SINA is distributed in the hope that it will be useful, but WITHOUT ANY |
|---|
| 11 | WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|---|
| 13 | for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with SINA. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | |
|---|
| 18 | Additional permission under GNU GPL version 3 section 7 |
|---|
| 19 | |
|---|
| 20 | If you modify SINA, or any covered work, by linking or combining it |
|---|
| 21 | with components of ARB (or a modified version of that software), |
|---|
| 22 | containing parts covered by the terms of the |
|---|
| 23 | ARB-public-library-license, the licensors of SINA grant you additional |
|---|
| 24 | permission to convey the resulting work. Corresponding Source for a |
|---|
| 25 | non-source form of such a combination shall include the source code |
|---|
| 26 | for the parts of ARB used as well as that of the covered work. |
|---|
| 27 | */ |
|---|
| 28 | |
|---|
| 29 | #include "pseq.h" |
|---|
| 30 | |
|---|
| 31 | #include <string> |
|---|
| 32 | |
|---|
| 33 | namespace sina { |
|---|
| 34 | std::ostream& |
|---|
| 35 | operator<<(std::ostream& out, const aligned_base_profile& ab) |
|---|
| 36 | { |
|---|
| 37 | std::stringstream tmp; |
|---|
| 38 | tmp << ab.getBase().getString() << "(" << ab.getPosition() << ")"; |
|---|
| 39 | return out << tmp.str(); |
|---|
| 40 | } |
|---|
| 41 | } // namespace sina |
|---|
| 42 | |
|---|
| 43 | using namespace sina; |
|---|
| 44 | pseq::pseq(std::vector<const cseq*>::iterator seqs_it, |
|---|
| 45 | std::vector<const cseq*>::iterator seqs_end) |
|---|
| 46 | : width(0) |
|---|
| 47 | { |
|---|
| 48 | if (seqs_it != seqs_end) { |
|---|
| 49 | width = (*seqs_it)->getWidth(); |
|---|
| 50 | } |
|---|
| 51 | int height = 0; |
|---|
| 52 | |
|---|
| 53 | std::vector<cseq::const_iterator> base_iterators, base_ends; |
|---|
| 54 | for (; seqs_it != seqs_end; ++seqs_it) { |
|---|
| 55 | base_iterators.push_back((*seqs_it)->begin()); |
|---|
| 56 | base_ends.push_back((*seqs_it)->end()); |
|---|
| 57 | ++height; |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | bool gap[height]; |
|---|
| 61 | for (int i=0; i<height; ++i) { |
|---|
| 62 | gap[i] = true; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | using idx_type = aligned_base::idx_type; |
|---|
| 66 | |
|---|
| 67 | idx_type current_column = 0; |
|---|
| 68 | while (current_column < width) { |
|---|
| 69 | idx_type next_column = width; |
|---|
| 70 | int A=0, G=0, C=0, T=0; |
|---|
| 71 | int gapOpen=0, gapExtend=0; |
|---|
| 72 | for (int row = 0; row < height; ++row) { |
|---|
| 73 | cseq::const_iterator it = base_iterators[row]; |
|---|
| 74 | if (it != base_ends[row] && |
|---|
| 75 | it->getPosition() == current_column) { |
|---|
| 76 | if (it->ambig_order() > 0) { |
|---|
| 77 | int points = 12 / it->ambig_order(); |
|---|
| 78 | if (it->has_A()) { |
|---|
| 79 | A += points; |
|---|
| 80 | } |
|---|
| 81 | if (it->has_G()) { |
|---|
| 82 | G += points; |
|---|
| 83 | } |
|---|
| 84 | if (it->has_C()) { |
|---|
| 85 | C += points; |
|---|
| 86 | } |
|---|
| 87 | if (it->has_TU()) { |
|---|
| 88 | T += points; |
|---|
| 89 | } |
|---|
| 90 | gap[row] = false; |
|---|
| 91 | } |
|---|
| 92 | ++base_iterators[row]; |
|---|
| 93 | } else { |
|---|
| 94 | if (gap[row]) { |
|---|
| 95 | ++gapExtend; |
|---|
| 96 | } else { |
|---|
| 97 | gap[row] = true; |
|---|
| 98 | ++gapOpen; |
|---|
| 99 | } |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | if (base_iterators[row] != base_ends[row]) { |
|---|
| 103 | next_column = std::min( |
|---|
| 104 | next_column, |
|---|
| 105 | base_iterators[row]->getPosition() |
|---|
| 106 | ); |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | base_profile bp(A, G, C, T, gapOpen*12, gapExtend*12); |
|---|
| 111 | profile.emplace_back(current_column, bp); |
|---|
| 112 | |
|---|
| 113 | current_column = next_column; |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | void |
|---|
| 118 | pseq::print_graphviz(std::ostream& out, const std::string& /*name*/) { |
|---|
| 119 | for (iterator it = begin(); it != end(); ++it) { |
|---|
| 120 | out << it->getBase().getString() << std::endl; |
|---|
| 121 | } |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | /* |
|---|
| 125 | Local Variables: |
|---|
| 126 | mode:c++ |
|---|
| 127 | c-file-style:"stroustrup" |
|---|
| 128 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
|---|
| 129 | indent-tabs-mode:nil |
|---|
| 130 | fill-column:99 |
|---|
| 131 | End: |
|---|
| 132 | */ |
|---|
| 133 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
|---|
| 134 | |
|---|