File: getparents.cpp

package info (click to toggle)
mothur 1.48.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,692 kB
  • sloc: cpp: 161,866; makefile: 122; sh: 31
file content (89 lines) | stat: -rwxr-xr-x 1,890 bytes parent folder | download | duplicates (7)
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
#include "myutils.h"
#include "chime.h"
#include "ultra.h"
#include <set>

void AddTargets(Ultra &U, const SeqData &Query, set<unsigned> &TargetIndexes);

void GetChunkInfo(unsigned L, unsigned &Length, vector<unsigned> &Los)
	{
	Los.clear();

	if (L <= opt_minchunk)
		{
		Length = L;
		Los.push_back(0);
		return;
		}

	Length = (L - 1)/opt_chunks + 1;
	if (Length < opt_minchunk)
		Length = opt_minchunk;

	unsigned Lo = 0;
	for (;;)
		{
		if (Lo + Length >= L)
			{
			Lo = L - Length - 1;
			Los.push_back(Lo);
			return;
			}
		Los.push_back(Lo);
		Lo += Length;
		}
	}

void GetCandidateParents(Ultra &U, const SeqData &QSD, float AbQ,
  vector<unsigned> &Parents)
	{
	Parents.clear();

	set<unsigned> TargetIndexes;

	unsigned QL = QSD.L;

	SeqData QuerySD = QSD;

	unsigned ChunkLength;
	vector<unsigned> ChunkLos;
	GetChunkInfo(QL, ChunkLength, ChunkLos);
	unsigned ChunkCount = SIZE(ChunkLos);
	for (unsigned ChunkIndex = 0; ChunkIndex < ChunkCount; ++ChunkIndex)
		{
		unsigned Lo = ChunkLos[ChunkIndex];
		asserta(Lo + ChunkLength <= QL);

		const byte *Chunk = QSD.Seq + Lo;

	// THIS MESSES UP --self!!
		//char Prefix[32];
		//sprintf(Prefix, "%u|", Lo);
		//string ChunkLabel = string(Prefix) + string(QSD.Label);

		//QuerySD.Label = ChunkLabel.c_str();
		QuerySD.Seq = Chunk;
		QuerySD.L = ChunkLength;

		AddTargets(U, QuerySD, TargetIndexes);

		Lo += ChunkLength;
		}

	for (set<unsigned>::const_iterator p = TargetIndexes.begin();
	  p != TargetIndexes.end(); ++p)
		{
		unsigned TargetIndex = *p;
		bool Accept = true;
		if (AbQ > 0.0f)
			{
			const char *TargetLabel = U.GetSeedLabel(TargetIndex);
			float AbT = GetAbFromLabel(string(TargetLabel));
			if (AbT > 0.0f && AbT < opt_abskew*AbQ)
				Accept = false;
			}

		if (Accept)
			Parents.push_back(TargetIndex);
		}
	}