mapgd  0.4
A program for the Maximum-likelihood analysis of population genomic data.
 All Data Structures Functions Variables Friends Groups Pages
map_file.h
1 #ifndef _MAP_FILE_H_
2 #define _MAP_FILE_H_
3 
4 #include <map>
5 #include <string>
6 #include <iostream>
7 #include <typeinfo>
8 #include <libintl.h>
9 
10 #include "stream_tools.h"
11 #include "typedef.h"
12 #include "stream_tools.h"
13 #include "file_index.h"
14 #include "error_codes.h"
15 
16 /* These should all be included from the objects using this code, but I'm not
17  * linking things correctly right now.
18  */
19 #include "allele.h"
20 #include "linkage_data.h"
21 #include "locus.h"
22 #include "genotype.h"
23 #include "sample_gof.h"
24 #include "relatedness_data.h"
25 #include "population.h"
26 #include "pooled_data.h"
27 #include "sample_name.h"
28 #include "bcf2pro.h"
29 #include "gzstream.h"
30 #include "tmp_buffer.h"
31 
32 #define READ std::ios::in
33 #define WRITE std::ios::out
34 #define BINARY std::ios::binary
35 
36 #define OPEN 1
37 // PLEASE LIMIT LINE LENGTH TO 79 CHARACTERS----------------------------------/
38 
40 
50 class Base_file {
51 private:
52  void write_binary(const Data *);
53  void write_binary(const Indexed_data *);
54  void write_text(const Data *);
55  void write_text(File_index &, const Indexed_data *);
56 
57 protected:
58 
60  bool open_;
61 
63  /* Since all tables begin with a header,
64  * Base_file::read(Data *) will return NULL before until
65  * read_header has been called and moved the iostream past
66  * the header.
67  */
68  bool table_open_;
69 
72 
74  bool compressed_;
75 
78 
79  bool read_;
80  bool write_;
81  bool binary_;
82  bool try_binary_;
83  bool indexed_;
84 
85  std::istream *in_;
86  std::ostream *out_;
87 
89 
90  std::fstream file_;
91 
94 
96  std::ios::openmode openmode_;
97  std::string filename_;
98 public:
100  const std::fstream::openmode& openmode();
102  const std::string& filename();
104 
105  Base_file();
106 
108  void open_no_extention(const char *, const std::ios::openmode &);
110  void open(const std::ios::openmode&);
112  void open(std::iostream*, const std::ios_base::openmode &);
114  void open(std::istream*, const std::ios_base::openmode &);
116  void open(std::ostream*, const std::ios_base::openmode &);
117 
119  std::istream* get_in(void);
121  std::ostream* get_out(void);
122 
124  void close(void);
126  void close_table(void);
128  bool is_open(void) const;
130  bool table_is_open(void) const;
132  bool binary(void) const;
133 
137  Data *read_header(void);
139 
140  void write_header(const Data *);
141  void write_header(const File_index &, const Data *);
142 
144  /*
145  *
146  */
147  Base_file& read(Data *);
149 
151  Base_file& write(const Data *);
152  Base_file& write(File_index &, const Indexed_data *);
153 
155  void seek(const std::streampos &pos);
157  void seekg(const std::streampos &pos);
159  void seekp(const std::streampos &pos);
160 
161  void seek(std::streampos pos, std::ios_base::seekdir way);
162  void seekg(std::streampos off, std::ios_base::seekdir way);
163  void seekp(std::streampos off, std::ios_base::seekdir way);
164 
165  std::streampos tellp(void);
166  std::streampos tellg(void);
167 
172  void set_delim (const char&);
175  const char & get_delim (void) const;
178  /*functions dealing with ?*/
179 
186  size_t size(void) const;
187  bool eof(void);
188  bool indexed(void) const;
189  bool concatenated(void);
190  bool check_concatenated(void);
191  bool check_compressed(void);
192 
193 };
194 
195 template <class Data>
196 class Data_file : public Base_file {
197 private :
198 protected :
199  void read_binary(Data &);
200  void write_binary(const Data &);
201 
202  virtual void read_text(Data &){};
203  virtual void write_text(const Data&){};
204 
205  using Base_file::out_;
206  using Base_file::in_;
207 
208  using Base_file::open_;
210  using Base_file::read_;
211  using Base_file::write_;
213  using Base_file::binary_;
214  using Base_file::filename_;
216  using Base_file::indexed_;
217 public:
218  using Base_file::open;
219 
221  void open(const char *, const std::ios_base::openmode &);
222 
224  void open_extention(const char *, const std::ios_base::openmode &);
225 
226 // ~Data_file(){};
227 
229 
237  void open_from(Base_file &);
238 
240 
248  void open_header(Base_file &);
249 
251 
253  Data_file& write(const Data &);
254 
256 
258  Data_file& read(Data &);
259 
260  using Base_file::concatenated;
261 };
262 
263 template <class T>
264 class Flat_file : public Data_file <T> {
265 private:
266  void read_text(T&);
267  void write_text(const T&);
268 
269  using Data_file<T>::out_; //(const std::ios_base::openmode &);
270  using Data_file<T>::in_; //(const std::ios_base::openmode &);
271  using Base_file::write_; //(const std::ios_base::openmode &);
272  using Base_file::binary_; //(const std::ios_base::openmode &);
273  using Base_file::try_binary_; //(const std::ios_base::openmode &);
274  using Base_file::concatenated_; //(const std::ios_base::openmode &);
276 
277 public:
278  using Data_file<T>::open;
279  using Base_file::get_delim;
280  using Base_file::concatenated;
281 // ~Flat_file(){};
282  void write_header(const T&);
283  T read_header(void);
284 };
285 
286 template <class T>
287 class Indexed_file: public Data_file <T> {
288 private:
289  id1_t reference_size_;
290 protected:
292 
293  void read_text(T&);
294  void write_text(const T&);
295 
296  void read_binary(T &);
297  void write_binary(const T &);
298 
299  using Data_file<T>::out_; //(const std::ios_base::openmode &);
300  using Data_file<T>::in_; //(const std::ios_base::openmode &);
301  using Base_file::write_; //(const std::ios_base::openmode &);
302  using Base_file::binary_; //(const std::ios_base::openmode &);
303  using Base_file::try_binary_; //(const std::ios_base::openmode &);
305  using Base_file::read_;
306  using Base_file::concatenated_; //(const std::ios_base::openmode &);
307  using Base_file::filename_;
308 
309 public:
310  using Data_file<T>::open;
311  using Base_file::concatenated;
312 
313  void set_index(const File_index&);
314  ~Indexed_file(){};
315 
316  File_index get_index(void) const;
317 
322  Indexed_file& write(const T&); //(const Indexed_data &);
323  Indexed_file& read(T&); //(const Indexed_data &);
324 
325  id1_t get_pos(const T &) const;
326  void write_header(const T&);
327  T read_header(void);
328 };
329 
330 template <class T>
332  void read_text(T&);
333  void write_text(const T&);
334 
335  void read_binary(T &);
336  void write_binary(const T &);
337 
338  using Indexed_file<T>::file_index_; //(const std::ios_base::openmode &);
339  using Data_file<T>::out_; //(const std::ios_base::openmode &);
340  using Data_file<T>::in_; //(const std::ios_base::openmode &);
341  using Base_file::write_; //(const std::ios_base::openmode &);
342  using Base_file::binary_; //(const std::ios_base::openmode &);
343  using Base_file::try_binary_; //(const std::ios_base::openmode &);
345  using Base_file::read_;
346  using Base_file::concatenated_; //(const std::ios_base::openmode &);
347  using Base_file::filename_;
348 
349 public:
350  using Data_file<T>::open;
351  using Base_file::concatenated;
352  Double_indexed_file& write(const T&); //(const Indexed_data &);
353  Double_indexed_file& read(T&); //(const Indexed_data &);
354 };
355 
356 /*
357 static struct Map_file_registry_initalizer {
358  Map_file_registry_initalizer ();
359  ~Map_file_registry_initalizer ();
360 } Map_file_registry_initalizer;
361 
362 class Map_file_registration
363 {
364 public:
366  Map_file_registration (const std::string &str, *(*fn)() );
367  ~Map_file_registration (void);
368 private:
369  std::string name_;
370 };
371 std::vector <std::string> map_registry_list(void);
372 */
373 
374 //This seriously needs to be cleaned up.
375 
376 
377 template <class T>
378 void Data_file<T>::open(const char* filename, const std::ios_base::openmode &mode)
379 {
380  std::vector<std::string> line;
381  filename_=std::string(filename);
382  if (open_){
383  std::cerr << __FILE__ << ":" << __LINE__ << ": " << typeid(this).name() << " is already open." << std::endl;
384  exit(0);
385  }
386  if ( mode & std::ios::in ){
387  line=split_last(filename, '.');
388 // if ( Base_file::check_concatenated(filename) ){
389  if (line.back()!=T::file_name) {
390 #ifdef DEBUG
391  std::cerr << line.back() << "!=" << T::file_name;
392  std::cerr << "opening " << filename_ << " in concatenated mode\n";
393 #endif
394  concatenated_=true;
395  open_no_extention(filename, mode);
396  return;
397  } else {
398  concatenated_=false;
399  filename_=line[0];
400  }
401  } else {
402  concatenated_=false;
403  }
404 #ifdef DEBUG
405  std::cerr << "opening "<< filename_ <<" in split mode\n";
406 #endif
407  open_extention(filename_.c_str(), mode);
408 }
409 
410 template <class T>
411 void Data_file<T>::open_extention(const char* filename, const std::ios_base::openmode &mode)
412 {
413  if (filename_.size()==0) filename_=std::string(filename);
414  std::string temp_filename=std::string(filename)+T::file_name;
415 #ifdef DEBUG
416  std::cerr << __LINE__ << "opening w extension "<< temp_filename <<"\n";
417 #endif
418  open_no_extention(temp_filename.c_str(), mode);
419 }
420 
421 template <class T>
423 {
424  if (file.table_is_open() ) file.close_table();
425  if (file.openmode() & std::ios::in){
426 #ifdef DEBUG
427  std::cerr << "opening from...\n";
428 #endif
429  if(file.concatenated() ) this->open(file.get_in(), file.openmode() );
430  else this->open_extention(file.filename().c_str(), file.openmode() );
431  } else if (file.openmode() & std::ios::out) {
432  if(file.concatenated() ) this->open(file.get_out(), file.openmode() );
433  else this->open_extention(file.filename().c_str(), file.openmode() );
434  }
435  try_binary_=(file.openmode() & std::ios::binary);
436  open_=true;
437 }
438 
439 template <class T>
440 id1_t Indexed_file<T>::get_pos(const T &data) const
441 {
442  return data.get_abs_pos();
443 }
444 
445 template <class T>
447 {
448  if (!table_open_ ){
449  return *this;
450  }
451  if (read_){
452  if (binary_) read_binary(data);
453  else read_text(data);
454  } else {
455  std::cerr << __FILE__<< ":" <<__LINE__ << ": file not open for reading. The methods Flat_file<type>::open() and Flat_file<type>::read_header(<type>) should be called.";
456  }
457  return *this;
458 }
459 
460 template <class T>
462 {
463  if (!table_open_ ){
464  return *this;
465  }
466  if (read_){
467  if (binary_) read_binary(data);
468  else read_text(data);
469  } else {
470  std::cerr << __FILE__<< ":" <<__LINE__ << ": file not open for reading. The methods Flat_file<type>::open() and Flat_file<type>::read_header(<type>) should be called.";
471  }
472  return *this;
473 }
474 
475 template <class T>
477 {
478  if (!table_open_ ){
479  return *this;
480  }
481  if (read_){
482  if (binary_) read_binary(data);
483  else read_text(data);
484  } else {
485  std::cerr << __FILE__<< ":" <<__LINE__ << ": file not open for reading. The methods Flat_file<type>::open() and Flat_file<type>::read_header(<type>) should be called.";
486  }
487  return *this;
488 }
489 
490 template <class T>
492 {
493  if (!in_->good() ) {
494  std::cerr << "an error has occurred during reading.\n";
495  exit(0);
496  }
497  if (in_->peek()=='@') {
498  std::string line;
499  std::getline(*in_, line);
500  if (line!="@END_TABLE") {
501  std::cerr << __FILE__ << ":" << __LINE__ << ": file not closed correctly, exiting.\n";
502  std::cerr << line << std::endl;
503  exit(0);
504  }
505  if (!concatenated_) {
506  this->close();
507  } else {
508  this->close_table();
509  }
510  }
511  else *in_ >> data;
512 }
513 
514 template <class T>
516 {
517  //TODO Check for table_open instead?
518  id1_t pos;
519  std::string scaffold;
520  if (!in_->good() ) {
521  std::cerr << "an error has occurred during reading.\n";
522  exit(0);
523  }
524  if (in_->peek()=='@') {
525  std::string line;
526  *in_ >> line;
527  if (line!="@END_TABLE") {
528  std::cerr << line << std::endl;
529  std::cerr << __FILE__ << ":" << __LINE__ << ": file not closed correctly, exiting.\n";
530  exit(0);
531  }
532  if (!concatenated_) {
533  this->close();
534  } else {
535  this->close_table();
536  }
537  } else {
538 #ifdef DEBUG
539  std::cerr << (char)(in_->peek()) << std::endl;
540 #endif
541  *in_ >> scaffold;
542  *in_ >> pos;
543  *in_ >> data;
544  data.set_abs_pos(file_index_.get_abs_pos(scaffold, pos) );
545  }
546 }
547 
548 template <class T>
550 {
551  //TODO Check for table_open instead?
552  id1_t pos1, pos2;
553  std::string scaffold1, scaffold2;
554  if (!in_->good() ) {
555  std::cerr << "an error has occurred during reading.\n";
556  exit(0);
557  }
558  if (in_->peek()=='@') {
559  std::string line;
560  *in_ >> line;
561  if (line!="@END_TABLE") {
562  std::cerr << line << std::endl;
563  std::cerr << __FILE__ << ":" << __LINE__ << ": file not closed correctly, exiting.\n";
564  exit(0);
565  }
566  if (!concatenated_) {
567  this->close();
568  } else {
569  this->close_table();
570  }
571  } else {
572 #ifdef DEBUG
573  std::cerr << (char)(in_->peek()) << std::endl;
574 #endif
575  *in_ >> scaffold1;
576  *in_ >> pos1;
577  *in_ >> scaffold2;
578  *in_ >> pos2;
579  *in_ >> data;
580  data.set_abs_pos1(file_index_.get_abs_pos(scaffold1, pos1) );
581  data.set_abs_pos2(file_index_.get_abs_pos(scaffold2, pos2) );
582  }
583 }
584 
585 template <class T>
587 {
588 // char a='a';
589  if (in_->peek()!='@'){
590 // in_->read(&a, sizeof(char) );
591  data.read_binary(*in_);
592  } else {
593  if (!concatenated_) {
594  this->close();
595  } else {
596  this->close_table();
597  }
598  }
599 }
600 
601 template <class T>
602 void Indexed_file<T>::read_binary(T &data)
603 {
604 // char a='a';
605  if (in_->peek()=='@')
606  {
607  if (!concatenated_) {
608  this->close();
609  } else {
610  this->close_table();
611  }
612  } else {
613  //WTF?!?!
614 // in_->read(&a, sizeof(char) );
615  data.read_pos(*in_);
616  data.read_binary(*in_);
617  }
618 
619 }
620 
621 template <class T>
623 {
624 // char a='a';
625  if (in_->peek()=='@')
626  {
627  if (!concatenated_) {
628  this->close();
629  } else {
630  this->close_table();
631  }
632  } else {
633  //WTF?!?!
634 // in_->read(&a, sizeof(char) );
635  data.read_pos(*in_);
636  data.read_binary(*in_);
637  }
638 
639 }
640 
641 template <class T>
642 void Flat_file<T>::write_text(const T &data)
643 {
644  *out_ << data << std::endl;
645 }
646 
647 template <class T>
648 void Indexed_file<T>::write_text(const T &data)
649 {
650  *out_ << file_index_.get_string(file_index_.get_id0(data.get_abs_pos()) ) << '\t' << file_index_.get_id1(data.get_abs_pos() ) << '\t' << data << std::endl;
651 }
652 
653 template <class T>
655 {
656  *out_ << file_index_.get_string(file_index_.get_id0(data.get_abs_pos()) ) << '\t' << file_index_.get_id1(data.get_abs_pos() ) << '\t' << file_index_.get_string(file_index_.get_id0(data.get_abs_pos2()) ) << '\t' << file_index_.get_id1(data.get_abs_pos2() ) << '\t' << data << std::endl;
657 }
658 
659 
660 template <class T>
661 void Data_file<T>::write_binary(const T &data)
662 {
663 // char a='a'; //WTF?!?!
664 // out_->write(&a, sizeof(char) );
665  data.write_binary(*out_);
666 }
667 
668 template <class T>
669 void Indexed_file<T>::write_binary(const T &data)
670 {
671 // char a='a'; //WTF?!?!
672 // out_->write(&a, sizeof(char) );
673  data.write_pos(*out_);
674  data.write_binary(*out_);
675 }
676 
677 template <class T>
678 void Double_indexed_file<T>::write_binary(const T &data)
679 {
680 // char a='a'; //WTF?!?!
681 // out_->write(&a, sizeof(char) );
682  data.write_pos(*out_);
683  data.write_binary(*out_);
684 }
685 
686 template <class T>
688 {
689  if (binary_) write_binary(data);
690  else write_text(data);
691 // if (!out_->good() ) { std::cerr << __FILE__ << ":" << __LINE__ << ": unexpected error writing file. Exiting.\n"; exit(0);};
692  return *this;
693 }
694 
695 template <class T>
697 {
698  if (binary_) write_binary(data);
699  else write_text(data);
700 // if (!out_->good() ) { std::cerr << __FILE__ << ":" << __LINE__ << ": unexpected error writing file. Exiting.\n"; exit(0);};
701  return *this;
702 }
703 
704 template <class T>
706 {
707  if (binary_) write_binary(data);
708  else write_text(data);
709 // if (!out_->good() ) { std::cerr << __FILE__ << ":" << __LINE__ << ": unexpected error writing file. Exiting.\n"; exit(0);};
710  return *this;
711 }
712 
713 template <class T>
714 void Flat_file<T>::write_header(const T &data)
715 {
716  if (write_) {
717  *out_ << "@NAME:" << T::table_name << "\tVERSION:" << VERSION;
718  if (try_binary_ && T::binary)
719  {
720  *out_ << "\tFORMAT:BINARY";
721  binary_=true;
722  } else {
723  *out_ << "\tFORMAT:TEXT";
724  binary_=false;
725  }
726  if (concatenated_) *out_ << "\tCONCATENATED";
727  *out_ << std::endl;
728  *out_ << data.header();
729  table_open_=true;
730  } else {
731  std::cerr << __FILE__ << ":" << __LINE__ << ": file not open for writing. Exiting.\n"; exit(0);
732  }
733 }
734 
735 template <class T>
737 {
738  std::string line;
739  std::vector <std::string> columns;
740  std::getline(*in_, line);
741  columns=split(line, '\t');
742  if (columns.size()>2){
743  if (columns[0]=="@NAME:"+T::table_name ){
744  binary_=std::find(columns.begin(), columns.end(), "FORMAT:BINARY")!=columns.end();
745  concatenated_=std::find(columns.begin(), columns.end(), "CONCATENATED")!=columns.end();
746  std::getline(*in_, line);
747  columns=split(line, '\t');
748  T data(columns);
749  table_open_=true;
750  return data;
751  }
752  std::cerr << __FILE__ << ":" << __LINE__ << " attempted to open incorrect header.\n";
753  std::cerr << line << std::endl;
754  }
755  table_open_=false;
756  std::cerr << __FILE__ << ":" << __LINE__ << " could not initilize " << typeid(T).name() <<"\n";
757  std::cerr << line << std::endl;
758  T data;
759  return data;
760 }
761 
762 template <class T>
764 {
766  index.open_from(*this);
767  file_index_=index.read_header();
768  while(index.table_is_open() ){
769  index.read(file_index_);
770  }
771 
772  std::string line;
773  std::vector <std::string> columns;
774 #ifdef DEBUG
775  std::cerr << in_->peek() << std::endl;
776 #endif
777  /*while(in_->peek()!='@' && in_->good() ){
778  std::getline(*in_, line);
779  std::cerr << line << std::endl;
780  }*/
781  std::getline(*in_, line);
782 
783  columns=split(line, '\t');
784  if (columns.size()>2){
785  if (columns[0]=="@NAME:"+T::table_name){
786  binary_=std::find(columns.begin(), columns.end(), "FORMAT:BINARY")!=columns.end();
787  concatenated_=std::find(columns.begin(), columns.end(), "CONCATENATED")!=columns.end();
788  std::getline(*in_, line);
789  columns=split(line, '\t');
790  T data(columns);
791  table_open_=true;
792  return data;
793  }
794  std::cerr << __FILE__ << ":" << __LINE__ << " attempted to open incorrect header.\n";
795  std::cerr << line << std::endl;
796  std::cerr << T::table_name << std::endl;
797  }
798  std::cerr << __FILE__ << ":" << __LINE__ << " could not initilize " << typeid(T).name() << "\n";
799  std::cerr << line << std::endl;
800  T data;
801  table_open_=false;
802  reference_size_=file_index_.get_reference_size();
803  return data;
804 }
805 
806 template <class T>
807 void Indexed_file<T>::write_header(const T &data)
808 {
809  if (!write_) {
810  std::cerr << __FILE__ << ":" << __LINE__ << " file not open for writing. Exiting \n";
811  exit(0);
812  }
814 #ifdef DEBUG
815  std::cerr << "Writing header of " << filename_ << std::endl;
816  std::cerr << "aka: " << this->filename() << std::endl;
817 #endif
818  index.open_from(*this);
819  if (!index.is_open() ) {
820  std::cerr << __FILE__ << ":" << __LINE__ << " cannot open for writing. Exiting \n";
821  exit(0);
822  }
823  index.write_header(file_index_);
824  index.write(file_index_);
825  index.close_table();
826  *out_ << "@NAME:" << T::table_name << "\tVERSION:" << VERSION;
827  if (try_binary_ && T::binary){
828  *out_ << "\tFORMAT:BINARY";
829  binary_=true;
830  } else {
831  *out_ << "\tFORMAT:TEXT";
832  binary_=false;
833  }
834  if (concatenated_) *out_ << "\tCONCATENATED";
835  *out_ << "\tINDEXED\n";
836  *out_ << data.header();
837  table_open_=true;
838 }
839 
840 template <class T>
842 {
843  file_index_=index;
844 }
845 
846 template <class T>
848 {
849  return file_index_;
850 }
851 
852 #endif
bool is_open(void) const
Returns true iff Base_file is open.
Definition: map_file.cc:369
void write_text(const T &)
Write in text mode. DONE.
Definition: map_file.h:642
igzstream gzin_
compressed istream.
Definition: map_file.h:92
Definition: gzstream.h:103
Definition: map_file.h:287
bool binary(void) const
Returns true iff a table is open in binary mode.
Definition: map_file.cc:442
T read_header(void)
Reads a file header.
Definition: map_file.h:763
void seek(const std::streampos &pos)
sets in and out (for reading and writing) to position pos.
void seekp(const std::streampos &pos)
sets out (for writing) to position pos.
Definition: map_file.cc:242
Definition: gzstream.h:92
std::streampos tellg(void)
Tells streampos of in (reading)
Definition: map_file.cc:257
std::streampos tellp(void)
Tells streampos of out (writing)
Definition: map_file.cc:252
void open_from(Base_file &)
! Appends to a file.
void write_text(const T &)
Write in text mode. DONE.
Definition: map_file.h:648
void set_delim(const char &)
Sets the delimiter that separates columns. Only used in text mode.
Tmp_buffer buffer_
a buffer which can be rewound.
Definition: map_file.h:88
void open_extention(const char *, const std::ios_base::openmode &)
! Doesn't check extension.
void write_header(const T &)
Writes a file header.
Definition: map_file.h:807
std::ostream * get_out(void)
returns the ostream.
Definition: map_file.cc:224
bool indexed_
Indexed mode flag.
Definition: map_file.h:83
File_index get_index(void) const
Returns the File_index.
Definition: map_file.h:847
void read_text(T &)
Read file in text mode. DONE.
Definition: map_file.h:491
const std::string & filename()
returns the filename.
Definition: map_file.cc:262
void set_index(const File_index &)
Sets the File_index.
Definition: map_file.h:841
Data which has an absolute position.
Definition: data.h:144
Definition: map_file.h:196
Base_file & read(Data *)
Reads from the istream.
Definition: map_file.cc:287
void open_no_extention(const char *, const std::ios::openmode &)
The function that opens a indexed_file (if file).
Definition: map_file.cc:59
bool try_binary_
Attempt to set binary mode flag.
Definition: map_file.h:82
An interface that transforms pairs of name and position keys into record numbers. ...
Definition: file_index.h:23
void write_header(const T &)
Writes a file header.
Definition: map_file.h:714
bool binary_
Binary mode flag.
Definition: map_file.h:81
bool compressed_
indicates whether the input/output stream is compressed.
Definition: map_file.h:74
Data * read_header(void)
Returns a pointer to a new instance of the derived data class.
Definition: map_file.cc:382
bool table_is_open(void) const
Returns true iff a table is open in Base_file.
Definition: map_file.cc:374
char delim_column_
The delimiter which separates columns.
Definition: map_file.h:77
void open(const char *, const std::ios_base::openmode &)
! The function that opens a Data_file (if file).
void read_text(T &)
Read file in text mode. DONE.
Definition: map_file.h:515
void seekg(const std::streampos &pos)
sets in (for reading) to position pos.
Definition: map_file.cc:247
Base_file()
returns the concatenated flag.
Definition: map_file.cc:5
std::ios::openmode openmode_
stores information about the mode in which the file was opened.
Definition: map_file.h:96
bool table_open_
indicates whether the header has been read successfully
Definition: map_file.h:68
bool read_
File is open for reading.
Definition: map_file.h:79
std::istream * in_
All data is read from in.
Definition: map_file.h:85
void write_text(const T &)
Write in text mode. DONE.
Definition: map_file.h:654
size_t size(void) const
Returns the number of rows in the file.
ogzstream gzout_
compressed ostream.
Definition: map_file.h:93
Base_file & write(const Data *)
Writes to the ostream.
Definition: map_file.cc:487
void write_binary(const Data *)
Write in binary mode.
Definition: map_file.cc:460
bool write_
File is open for writing.
Definition: map_file.h:80
Definition: map_file.h:264
std::ostream * out_
All data is written is written to out.
Definition: map_file.h:86
void open(const std::ios::openmode &)
Opens a Base_file to the cin/cout.
std::fstream file_
The file to read data from.
Definition: map_file.h:90
T read_header(void)
Reads a file header.
Definition: map_file.h:736
void write_binary(const Data &)
Write in binary mode.
Definition: tmp_buffer.h:37
void close(void)
Close iostreams, writes tail, etc.
Definition: map_file.cc:275
Data_file & read(Data &)
Reads a row from the file and advances one row.
File_index file_index_
A file_index which turns (id0, id1)->pos.
Definition: map_file.h:291
bool open_
indicates whether the iostream opened succesfully
Definition: map_file.h:60
std::string filename_
The name of the file if opened.
Definition: map_file.h:97
A templet which stores data associated with specific locations in a genome.
Definition: map_file.h:50
A class which can be written as flat text file or into an SQL database.
Definition: data.h:34
bool concatenated_
indicates whether multiple tables are included in the file
Definition: map_file.h:71
std::istream * get_in(void)
returns the istream.
Definition: map_file.cc:219
const std::fstream::openmode & openmode()
returns the open mode.
Definition: map_file.cc:229
void open_header(Base_file &)
Opens a header for a Flat_file.
const char & get_delim(void) const
Gets the delimiter that separates columns. Only used in text mode.
Definition: map_file.cc:40
Indexed_file & write(const T &)
Returns the position in the file.
Definition: map_file.h:696
void read_text(T &)
Read file in text mode. DONE.
Definition: map_file.h:549
void read_binary(Data &)
Read file in binary mode.
Definition: map_file.h:331
void close_table(void)
Ends table w/o closing iostreams.
Definition: map_file.cc:267
Data_file & write(const Data &)
Writes a row to the file and advances one row.