File: validaa.cpp

package info (click to toggle)
pilercr 1.06%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 844 kB
  • sloc: cpp: 14,339; makefile: 67; sh: 36
file content (128 lines) | stat: -rwxr-xr-x 3,402 bytes parent folder | download | duplicates (2)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include "pilercr.h"

void StripBlanksAndGaps(std::string &s)
	{
	std::string tmp;
	for (size_t i = 0; i < s.size(); ++i)
		{
		char c = s[i];
		if (c != '-' && c != ' ')
			tmp += c;
		}
	s = tmp;
	}

void StripBlanksAndGaps(Seq &s)
	{
	Seq tmp;
	tmp.SetName(s.GetName());
	for (size_t i = 0; i < s.size(); ++i)
		{
		char c = s[i];
		if (c != '-' && c != ' ')
			tmp.push_back(c);
		}
	s = tmp;
	}

static void ValidateRep(const ArrayAln &AA, int RepeatIndex, int &Pos)
	{
	std::string Repeat = AA.Repeats[RepeatIndex];
	std::string LeftFlank = AA.LeftFlanks[RepeatIndex];
	const std::string &Spacer = AA.Spacers[RepeatIndex];

	StripBlanksAndGaps(Repeat);
	StripBlanksAndGaps(LeftFlank);

	size_t LeftFlankLength = LeftFlank.size();
	size_t RepeatLength = Repeat.size();
	size_t SpacerLength = Spacer.size();

	assert(Pos >= (int) LeftFlankLength);
	int LeftFlankStartPos = Pos - (int) LeftFlankLength;

	for (int i = 0; i < (int) LeftFlankLength; ++i)
		{
		char c1 = g_SeqQ[LeftFlankStartPos + i];
		char c2 = LeftFlank[i];
		if (toupper(c1) != toupper(c2))
			{
			Log("Repeat %d, flank[%d]=%c != Seq[%d]=%c LeftFlankStartPos=%d\n",
			  RepeatIndex, i, c1, LeftFlankStartPos + i, c2, LeftFlankStartPos);
			Log("Flank=");
			for (size_t j = 0; j < LeftFlankLength; ++j)
				Log("%c", LeftFlank[j]);
			Log("\n");
			Log("Seq[%d;%d]=", LeftFlankStartPos, LeftFlankLength);
			for (size_t j = 0; j < LeftFlankLength; ++j)
				Log("%c", g_SeqQ[LeftFlankStartPos + j]);
			Log("\n");
			LogAA(AA);
			Quit("ValidateRep failed");
			}
		}

	for (size_t i = 0; i < RepeatLength; ++i)
		{
		char c1 = g_SeqQ[Pos + i];
		char c2 = Repeat[i];
		if (toupper(c1) != toupper(c2))
			{
			Log("Repeat %d, Repeat[%d]=%c != Seq[%d]=%c\n",
			  RepeatIndex, i, c1, Pos + i, c2);
			Log("Repeat=");
			for (size_t j = 0; j < RepeatLength; ++j)
				Log("%c", Repeat[j]);
			Log("\n");
			Log("Seq[%d;%d]=", Pos, RepeatLength);
			for (size_t j = 0; j < RepeatLength; ++j)
				Log("%c", g_SeqQ[Pos + j]);
			Log("\n");
			LogAA(AA);
			Quit("ValidateRep failed");
			}
		}

	for (size_t i = 0; i < SpacerLength; ++i)
		{
		char c1 = g_SeqQ[Pos + RepeatLength + i];
		char c2 = Spacer[i];
		if (toupper(c1) != toupper(c2))
			{
			Log("Repeat %d, Spacer[%d]=%c != Seq[%d]=%c\n",
			  RepeatIndex, i, c1, Pos + RepeatLength + i, c2);
			Log("Spacer=");
			for (size_t j = 0; j < SpacerLength; ++j)
				Log("%c", Spacer[j]);
			Log("\n");
			Log("Seq[%d;%d]=", Pos + RepeatLength, SpacerLength);
			for (size_t j = 0; j < SpacerLength; ++j)
				Log("%c", g_SeqQ[Pos + RepeatLength + j]);
			Log("\n");
			LogAA(AA);
			Quit("ValidateRep failed");
			}
		}

	Pos += (int) (RepeatLength + SpacerLength);
	}

void ValidateAA(const ArrayAln &AA)
	{
	const size_t RepeatCount = AA.Spacers.size();
	assert(RepeatCount == AA.Repeats.size());
	assert(RepeatCount == AA.Spacers.size());

	int Pos = AA.Pos;
	for (size_t RepeatIndex = 0; RepeatIndex < RepeatCount; ++RepeatIndex)
		{
		const std::string &LeftFlank = AA.LeftFlanks[RepeatIndex];
		const std::string &Repeat = AA.Repeats[RepeatIndex];
		const std::string &Spacer = AA.Spacers[RepeatIndex];

		assert(Repeat.size() == AA.Repeats[0].size());
		assert(LeftFlank.size() == g_FlankSize);

		ValidateRep(AA, (int) RepeatIndex, Pos);
		}
	}