-
Notifications
You must be signed in to change notification settings - Fork 0
/
mafTest.cpp
92 lines (79 loc) · 2.19 KB
/
mafTest.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <string>
#include <cctype>
#include <vector>
#include <fstream>
#include <iostream>
#include <cassert>
#include "alignmentIndex.h"
#include "mafParser.h"
using namespace std;
int main(int argc, char* argv[])
{
std::string buffer;
std::vector<std::string> query;
/*
std::string inFile("D:/Projects/JHU2/maf-query/data/subset.maf");
std::string reference("Homo_sapiens");
std::ifstream queryFile("D:/Projects/JHU2/maf-query/data/species.txt");
*/
std::string inFile(argv[1]);
std::string reference(argv[2]);
std::ifstream queryFile(argv[3]);
while (std::getline(queryFile, buffer))
{
query.push_back(buffer);
}
std::sort(query.begin(), query.end());
std::ifstream input(inFile.c_str());
MafParser parser(input);
std::vector<size_t> referenceIdx;
std::vector<size_t> referencePos;
std::vector<std::string> conservation;
std::vector<MafParser::Record> alignmentBlock;
AlignmentIndexReader index(query, "");
while (parser.ReadBlock(alignmentBlock))
{
referenceIdx.clear();
referencePos.clear();
for (size_t i = 0; i < alignmentBlock.size(); ++i)
{
if (alignmentBlock[i].species == reference)
{
referenceIdx.push_back(i);
referencePos.push_back(alignmentBlock[i].start);
}
}
for (size_t j = 0; j < alignmentBlock[0].alignment.size(); j++)
{
for (size_t i = 0; i < referenceIdx.size(); ++i)
{
conservation.clear();
auto& pos = referencePos[i];
auto& ref = alignmentBlock[referenceIdx[i]];
if (ref.alignment[j] == '-')
{
continue;
}
for (auto& rec : alignmentBlock)
{
if (rec.species != reference && toupper(ref.alignment[j]) == toupper(rec.alignment[j]))
{
conservation.push_back(rec.species);
}
}
std::sort(conservation.begin(), conservation.end());
conservation.erase(std::unique(conservation.begin(), conservation.end()), conservation.end());
std::vector<size_t> indexConservation;
index.Read(ref.chr, ref.PositivePos(pos), indexConservation);
std::vector<std::string> strIndexConservation;
for (auto idx : indexConservation)
{
strIndexConservation.push_back(query[idx]);
}
assert(strIndexConservation == conservation);
++pos;
}
}
}
return 0;
}