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 #ifndef _U2_MSA_DBI_H_
23 #define _U2_MSA_DBI_H_
24 
25 #include <U2Core/U2Dbi.h>
26 #include <U2Core/U2Msa.h>
27 #include <U2Core/U2Type.h>
28 
29 namespace U2 {
30 
31 /**
32     An interface to obtain access to multiple sequence alignment
33 */
34 class U2MsaDbi : public U2ChildDbi {
35 protected:
U2MsaDbi(U2Dbi * rootDbi)36     U2MsaDbi(U2Dbi *rootDbi)
37         : U2ChildDbi(rootDbi) {
38     }
39 
40 public:
41     /** Reads Msa objects by id */
42     virtual U2Msa getMsaObject(const U2DataId &id, U2OpStatus &os) = 0;
43 
44     /** Returns the number of rows in the MSA */
45     virtual int getNumOfRows(const U2DataId &msaId, U2OpStatus &os) = 0;
46 
47     /** Returns all MSA rows */
48     virtual QList<U2MsaRow> getRows(const U2DataId &msaId, U2OpStatus &os) = 0;
49 
50     /** Return a row with the specified ID */
51     virtual U2MsaRow getRow(const U2DataId &msaId, qint64 rowId, U2OpStatus &os) = 0;
52 
53     /** Returns the list of rows IDs in the database for the specified MSA (in increasing order) */
54     virtual QList<qint64> getOrderedRowIds(const U2DataId &msaId, U2OpStatus &os) = 0;
55 
56     /** Return the MSA alphabet */
57     virtual U2AlphabetId getMsaAlphabet(const U2DataId &msaId, U2OpStatus &os) = 0;
58 
59     /** Return the MSA length */
60     virtual qint64 getMsaLength(const U2DataId &msaId, U2OpStatus &os) = 0;
61 
62     /**
63      * Creates a new empty MSA object
64      * Requires: U2DbiFeature_WriteMsa feature support
65      */
66     virtual U2DataId createMcaObject(const QString &folder, const QString &name, const U2AlphabetId &alphabet, U2OpStatus &os) = 0;
67     virtual U2DataId createMcaObject(const QString &folder, const QString &name, const U2AlphabetId &alphabet, int length, U2OpStatus &os) = 0;
68     virtual U2DataId createMsaObject(const QString &folder, const QString &name, const U2AlphabetId &alphabet, U2OpStatus &os) = 0;
69     virtual U2DataId createMsaObject(const QString &folder, const QString &name, const U2AlphabetId &alphabet, int length, U2OpStatus &os) = 0;
70 
71     /**
72      * Updates the multiple alignment name
73      * Requires: U2DbiFeature_WriteMsa feature support
74      */
75     virtual void updateMsaName(const U2DataId &msaId, const QString &name, U2OpStatus &os) = 0;
76 
77     /**
78      * Updates the multiple alignment alphabet
79      * Requires: U2DbiFeature_WriteMsa feature support
80      */
81     virtual void updateMsaAlphabet(const U2DataId &msaId, const U2AlphabetId &alphabet, U2OpStatus &os) = 0;
82 
83     /**
84      * Adds rows to the MSA
85      * Requires: U2DbiFeature_WriteMsa feature support
86      *
87      * Inserts rows at the given insertRowIndex, so the first inserted row will have rowIndex === insertRowIndex.
88      * For example with insertRowIndex = 0 rows will be pre-appended to the MSA.
89      * If insertRowIndex < 0 || insertRowIndex >= MSA.length - appends rows to the end of the MSA.
90      *
91      * Details:
92      * Creates rows (and gap models for them) in the database.
93      * Enlarges msa length, if 'length' of any of the 'rows' is greater than current msa length.
94      * Recalculates 'length' of the 'rows'.
95      * Assigns MSA as a parent for all the sequences.
96      * If a row ID equals "-1", sets a valid ID to the passed U2MaRow instances.
97      * Updates the number of rows of the MSA.
98      * Updates the alignment length.
99      * Increments the alignment version.
100      * Tracks modifications, if required.
101      */
102     virtual void addRows(const U2DataId &msaId, QList<U2MsaRow> &rows, int insertRowIndex, U2OpStatus &os) = 0;
103 
104     /**
105      * Adds a row to the MSA
106      * If 'rowIndex' equals to '-1' the row is appended to the end of the MSA,
107      * otherwise it is inserted to the specified position and all positions are updated.
108      * Requires: U2DbiFeature_WriteMsa feature support
109      */
110     virtual void addRow(const U2DataId &msaId, int rowIndex, U2MsaRow &row, U2OpStatus &os) = 0;
111 
112     /**
113      * Removes rows from MSA
114      * Automatically removes affected sequences that are not anymore located in some folder nor Msa object
115      * Requires: U2DbiFeature_WriteMsa feature support
116      */
117     virtual void removeRows(const U2DataId &msaId, const QList<qint64> &rowIds, U2OpStatus &os) = 0;
118 
119     /**
120      * Removes the row gaps, the row.
121      * Also removes the record that the msa is a parent of the row sequence
122      * and attempts to remove the sequence after it.
123      * Requires: U2DbiFeature_WriteMsa feature support
124      */
125     virtual void removeRow(const U2DataId &msaId, qint64 rowId, U2OpStatus &os) = 0;
126 
127     /** Updates name of the sequence of the row. */
128     virtual void updateRowName(const U2DataId &msaId, qint64 rowId, const QString &newName, U2OpStatus &os) = 0;
129 
130     /**
131      * Updates a row with the specified ID and its sequence.
132      * Requires: U2DbiFeature_WriteMsa feature support
133      */
134     virtual void updateRowContent(const U2DataId &msaId, qint64 rowId, const QByteArray &seqBytes, const QList<U2MsaGap> &gaps, U2OpStatus &os) = 0;
135 
136     /**
137      * Removes all previous values and sets a new gap model for a row in a MSA
138      * Requires: U2DbiFeature_WriteMsa feature support
139      */
140     virtual void updateGapModel(const U2DataId &msaId, qint64 msaRowId, const QList<U2MsaGap> &gapModel, U2OpStatus &os) = 0;
141 
142     /**
143      * Updates positions of the rows in the database according to the order in the list
144      * Be careful, all IDs must exactly match IDs of the MSA!
145      * Requires: U2DbiFeature_WriteMsa feature support
146      */
147     virtual void setNewRowsOrder(const U2DataId &msaId, const QList<qint64> &rowIds, U2OpStatus &os) = 0;
148 
149     /** Updates a part of the Msa object info - the length */
150     virtual void updateMsaLength(const U2DataId &msaId, qint64 length, U2OpStatus &os) = 0;
151 };
152 
153 }  // namespace U2
154 
155 #endif
156