1 /**
2  * UGENE - Integrated Bioinformatics Tools.
3  * Copyright (C) 2008-2021 UniPro <ugene@unipro.ru>
4  * http://ugene.net
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  * MA 02110-1301, USA.
20  */
21 
22 #include "DNAFlexGraph.h"
23 
24 #include <U2Core/DNAAlphabet.h>
25 #include <U2Core/DNASequenceObject.h>
26 #include <U2Core/TextUtils.h>
27 
28 #include "DNAFlexGraphAlgorithm.h"
29 
30 namespace U2 {
31 
32 const qint64 DNAFlexGraphFactory::DEFAULT_WINDOW_SIZE = 100;
33 
34 const int DNAFlexGraphFactory::DEFAULT_WINDOW_STEP = 1;
35 
36 /**
37  * Name of the graph (shown to a user)
38  */
nameByType()39 static QString nameByType() {
40     return DNAFlexGraphFactory::tr("DNA Flexibility");
41 }
42 
43 /**
44  * Constructor of the DNA Flexibility graph
45  */
DNAFlexGraphFactory(QObject * parent)46 DNAFlexGraphFactory::DNAFlexGraphFactory(QObject *parent)
47     : GSequenceGraphFactory(nameByType(), parent) {
48 }
49 
50 /**
51  * Verifies that the sequence alphabet is standard DNA alphabet
52  */
isEnabled(const U2SequenceObject * sequenceObject) const53 bool DNAFlexGraphFactory::isEnabled(const U2SequenceObject *sequenceObject) const {
54     const DNAAlphabet *alphabet = sequenceObject->getAlphabet();
55     return alphabet->getId() == BaseDNAAlphabetIds::NUCL_DNA_DEFAULT();
56 }
57 
58 /**
59  * Initializes graph data
60  */
createGraphs(GSequenceGraphView * view)61 QList<QSharedPointer<GSequenceGraphData>> DNAFlexGraphFactory::createGraphs(GSequenceGraphView *view) {
62     assert(isEnabled(view->getSequenceObject()));
63     return {QSharedPointer<GSequenceGraphData>(new GSequenceGraphData(view, getGraphName(), new DNAFlexGraphAlgorithm()))};
64 }
65 
66 /**
67  * Initializes the graph drawer
68  */
getDrawer(GSequenceGraphView * view)69 GSequenceGraphDrawer *DNAFlexGraphFactory::getDrawer(GSequenceGraphView *view) {
70     qint64 window = qMin(DEFAULT_WINDOW_SIZE, view->getSequenceLength());
71     return new GSequenceGraphDrawer(view, window, DEFAULT_WINDOW_STEP);
72 }
73 
74 }  // namespace U2
75