mapgd  0.4
A program for the Maximum-likelihood analysis of population genomic data.
 All Data Structures Functions Variables Friends Groups Pages
file_index.h
1 #ifndef _FILE_INDEX_H_
2 #define _FILE_INDEX_H_
3 
4 #include <iostream>
5 #include <map>
6 #include <vector>
7 #include <stdio.h>
8 #include <cstring>
9 #include <string>
10 
11 #ifndef NOSQL
12 #include "sqlite3.h"
13 #endif
14 
15 #include "stream_tools.h"
16 #include "typedef.h"
17 #include "data.h"
18 
20 /* File_index should always be used to re designate pairs of keys into a single record
21  * number.
22  */
23 class File_index : public virtual Data {
24 
25 private:
27  std::map <std::string, id0_t> id0_str_;
28 
30  std::vector <std::string> id0_;
31 
33  std::vector <id1_t> size_;
34 
36  std::vector <id1_t> cumulative_size_;
37 
39  id0_t last_id0_;
40 
42  std::string last_id0_str_;
43 
45  bool open_;
46  size_t byte_size_;
47 
48  static const Registration registered;
49 
50  static Data * create(const std::vector <std::string> & Columns){
51  return new File_index(Columns);
52  }
53 
54 public:
55  File_index();
56  File_index(std::vector<std::string>);
57  bool bianary(void) const {return false;};
58 
60  id1_off_t get_offset (const std::string &, const id1_t &) const;
61 
63  id1_t get_abs_pos (const std::string &, const id1_t &) const;
64 
66  id1_t get_abs_pos (const id0_t &, const id1_t &) const;
67 
69  id0_t get_id0 (const std::string &) const;
70 
72  id0_t get_id0 (const id1_t &) const;
73 
75  id1_t get_id1 (const id1_t &) const;
76 
78  std::string get_string (const id0_t &) const;
79 
81  void set_string (const id0_t &, const std::string &);
82 
84  void set_size (const std::string &, const id1_t &);
85 
87  void set_size (const id0_t &, const id1_t &);
88 
90  void set_last_size (const id1_t &);
91 
93  void set_next_size (const id1_t &);
94 
96  const std::vector <std::string> get_names (void) const;
97 
99  size_t get_names_size (void) const;
100 
102  const std::vector <id1_t> get_sizes (void) const;
103 
105  id1_t get_size (const id0_t &) const;
106 
108  id1_t get_size (const std::string &) const;
109 
111  id1_t get_cumulative_size (const id0_t &) const;
112 
114  id1_t get_cumulative_size (const std::string &) const;
115 
117  id1_t get_reference_size (void) const;
118 
120  id1_t get_last_size (void);
121 
123  id1_t get_next_size (void);
124 
126  int read_index(std::istream &);
127 
129  std::istream & from_sam_header(std::istream &);
130 
132  int add_id (const std::string &, const id1_t &);
133 
135  int write_index(std::ostream &);
136 
138  File_index & operator=(const File_index&);
139 
140  bool is_open(void) const;
141 
142  std::string header(void) const;
143  static const std::string file_name;
144  static const std::string table_name;
145  static const bool binary;
146  size_t size(void) const;
147 
149  void write (std::ostream&) const;
151  void read (std::istream&);
152 
153  const std::string get_file_name() const {return File_index::file_name;};
154  const std::string get_table_name() const {return File_index::table_name;};
155  const bool get_binary() const;
157  const std::string sql_header(void) const;
159  const std::string sql_column_names(void) const;
161  const std::string sql_values(void) const;
163  void sql_read(std::istream &) override;
164 };
165 
166 #endif
std::istream & from_sam_header(std::istream &)
read in a file index from a sam header.
Definition: file_index.cc:128
id1_t get_reference_size(void) const
get the sum of all size.
Definition: file_index.cc:121
const std::string sql_values(void) const
returns the column values (SQL).
Definition: file_index.cc:264
void set_last_size(const id1_t &)
set the number of rows in the most recently read scaffold.
const std::vector< id1_t > get_sizes(void) const
get a vector containing the sizes of each scaffold.
Definition: file_index.cc:193
std::string last_id0_str_
the last string id returned by an decodeid0 quarry. Initialized to "".
Definition: file_index.h:42
id1_t get_last_size(void)
get the size of the last scaffold which has been read from. returns map_file::noid on error...
void set_size(const std::string &, const id1_t &)
set the number of rows (bp) in the scaffold with string id id0.
size_t size(void) const
The size of the class in bytes.
Definition: file_index.cc:248
std::map< std::string, id0_t > id0_str_
a hash table to store pairs of strings and the id representing them.
Definition: file_index.h:27
An interface that transforms pairs of name and position keys into record numbers. ...
Definition: file_index.h:23
void write(std::ostream &) const
use the << operator to write File_index.
Definition: file_index.cc:211
void set_next_size(const id1_t &)
set the number of rows in the next scaffold to be read.
id1_off_t get_offset(const std::string &, const id1_t &) const
returns the number of rows until a row with id0, id1.
int write_index(std::ostream &)
write out a File_index
Definition: file_index.cc:176
void read(std::istream &)
use the >> operator to read File_index.
Definition: file_index.cc:222
std::vector< id1_t > cumulative_size_
the cumulative number of bp per scaffold.
Definition: file_index.h:36
size_t get_names_size(void) const
get the length of the vector containing the name of each scaffold.
Definition: file_index.cc:205
id1_t get_cumulative_size(const id0_t &) const
get the sum of all size less than or equal to id0.
Definition: file_index.cc:104
id1_t get_abs_pos(const std::string &, const id1_t &) const
returns the record number corresponding to id0, id1.
Definition: file_index.cc:50
const std::string sql_column_names(void) const
returns the column names (SQL).
Definition: file_index.cc:259
id0_t last_id0_
the last numerical id returned by an decodeid0 quarry. Initialized to 0-1.
Definition: file_index.h:39
int read_index(std::istream &)
read in a File_index (strictly text mode).
id1_t get_id1(const id1_t &) const
returns the id1 corresponding rowid.
Definition: file_index.cc:73
id1_t get_next_size(void)
get the size of the next scaffold to be read. returns map_file::noid on error.
const std::string sql_header(void) const
returns the string needed to create an SQL table.
Definition: file_index.cc:254
id1_t get_size(const id0_t &) const
get the size of scaffold blarg.
Definition: file_index.cc:95
bool open_
TODO: Is this ever used?
Definition: file_index.h:45
A class which registers a child of Data in Data::new_data_.
Definition: data.h:222
A class which can be written as flat text file or into an SQL database.
Definition: data.h:34
const std::vector< std::string > get_names(void) const
get a vector containing the name of each scaffold.
Definition: file_index.cc:199
void sql_read(std::istream &) override
binds data to sqlite3_stmt.
Definition: file_index.cc:284
File_index & operator=(const File_index &)
not implemented. Do not use.
Definition: file_index.cc:28
std::vector< id1_t > size_
the number of bp per scaffold.
Definition: file_index.h:33
void set_string(const id0_t &, const std::string &)
sets the string corresponding to id0.
std::string get_string(const id0_t &) const
returns the string corresponding to id0.
Definition: file_index.cc:56
std::vector< std::string > id0_
the keys to the hash table id0_str_.
Definition: file_index.h:30
static const bool binary
Returns the destination table name.
Definition: file_index.h:145
int add_id(const std::string &, const id1_t &)
add an new id at the end of the index.
Definition: file_index.cc:164
id0_t get_id0(const std::string &) const
returns the id0 corresponding to string.
Definition: file_index.cc:62