File: getconsaa.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 (83 lines) | stat: -rwxr-xr-x 1,463 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
#include "pilercr.h"

const int *GetCountsAA(const ArrayAln &AA, int ColIndex)
	{
	static int Counts[5];

	const size_t RepeatCount = AA.Repeats.size();

	for (int i = 0; i < 5; ++i)
		Counts[i] = 0;

	for (size_t RepeatIndex = 0; RepeatIndex < RepeatCount; ++RepeatIndex)
		{
		const std::string &Repeat = AA.Repeats[RepeatIndex];
		assert(ColIndex >= 0 && ColIndex < (int) Repeat.size());
		char c = Repeat[ColIndex];
		switch (toupper(c))
			{
		case 'A':
			++(Counts[0]);
			break;
		case 'C':
			++(Counts[1]);
			break;
		case 'G':
			++(Counts[2]);
			break;
		case 'T':
			++(Counts[3]);
			break;
		case '-':
			++(Counts[4]);
			break;
			}
		}
	return Counts;
	}

void GetConsSeqAA(const ArrayAln &AA, Seq &ConsSeq)
	{
	ConsSeq.clear();
	ConsSeq.SetName("cons");

	size_t ColCount = AA.Repeats[0].size();
	for (size_t ColIndex = 0; ColIndex < ColCount; ++ColIndex)
		{
		const int *Counts = GetCountsAA(AA, (int) ColIndex);
		int MaxCount = 0;
		int MaxLetter = 0;
		for (int i = 0; i < 5; ++i)
			{
			if (Counts[i] > MaxCount)
				{
				MaxCount = Counts[i];
				MaxLetter = i;
				}
			}

		char c = '?';
		switch (MaxLetter)
			{
		case 0:
			c = 'A';
			break;
		case 1:
			c = 'C';
			break;
		case 2:
			c = 'G';
			break;
		case 3:
			c = 'T';
			break;
		case 4:
			c = '-';
			break;
		default:
			Quit("Bad maxletter");
			}

		ConsSeq.push_back(c);
		}
	}