OpenStructure
linear_indexer.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2020 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 
20 
21 #ifndef OST_DB_LINEAR_INDEXER_HH
22 #define OST_DB_LINEAR_INDEXER_HH
23 
24 #include <fstream>
25 #include <map>
26 #include <vector>
27 #include <boost/shared_ptr.hpp>
28 #include <ost/base.hh>
29 #include <ost/stdint.hh>
30 
31 
32 namespace ost { namespace db {
33 
34 class LinearIndexer;
35 typedef boost::shared_ptr<LinearIndexer> LinearIndexerPtr;
36 
37 struct AssemblyInfo {
38 
39  void Read(std::ifstream& in_stream);
40 
41  void Write(std::ofstream& out_stream) const;
42 
43  bool operator==(const AssemblyInfo& other) const {
44  return (data_start == other.data_start &&
45  chain_names == other.chain_names &&
46  chain_lengths == other.chain_lengths);
47  }
48 
49  bool operator!=(const AssemblyInfo& other) const {
50  return !(*this==other);
51  }
52 
54  std::vector<String> chain_names;
55  std::vector<uint> chain_lengths;
56 };
57 
59 
60 public:
61 
62  LinearIndexer(): current_num_residues_(0) { }
63 
64  static LinearIndexerPtr Load(const String& filename);
65 
66  void Save(const String& filename) const;
67 
68  void AddAssembly(const String& name,
69  const std::vector<String>& chain_names,
70  const std::vector<uint>& chain_lengths);
71 
72  void RemoveAssembly(const String& name);
73 
74  std::vector<String> GetAssemblies() const;
75 
76  std::vector<String> GetChainNames(const String& name) const;
77 
78  std::vector<uint> GetChainLengths(const String& name) const;
79 
80  std::pair<uint64_t, uint64_t> GetDataRange(const String& name) const;
81 
82  std::pair<uint64_t, uint64_t> GetDataRange(const String& name,
83  const String& chain_name) const;
84 
85  uint64_t GetNumResidues() const { return current_num_residues_; }
86 
87  bool operator==(const LinearIndexer& other) const {
88  return (assemblies_ == other.assemblies_ &&
89  idx_mapper_ == other.idx_mapper_ &&
90  current_num_residues_ == other.current_num_residues_);
91 
92  }
93 
94  bool operator!=(const LinearIndexer& other) const {
95  return !(*this == other);
96  }
97 
98 private:
99 
100  std::vector<AssemblyInfo> assemblies_;
101  std::map<String, int> idx_mapper_;
102  uint64_t current_num_residues_;
103 };
104 
105 
106 }} // ns
107 
108 #endif
std::vector< String > GetChainNames(const String &name) const
std::pair< uint64_t, uint64_t > GetDataRange(const String &name, const String &chain_name) const
std::pair< uint64_t, uint64_t > GetDataRange(const String &name) const
std::vector< String > GetAssemblies() const
bool operator!=(const LinearIndexer &other) const
void Save(const String &filename) const
bool operator==(const LinearIndexer &other) const
void RemoveAssembly(const String &name)
static LinearIndexerPtr Load(const String &filename)
void AddAssembly(const String &name, const std::vector< String > &chain_names, const std::vector< uint > &chain_lengths)
uint64_t GetNumResidues() const
std::vector< uint > GetChainLengths(const String &name) const
std::string String
Definition: base.hh:54
boost::shared_ptr< LinearIndexer > LinearIndexerPtr
Definition: base.dox:1
unsigned __int64 uint64_t
Definition: stdint_msc.hh:90
void Write(std::ofstream &out_stream) const
bool operator==(const AssemblyInfo &other) const
std::vector< String > chain_names
std::vector< uint > chain_lengths
bool operator!=(const AssemblyInfo &other) const
void Read(std::ifstream &in_stream)