libsequence  1.9.5
test_SimDataIO.cc
1 #include <Sequence/SimDataIO.hpp>
2 #include <iostream>
3 #include <fstream>
4 
5 using namespace std;
6 using namespace Sequence;
7 
8 void print_problems( const SimData & d,
9  const SimData & d2 );
10 
11 int main( int argc, char ** argv )
12 {
13  SimData d;
14  while(!cin.eof())
15  {
16  cin >> d >> ws;
17 
18  cerr << "Writing in gzip\n";
19  gzFile gzf = gzopen("test_zlib_out.gz","w");
20  write_SimData_gz(gzf, d);
21  gzclose(gzf);
22 
23  cerr << "Reading from gzip\n";
24  //now, try to read it
25  gzf = gzopen("test_zlib_out.gz","r");
26  SimData d2 = read_SimData_gz(gzf);
27  gzclose(gzf);
28 
29  cerr << "Writing in binary\n";
30  //write it in binary
31  ofstream obin("test_binary_out.bin",ios::binary);
32  write_SimData_binary(obin,d);
33  obin.close();
34 
35  cerr << "Reading from binary\n";
36  //read it
37  ifstream ibin("test_binary_out.bin",ios::binary);
38  SimData d3 = read_SimData_binary(ibin);
39  ibin.close();
40 
41  cerr << "Writing to binary + gzip\n";
42  gzf = gzopen("test_zlib_out.bin.gz","bw");
43  write_SimData_gz(gzf, d, true);
44  gzclose(gzf);
45 
46  cerr << "Reading from binary + gzip\n";
47  //now, try to read it
48  gzf = gzopen("test_zlib_out.bin.gz","r");
49  SimData d4 = read_SimData_gz(gzf,true);
50  gzclose(gzf);
51 
52  if( d != d2 )
53  {
54  cerr << "Error: d != d2\n";
55  print_problems(d,d2);
56  }
57  if(d != d3)
58  {
59  cerr << "Error: d != d3\n";
60  print_problems(d,d3);
61  }
62  if(d != d4)
63  {
64  cerr << "Error: d != d4\n";
65  print_problems(d,d4);
66  }
67  }
68 }
69 
70 void print_problems( const SimData & d,
71  const SimData & d2 )
72 {
73  for( unsigned i = 0 ; i < d.numsites() ; ++i )
74  {
75  if( d.position(i) != d2.position(i) )
76  {
77  cerr << "Position " << i << ": " << d.position(i) << ' ' << d2.position(i) << '\n';
78  }
79  for( unsigned i = 0 ; i < d.size() ; ++i )
80  {
81  if( d[i] != d2[i] )
82  {
83  cerr << "Haplotype " << i << ": " << d[i] << "\n\n" << d2[i] << '\n';
84  }
85  }
86  }
87 }
STL namespace.
The namespace in which this library resides.
Data from coalescent simulations.