COMBINATORIAL_BLAS  1.6
VectorIOPermute.cpp
Go to the documentation of this file.
1 #include <mpi.h>
2 #include <sys/time.h>
3 #include <iostream>
4 #include <functional>
5 #include <algorithm>
6 #include <vector>
7 #include <sstream>
8 #include "CombBLAS/CombBLAS.h"
9 
10 using namespace std;
11 using namespace combblas;
12 
13 #define myidlen 35
14 #define myseqlen 150
15 
16 template <unsigned int IDLEN, unsigned int SEQLEN>
17 class ShortRead
18 {
19 public:
20  ShortRead(){ id[0] = '\0'; seq[0] = '\0'; qual[0] = '\0'; };
21  ShortRead(const string & s_id, const string & s_seq, const string & s_qual)
22  {
23  s_id.copy(id, IDLEN);
24  s_seq.copy(seq, SEQLEN);
25  s_qual.copy(qual, SEQLEN);
26  id[IDLEN] = '\0';
27  seq[SEQLEN] = '\0';
28  qual[SEQLEN] = '\0';
29 
30  }
31  template <unsigned int NS_IDLEN, unsigned int NS_SEQLEN>
32  friend ostream& operator<<( ostream& os, const ShortRead<NS_IDLEN,NS_SEQLEN> & sread);
33 
34 private:
35  char id[IDLEN+1]; // (+1)s are for null termination
36  char seq[SEQLEN+1];
37  char qual[SEQLEN+1];
38 
39  template <typename IT,unsigned int NS_IDLEN, unsigned int NS_SEQLEN> // NS: no-shadow
40  friend class ShortReadSaveHandler;
41 };
42 
43 template <unsigned int IDLEN, unsigned int SEQLEN>
44 ostream& operator<<(ostream& os, const ShortRead<IDLEN, SEQLEN> & sread )
45 {
46  os << sread.id << " " << sread.seq << " " << sread.qual << endl;
47  return os;
48 };
49 
50 
51 template <class IT, unsigned int IDLEN, unsigned int SEQLEN>
53 {
54 public:
57 
58  MPI_Datatype getMPIType()
59  {
60  return MPIType< ShortRead<IDLEN,SEQLEN> >(); // utilize the MPI type cache
61  }
62 
63  void binaryfill(FILE * rFile, IT & ind, ShortRead<IDLEN,SEQLEN> & val)
64  {
65  size_t entryLength = fread (&ind,sizeof(ind),1,rFile); // read the index first
66  entryLength += fread (&val,sizeof(ShortRead<IDLEN,SEQLEN>),1,rFile);
67  if(entryLength != 2)
68  cout << "Not enough bytes read in binaryfill " << endl;
69  }
70  size_t entrylength() { return sizeof(ShortRead<IDLEN,SEQLEN>); }
71 
72  template <typename c, typename t>
73  ShortRead<IDLEN,SEQLEN> read(std::basic_istream<c,t>& is, IT ind)
74  {
75  string s_id, s_seq, s_qual, s_null;
76  getline (is,s_id);
77  getline (is,s_seq);
78  getline (is,s_null); // basically the '+' sign
79  getline (is,s_qual);
80 
81  return ShortRead<IDLEN,SEQLEN>(s_id, s_seq, s_qual);
82  }
83 
84  template <typename c, typename t>
85  void save(std::basic_ostream<c,t>& os, const ShortRead<IDLEN,SEQLEN> & tw, IT ind)
86  {
87  // make it compatible with read...
88  }
89 };
90 
91 
92 
93 int main(int argc, char* argv[])
94 {
95  int nprocs, myrank;
96  MPI_Init(&argc, &argv);
97  MPI_Comm_size(MPI_COMM_WORLD,&nprocs);
98  MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
99 
100  if(argc < 4)
101  {
102  if(myrank == 0)
103  {
104  cout << "Usage: ./VectorIOPermute <VectorFile>" << endl;
105  cout << "<VectorFile> is a binary file" << endl;
106  }
107  MPI_Finalize();
108  return -1;
109  }
110  {
111 
113  ShortReads.ReadDistribute(string(argv[1]), 0, ShortReadSaveHandler<int64_t, myidlen, myseqlen>(), true); // read it from binary file in parallel
114 
115 
116  }
117  MPI_Finalize();
118  return 0;
119 }
void binaryfill(FILE *rFile, IT &ind, ShortRead< IDLEN, SEQLEN > &val)
ShortRead< IDLEN, SEQLEN > read(std::basic_istream< c, t > &is, IT ind)
ShortRead(const string &s_id, const string &s_seq, const string &s_qual)
ShortRead< IDLEN, SEQLEN > getNoNum(IT ind)
void save(std::basic_ostream< c, t > &os, const ShortRead< IDLEN, SEQLEN > &tw, IT ind)
int main(int argc, char *argv[])
MPI_Datatype getMPIType()
std::ifstream & ReadDistribute(std::ifstream &infile, int master, HANDLER handler)
Totally obsolete version that only accepts an ifstream object and ascii files.
Collection of Generic Sequential Functions.
Definition: CCGrid.h:4