source: trunk/GDE/SINA/builddir/src/pseq.cpp

Last change on this file was 19170, checked in by westram, 2 years ago
  • sina source
    • unpack + remove tarball
    • no longer ignore sina builddir.
File size: 4.0 KB
Line 
1/*
2Copyright (c) 2006-2018 Elmar Pruesse <elmar.pruesse@ucdenver.edu>
3
4This file is part of SINA.
5SINA is free software: you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free
7Software Foundation, either version 3 of the License, or (at your
8option) any later version.
9
10SINA is distributed in the hope that it will be useful, but WITHOUT ANY
11WARRANTY; without even the implied warranty of MERCHANTABILITY or
12FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13for more details.
14
15You should have received a copy of the GNU General Public License
16along with SINA.  If not, see <http://www.gnu.org/licenses/>.
17
18Additional permission under GNU GPL version 3 section 7
19
20If you modify SINA, or any covered work, by linking or combining it
21with components of ARB (or a modified version of that software),
22containing parts covered by the terms of the
23ARB-public-library-license, the licensors of SINA grant you additional
24permission to convey the resulting work. Corresponding Source for a
25non-source form of such a combination shall include the source code
26for the parts of ARB used as well as that of the covered work.
27*/
28
29#include "pseq.h"
30
31#include <string>
32
33namespace sina {
34std::ostream&
35operator<<(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
43using namespace sina;
44pseq::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
117void
118pseq::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
Note: See TracBrowser for help on using the repository browser.