File: Tprocess.cxx

package info (click to toggle)
phylonium 1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 44,340 kB
  • sloc: cpp: 15,701; ansic: 782; makefile: 139; python: 66; sh: 41
file content (123 lines) | stat: -rw-r--r-- 3,480 bytes parent folder | download | duplicates (3)
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
#include <string>
#include "catch.hpp"
#include "process.h"

std::string REFPOS_FILE_NAME;

void filter_overlaps_max(std::vector<homology> &pile);

bool operator==(const homology &a, const homology &b)
{
	if (a.start() != b.start()) return false;
	if (a.end() != b.end()) return false;
	if (a.start_query() != b.start_query()) return false;
	if (a.end_query() != b.end_query()) return false;

	return true;
}

TEST_CASE("Homology basics")
{
	auto A = homology{0, 0, 10};
	auto B = homology{1, 1, 10};

	REQUIRE(A.starts_left_of(B));
	REQUIRE(!A.ends_left_of(B));
	REQUIRE(A.overlaps(B));

	auto C = homology{10, 10, 10};
	REQUIRE(A.starts_left_of(C));
	REQUIRE(A.ends_left_of(C));
	REQUIRE(!A.overlaps(C));

	// Query coordinate doesn't matter
	A = homology{0, 23456, 10};
	B = homology{1, 678, 10};
	C = homology{10, 987, 10};

	REQUIRE(A.starts_left_of(B));
	REQUIRE(!A.ends_left_of(B));
	REQUIRE(A.overlaps(B));
	REQUIRE(A.starts_left_of(C));
	REQUIRE(A.ends_left_of(C));
	REQUIRE(!A.overlaps(C));

	auto D = homology{0, 0, 100}.trim(0, 10);
	A = homology{0, 0, 10};

	REQUIRE(D.start() == A.start());
	REQUIRE(D.end() == A.end());
	REQUIRE(D.start_query() == A.start_query());
	REQUIRE(D.end_query() == A.end_query());
}

TEST_CASE("Homology filtering")
{
	// two possible beginnings
	auto pile = std::vector<homology>{{0, 0, 10}, {1, 1, 3}};

	filter_overlaps_max(pile);
	REQUIRE(pile.size() == 1);
	REQUIRE(pile[0] == homology{0, 0, 10});

	// overlap in the middle
	pile = std::vector<homology>{
		{0, 0, 10}, {10, 10, 10}, {10, 10, 20}, {40, 40, 5}};

	auto expected =
		std::vector<homology>{{0, 0, 10}, {10, 10, 20}, {40, 40, 5}};

	filter_overlaps_max(pile);
	REQUIRE(pile == expected);

	// two possible endings
	pile = std::vector<homology>{
		{0, 0, 10}, {10, 10, 10}, {10, 10, 20}, {40, 40, 5}, {42, 42, 2}};

	filter_overlaps_max(pile);
	REQUIRE(pile == expected);

	// two chains
	pile = std::vector<homology>{{10, 10, 10}, {0, 0, 10},   {20, 20, 10},
								 {5, 5, 10},   {15, 15, 10}, {25, 25, 10},
								 {30, 30, 10}};

	expected = std::vector<homology>{
		{0, 0, 10}, {10, 10, 10}, {20, 20, 10}, {30, 30, 10}};

	std::sort(begin(pile), end(pile),
			  [](const homology &self, const homology &other) {
				  return self.starts_left_of(other);
			  });
	filter_overlaps_max(pile);
	REQUIRE(pile == expected);
}

TEST_CASE("Complete deletion")
{
	auto homologies = std::vector<std::vector<homology>>{
		{{10, 10, 10}, {110, 110, 20}, {220, 220, 10}, {260, 260, 10}},
		{{10, 10, 10}, {120, 120, 20}, {200, 200, 100}},
		{{0, 0, 300}, {300, 300, 100}}};

	auto expected = std::vector<std::vector<homology>>{
		{{10, 10, 10}, {120, 120, 10}, {220, 220, 10}, {260, 260, 10}},
		{{10, 10, 10}, {120, 120, 10}, {220, 220, 10}, {260, 260, 10}},
		{{10, 10, 10}, {120, 120, 10}, {220, 220, 10}, {260, 260, 10}}};

	REQUIRE(complete_delete(homologies) == expected);
	REQUIRE(complete_delete(expected) == expected);

	// query coordinates vary per sequence
	homologies = std::vector<std::vector<homology>>{
		{{10, 110, 10}, {110, 210, 20}, {220, 320, 10}, {260, 460, 10}},
		{{10, 510, 10}, {120, 620, 20}, {200, 700, 100}},
		{{0, 0, 300}, {300, 300, 100}}};

	expected = std::vector<std::vector<homology>>{
		{{10, 110, 10}, {120, 220, 10}, {220, 320, 10}, {260, 460, 10}},
		{{10, 510, 10}, {120, 620, 10}, {220, 720, 10}, {260, 760, 10}},
		{{10, 10, 10}, {120, 120, 10}, {220, 220, 10}, {260, 260, 10}}};

	REQUIRE(complete_delete(homologies) == expected);
}