-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcomputeTRFscore.cpp
64 lines (59 loc) · 1.91 KB
/
computeTRFscore.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 <SeqAnHTS/include/seqan/file.h>
#include <SeqAnHTS/include/seqan/align.h>
#include <SeqAnHTS/include/seqan/sequence.h>
#include <SeqAnHTS/include/seqan/seq_io.h>
#include <fstream>
using namespace std;
using namespace seqan;
//For repeating a motif n times
Dna5String repeat(Dna5String s, float n) {
Dna5String ret;
float diff = n - floor(n);
for (int i = 0; i < floor(n)+1; i++) {
append(ret,s);
}
if (diff > 0)
{
int t = round(diff*length(s));
append(ret,prefix(s,t));
}
return ret;
}
int getPurity(Dna5String pureRepeat, Dna5String realRepeat)
{
//if (length(pureRepeat)!=length(realRepeat))
//cout << "Pure and real repeats have unequal lengths! Real: " << length(realRepeat) << " and pure: " << length(pureRepeat) << endl;
//Type definition for alignment structure
typedef Dna5String TSequence;
typedef Align<TSequence,ArrayGaps> TAlign;
typedef Row<TAlign>::Type TRow;
//Create alignment structures, before and after
TAlign alignStruct;
resize(rows(alignStruct), 2);
assignSource(row(alignStruct,0),pureRepeat);
assignSource(row(alignStruct,1),realRepeat);
int alignmentScore = localAlignment(alignStruct, Score<int,Simple>(2,-7,-7));
return alignmentScore;
}
int main(int argc, char const ** argv)
{
//Check arguments.
if (argc != 3)
{
cerr << "USAGE: " << argv[0] << " (infoFile with: motif refRepeatNum repRepeatSeq) output ";
return 1;
}
ifstream inputFile(argv[1]);
ofstream outputFile(argv[2]);
string motifString, repeatString;
float refRepeatNum;
int trfScore;
while (inputFile >> motifString >> refRepeatNum >> repeatString)
{
Dna5String pureRepeat = repeat(motifString, refRepeatNum);
trfScore = getPurity(pureRepeat, repeatString);
outputFile << trfScore << endl;
}
return 0;
}