-
Notifications
You must be signed in to change notification settings - Fork 0
/
bc_est.cpp
64 lines (59 loc) · 1.3 KB
/
bc_est.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include<iomanip>
using namespace std;
int main()
{
int n_mar;
int n_ind;
double ct;
cout << "Enter the number of markers: ";
cin >> n_mar;
cout << "\n";
cout << "Enter the number of individuals: ";
cin >> n_ind;
cout << "\n";
string filename;
ifstream in;
cout << "Enter the name of the input file ";
cin >> filename;
in.open( filename.c_str() );
if (!in) {
cout << "Cannot open file.\n";
return (-1);
}
std::vector<std::vector<int> > geno(n_ind, std::vector<int>(n_mar, 0));
std::vector<std::vector<double> > rec(n_mar, std::vector<double>(n_mar, 0));
for (int i = 0; i < geno.size(); i++) {
for (int j = 0; j < geno[1].size(); j++) {
in >> geno[i][j];
}
}
in.close();
for (int i = 0; i < (n_mar-1); i++)
{
for (int j = (i+1); j < n_mar; j++)
{
ct=0.0;
for(int k=0; k < n_ind; k++)
{
if(geno[k][i]!=geno[k][j])
ct++;
}
rec[j][i]=rec[i][j]=ct/n_ind;
}
}
ofstream fout("rec_cpp.txt"); //opening an output stream fo
for (int i = 0; i < n_mar; i++)
{
for (int j = 0; j < n_mar; j++)
{
fout << std::fixed;
fout << std::setprecision(2);
fout << rec[i][j] << " ";
}
fout << "\n";
}
}