File: outarray.cpp

package info (click to toggle)
pilercr 1.06%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 844 kB
  • sloc: cpp: 14,339; makefile: 67; sh: 36
file content (200 lines) | stat: -rwxr-xr-x 5,286 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#include "pilercr.h"
#include "multaln.h"

#define TRACE		0

void PileToSeq(const std::vector<PileData> &Piles, int PileIndex, Seq &s,
  int *ptrPosLo, int *ptrPosHi)
	{
	const int PileCount = (int) Piles.size();
	assert(PileIndex >= 0 && PileIndex < PileCount);

	const PileData &Pile = Piles[PileIndex];
	const ContigData &Contig = GlobalPosToContig(Pile.Lo);

	int Lo = Pile.Lo - g_HitPadding;
	int Hi = Pile.Hi + g_HitPadding;

	if (Lo < Contig.From)
		Lo = Contig.From;
	int ContigTo = Contig.From + Contig.Length - 1;
	if (Hi >= ContigTo)
		Hi = ContigTo;

	int Length = Hi - Lo + 1;
	assert(Length > 0);

	int n = (int) strlen(Contig.Label) + 64;
	char *Name = all(char, n);
	sprintf(Name, "%s:%d-%d", Contig.Label, Lo, Hi);
	s.SetName(Name);
	freemem(Name);

	s.reserve(Length);
	for (int Pos = Lo; Pos <= Hi; ++Pos)
		s.push_back(g_SeqQ[Pos]);

	*ptrPosLo = Lo;
	*ptrPosHi = Hi;
	}

static void OutputArrayHeaderSim()
	{
	Out("\n\n");
	Out("Array          Sequence    Position      Length  # Copies  Repeat  Spacer  +  Consensus\n");
	Out("=====  ================  ==========  ==========  ========  ======  ======  =  =========\n");
	}

static void OutputArrayHeaderPos()
	{
	Out("\n");
	Out("Array          Sequence    Position      Length  # Copies  Repeat  Spacer    Distance  Consensus\n");
	Out("=====  ================  ==========  ==========  ========  ======  ======  ==========  =========\n");
	}

static void OutputArraySummaryLineSim(const ArrayAln &AA)
	{
	const ContigData &Contig = GlobalPosToContig(AA.Pos);
	const char *Label = Contig.Label;
	int ArrayLength = GetArrayLength(AA);
	int RepeatCount = (int) AA.Repeats.size();
	int AvgRepeatLength = GetAvgRepeatLength(AA);
	int AvgSpacerLength = GetAvgSpacerLength(AA);
	char Strand = (AA.ClusterRevComp ? '-' : '+');

	char *TmpLabel;
	int LocalLo = GlobalToLocal(AA.Pos, &TmpLabel);
	Out("%5d  %16.16s  %10d  %10d  %8d  %6d  %6d  %c  ",
	  AA.Id, Label, LocalLo + 1, ArrayLength, RepeatCount, AvgRepeatLength,
	  AvgSpacerLength, Strand);

	const Seq &s = AA.AlignedConsSeq;
	int Len = s.Length();

	for (int i = 0; i < Len; ++i)
		Out("%c", s.GetChar(i));
	Out("\n");
	}

static void OutputArraySummaryLinePos(const ArrayAln &AA, int Distance)
	{
	const ContigData &Contig = GlobalPosToContig(AA.Pos);
	const char *Label = Contig.Label;
	int ArrayLength = GetArrayLength(AA);
	int RepeatCount = (int) AA.Repeats.size();
	int AvgRepeatLength = GetAvgRepeatLength(AA);
	int AvgSpacerLength = GetAvgSpacerLength(AA);

	char *TmpLabel;
	int LocalLo = GlobalToLocal(AA.Pos, &TmpLabel);
	Out("%5d  %16.16s  %10d  %10d  %8d  %6d  %6d  ",
	  AA.Id, Label, LocalLo + 1, ArrayLength, RepeatCount, AvgRepeatLength, AvgSpacerLength);

	if (Distance == -1)
		Out("            ");
	else
		Out("%10d  ", Distance);

	const Seq &s = AA.ConsSeq;
	int Len = s.Length();

	for (int i = 0; i < Len; ++i)
		Out("%c", s.GetChar(i));
	Out("\n");
	}

static void OutputArrayFooter(const Seq &ConsSymbols)
	{
	for (int i = 0; i < (5+2+16+2+10+2+10+8+2+6+2+6+2+2+3); i++)
		Out(" ");
	int Len = ConsSymbols.Length();
	for (int i = 0; i < Len; ++i)
		Out("%c", ConsSymbols.GetChar(i));
	Out("\n");
	}

static bool ByPos(const ArrayAln *A1, const ArrayAln *A2)
	{
	return A1->Pos < A2->Pos;
	}

void OutArrays(std::vector<ArrayAln *> &AAVec)
	{
	IntVecVec Clusters;
	ClusterConsRC(AAVec, Clusters);
	const size_t ClusterCount = Clusters.size();

	Progress("Creating report");

// Detail report
	Out("\n");
	Out("\n");
	Out("DETAIL REPORT\n");
	Out("\n");
	const size_t ArrayCount = AAVec.size();
	for (size_t ArrayIndex = 0; ArrayIndex < ArrayCount; ++ArrayIndex)
		{
		const ArrayAln &AA = *(AAVec[ArrayIndex]);
		OutDetailAA(AA);
		}

// Summary reports
	Out("\n");
	Out("\n");
	Out("SUMMARY BY SIMILARITY\n");
	Out("\n");
	OutputArrayHeaderSim();

	for (size_t ClusterIndex = 0; ClusterIndex < ClusterCount; ++ClusterIndex)
		{
		const IntVec &Cluster = Clusters[ClusterIndex];
		Seq ConsSymbols;
		AlignCluster(AAVec, Cluster, ConsSymbols);
		const size_t ArrayCount = Cluster.size();
		for (size_t i = 0; i < ArrayCount; ++i)
			{
			unsigned ArrayIndex = Cluster[i];
			ArrayAln &AA = *(AAVec[ArrayIndex]);
			if (ArrayCount == 1)
				AA.ClusterRevComp = false;
			OutputArraySummaryLineSim(AA);
			}
		if (ArrayCount > 1)
			OutputArrayFooter(ConsSymbols);
		Out("\n");
		}

	Out("\n");
	Out("\n");
	Out("SUMMARY BY POSITION\n");
	Out("\n");

	std::sort(AAVec.begin(), AAVec.end(), ByPos);

	int LastContigIndex = -1;
	int LastPos = -1;
	for (size_t ArrayIndex = 0; ArrayIndex < ArrayCount; ++ArrayIndex)
		{
		const ArrayAln &AA = *(AAVec[ArrayIndex]);
		int Pos = AA.Pos;
		int ContigIndex = GlobalPosToContigIndex(Pos);
		if (ContigIndex != LastContigIndex)
			{
			LastPos = -1;
			const ContigData &Contig = GlobalPosToContig(Pos);
			Out("\n");
			Out("\n");
			Out(">");
			Out(Contig.Label);
			Out("\n");
			OutputArrayHeaderPos();
			LastContigIndex = Contig.Index;
			}

		int Distance = -1;
		if (ArrayIndex > 0)
			Distance = DistanceAA(*(AAVec[ArrayIndex-1]), AA);

		OutputArraySummaryLinePos(AA, Distance);
		}
	}