| 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 | #ifndef _QUERY_ARB_H_ |
|---|
| 30 | #define _QUERY_ARB_H_ |
|---|
| 31 | |
|---|
| 32 | #include <string> |
|---|
| 33 | #include <utility> |
|---|
| 34 | #include <vector> |
|---|
| 35 | #include <list> |
|---|
| 36 | #include <memory> |
|---|
| 37 | |
|---|
| 38 | #include <boost/filesystem.hpp> |
|---|
| 39 | |
|---|
| 40 | #include "cseq.h" |
|---|
| 41 | #include "alignment_stats.h" |
|---|
| 42 | |
|---|
| 43 | struct GBDATA; |
|---|
| 44 | |
|---|
| 45 | namespace sina { |
|---|
| 46 | |
|---|
| 47 | /** |
|---|
| 48 | * Base exception thrown by query_arb |
|---|
| 49 | */ |
|---|
| 50 | class query_arb_exception : public std::exception |
|---|
| 51 | { |
|---|
| 52 | public: |
|---|
| 53 | query_arb_exception(std::string& what): m_what(what) {} |
|---|
| 54 | query_arb_exception(std::string what): m_what(std::move(what)) {} |
|---|
| 55 | query_arb_exception(const char* what): m_what(what) {} |
|---|
| 56 | query_arb_exception() = default; |
|---|
| 57 | const char* what() const noexcept override { return m_what.c_str(); } |
|---|
| 58 | ~query_arb_exception() noexcept override = default; |
|---|
| 59 | |
|---|
| 60 | private: |
|---|
| 61 | std::string m_what; |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | class query_arb{ |
|---|
| 66 | query_arb(const boost::filesystem::path& arbfile); |
|---|
| 67 | ~query_arb(); |
|---|
| 68 | |
|---|
| 69 | public: |
|---|
| 70 | /** |
|---|
| 71 | * Factory method. |
|---|
| 72 | * @param file_name ... |
|---|
| 73 | * @returns one instance per database file. If the method is called multiple times on the same file the same instance is returned. |
|---|
| 74 | */ |
|---|
| 75 | static query_arb* getARBDB(const boost::filesystem::path& file_name); |
|---|
| 76 | static void closeOpenARBDBs(); |
|---|
| 77 | |
|---|
| 78 | static const char* fn_turn; |
|---|
| 79 | static const char* fn_acc; |
|---|
| 80 | static const char* fn_start; |
|---|
| 81 | static const char* fn_qual; |
|---|
| 82 | static const char* fn_head; |
|---|
| 83 | static const char* fn_tail; |
|---|
| 84 | static const char* fn_date; |
|---|
| 85 | static const char* fn_astart; |
|---|
| 86 | static const char* fn_astop; |
|---|
| 87 | static const char* fn_idty; |
|---|
| 88 | static const char* fn_family; |
|---|
| 89 | static const char* fn_nuc; |
|---|
| 90 | static const char* fn_nuc_gene; |
|---|
| 91 | static const char* fn_bpscore; |
|---|
| 92 | static const char* fn_used_rels; |
|---|
| 93 | static const char* fn_fullname; |
|---|
| 94 | static const char* fn_align_log; |
|---|
| 95 | static const char* fn_filter; |
|---|
| 96 | static const char* fn_nearest; |
|---|
| 97 | |
|---|
| 98 | /** |
|---|
| 99 | * Saves the database using the default filename in binary format. |
|---|
| 100 | * @note The filename is specified in init(). |
|---|
| 101 | * Do not call this method before init() has been called. |
|---|
| 102 | * |
|---|
| 103 | * @see saveAs(const char* fname, const char* type="b") |
|---|
| 104 | */ |
|---|
| 105 | void save(); |
|---|
| 106 | |
|---|
| 107 | /** |
|---|
| 108 | * Saves the database using the specified filename. |
|---|
| 109 | * @param fname the filename. |
|---|
| 110 | * @param type Defines how the database should be saved. |
|---|
| 111 | * The value is a combination of one or more of the following |
|---|
| 112 | * values: |
|---|
| 113 | * * 'a' ascii |
|---|
| 114 | * * 'b' binary |
|---|
| 115 | * * 'm' save mapfile (only together with binary) |
|---|
| 116 | * * 'f' force saving even in disabled path to a different directory (out of order save) |
|---|
| 117 | * * 'S' save to stdout (for debugging) |
|---|
| 118 | * @note Either 'a' or 'b' must be defined. |
|---|
| 119 | */ |
|---|
| 120 | void saveAs(const boost::filesystem::path& fname, const char* type="b"); |
|---|
| 121 | |
|---|
| 122 | /** |
|---|
| 123 | * Returns filename of underlying ARB database file |
|---|
| 124 | */ |
|---|
| 125 | const boost::filesystem::path& getFileName() const; |
|---|
| 126 | |
|---|
| 127 | void setProtectionLevel(int p); |
|---|
| 128 | |
|---|
| 129 | int getSeqCount() const; |
|---|
| 130 | std::vector<std::string> getSequenceNames(); |
|---|
| 131 | |
|---|
| 132 | const cseq& getCseq(const std::string& name); |
|---|
| 133 | cseq getCseqUncached(const std::string& name); |
|---|
| 134 | void putCseq(const cseq& seq); |
|---|
| 135 | |
|---|
| 136 | /** |
|---|
| 137 | * Loads a meta data entry from ARB into the Cseq |
|---|
| 138 | * Note that this will only load missing keys, and not update |
|---|
| 139 | * changed keys unless relpad=true |
|---|
| 140 | */ |
|---|
| 141 | void loadKey(const cseq& c, const std::string& key, bool reload=false, bool warnMissingField = true); |
|---|
| 142 | void storeKey(cseq& c, const std::string& key); |
|---|
| 143 | std::vector<std::tuple<std::string, std::string, int>> listKeys(); |
|---|
| 144 | |
|---|
| 145 | long getAlignmentWidth() const; |
|---|
| 146 | static void override_default_alignment(const std::string& ali_name); |
|---|
| 147 | |
|---|
| 148 | std::string getFilter(const std::string& name); |
|---|
| 149 | std::vector<int> getPairs(); |
|---|
| 150 | std::vector<alignment_stats> getAlignmentStats(); |
|---|
| 151 | |
|---|
| 152 | void loadCache(); |
|---|
| 153 | void loadCache(std::vector<std::string>& keys); |
|---|
| 154 | std::vector<cseq*> getCacheContents(); |
|---|
| 155 | |
|---|
| 156 | void copySequence(query_arb& source, const std::string& name, bool mark); |
|---|
| 157 | private: |
|---|
| 158 | void setMark(); |
|---|
| 159 | void setMark(const std::string& name); |
|---|
| 160 | void setMark(const cseq& cs); |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | // make query_arb non-copyable |
|---|
| 164 | query_arb(const query_arb&) = delete; |
|---|
| 165 | query_arb& operator=(const query_arb&) = delete; |
|---|
| 166 | |
|---|
| 167 | struct priv_data; |
|---|
| 168 | std::unique_ptr<priv_data> data; |
|---|
| 169 | static std::map<boost::filesystem::path, query_arb*> open_arb_dbs; |
|---|
| 170 | |
|---|
| 171 | }; |
|---|
| 172 | |
|---|
| 173 | inline void |
|---|
| 174 | query_arb::setMark(const cseq& cs) { |
|---|
| 175 | setMark(cs.getName()); |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | inline void |
|---|
| 179 | query_arb::loadCache() { |
|---|
| 180 | std::vector<std::string> vs; loadCache(vs); |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | } // namespace sina |
|---|
| 185 | |
|---|
| 186 | #endif // _QUERY_ARB_H_ |
|---|
| 187 | |
|---|
| 188 | /* |
|---|
| 189 | Local Variables: |
|---|
| 190 | mode:c++ |
|---|
| 191 | c-file-style:"stroustrup" |
|---|
| 192 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) |
|---|
| 193 | indent-tabs-mode:nil |
|---|
| 194 | fill-column:99 |
|---|
| 195 | End: |
|---|
| 196 | */ |
|---|
| 197 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
|---|