Yurttas/PL/OOL/Cplusplus/F/07/03/02/00/mmap 20.cpp

 1/*
 2   Copyright(C) 2005
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : September 1, 2005.
11   authorĀ : Salih Yurttas.
12
13   mmap_20.cpp
14*/
15
16#include <iostream>
17
18#include <vector>
19#include <string>
20
21#include <map>
22
23using namespace std;
24
25int main(int argc, char* argv[]) {
26
27  const int N_SEQS= 4;
28
29  string d_list[] = {"AGGCTAAT",
30                     "GGCTAATA",
31                     "TGTAAATT",
32                     "ACGAGGCT"};
33
34  vector<string> dna_list(d_list,
35                          d_list+N_SEQS);
36
37  vector< vector<int> > counts_positions_list;
38
39  vector<int> v;
40
41  v.push_back(2);
42  v.push_back(5);
43  v.push_back(8);
44
45  counts_positions_list.push_back(v);
46
47  v.clear();
48
49  v.push_back(2);
50  v.push_back(4);
51  v.push_back(7);
52
53  counts_positions_list.push_back(v);
54
55  v.clear();
56
57  v.push_back(4);
58  v.push_back(1);
59  v.push_back(3);
60  v.push_back(7);
61  v.push_back(8);
62
63  counts_positions_list.push_back(v);
64
65  v.clear();
66
67  v.push_back(1);
68  v.push_back(8);
69
70  counts_positions_list.push_back(v);
71
72  v.clear();
73
74  multimap<string, vector<int>, less<string> > dna_counts_positions_list;
75
76  int n = counts_positions_list.size();
77
78  for(int i=0; i<n; ++i)
79    dna_counts_positions_list.insert(pair< string,vector<int> >(dna_list.at(i),counts_positions_list.at(i)));
80
81  multimap<string, vector<int>, less<string> >::const_iterator i = dna_counts_positions_list.begin();
82  multimap<string, vector<int>, less<string> >::const_iterator k = dna_counts_positions_list.end();
83
84  for(; i!=k; ++i) {
85    cout << i->first << " - ";
86    vector<int> t = i->second;
87    int m = t.at(0);
88    cout << m << " ";
89    for(int j=1; j<m; ++j)
90      cout << t.at(j) << ",";
91    cout << t.at(m) << endl;
92  }
93
94}